跳到主要内容
Zomer Gregorio

Zomer Gregorio

软件工程师

简历
前端
  • TypeScript
  • React
  • Next.js
  • TanStack
  • Tailwind CSS
后端
  • Node.js
  • Hono
  • Express
  • Django
数据
  • PostgreSQL
  • Redis
  • Drizzle
  • Prisma
基础设施/工具
  • Docker
  • GitHub Actions
  • Cloudflare
  • Vercel
博客

AdonisJS, Bun & Bun Cloud: A Modern CI/CD DevOps Stack

· adonisjs · bun · buncloud · ci-cd · devops

Explore integrating AdonisJS, Bun, and Bun Cloud with CI/CD for a high-performance, automated web application. Learn practical steps for a robust developer experience.

获取更新

每当我发布新内容时,你会收到一条简短通知。你的电子邮件或浏览器订阅信息仅用于发送这些更新,并可随时取消订阅;无需账户或跟踪档案。

开始接收通知前,需要通过确认邮件完成验证。

AdonisJS, Bun & Bun Cloud: A Modern CI/CD DevOps Stack

Building robust, high-performance web applications requires a thoughtful combination of frameworks, runtimes, and deployment strategies. This post demonstrates how to integrate AdonisJS, Bun, and Bun Cloud with a solid CI/CD pipeline, offering a powerful and efficient development and deployment workflow.

AdonisJS: The Robust Backend Framework

AdonisJS is a full-stack TypeScript-first web framework that emphasizes developer experience, convention over configuration, and a rich ecosystem. It provides a structured approach to building scalable APIs and web applications.

First, let's scaffold a new AdonisJS project using Bun as our package manager:

bun create adonisjs/core-app@latest bun-cloud-app
cd bun-cloud-app
bun install

Create a simple controller and route to expose an endpoint. For instance, app/Controllers/Http/HomeController.ts:

// app/Controllers/Http/HomeController.ts
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
 
export default class HomeController {
  public async index({ response }: HttpContextContract) {
    return response.json({ message: 'Hello from AdonisJS on Bun Cloud!' })
  }
}

And register the route in start/routes.ts:

// start/routes.ts
import Route from '@ioc:Adonis/Core/Route'
 
Route.get('/', 'HomeController.index')

Bun: The All-in-One JavaScript Runtime & Toolkit

Bun is an incredibly fast JavaScript runtime, package manager, bundler, and test runner, all in one. Its native performance significantly accelerates development cycles and improves application startup times.

We'll use Bun to manage dependencies and run our AdonisJS application. To start the development server:

bun dev

For production, Bun can build your AdonisJS application into a single executable or highly optimized files. AdonisJS ships with a build command that Bun can execute:

bun run build

This command compiles your TypeScript code and prepares it for production, leveraging Bun's speed for the build process.

Bun Cloud: Effortless Serverless Deployment

Bun Cloud is a simplified, high-performance serverless platform designed specifically for Bun applications. It offers automatic scaling, global distribution, and zero-downtime deployments, making it ideal for modern web services.

To deploy your AdonisJS application to Bun Cloud, you'll first need to ensure you have the Bun CLI installed and are logged in. Create a bunfig.toml file at the root of your project to configure the deployment:

# bunfig.toml
[deploy]
entrypoint = "build/server.js"

This tells Bun Cloud to use the compiled server.js file generated by AdonisJS's build process. Now, deploy it:

bun deploy

Bun Cloud automatically detects your bun.lockb file and installs dependencies, then deploys your application. You'll get a URL to access your live service.

CI/CD & DevOps: Automating the Workflow

Integrating CI/CD ensures that every code change is automatically built, tested, and potentially deployed, leading to faster, more reliable releases. We'll use GitHub Actions for this.

Create a .github/workflows/deploy.yml file:

# .github/workflows/deploy.yml
name: Deploy to Bun Cloud
 
on:
  push:
    branches:
      - main
 
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: oven-sh/setup-bun@v1
        with:
          bun-version: latest
      - name: Install dependencies
        run: bun install
      - name: Run tests
        run: bun test # Assuming you have tests configured
      - name: Build application
        run: bun run build
      - name: Deploy to Bun Cloud
        env:
          BUN_CLOUD_TOKEN: ${{ secrets.BUN_CLOUD_TOKEN }}
        run: bun deploy

This workflow checks out your code, sets up Bun, installs dependencies, runs tests, builds the AdonisJS application, and finally deploys it to Bun Cloud using a BUN_CLOUD_TOKEN stored as a GitHub Secret. This token can be generated from your Bun Cloud account settings.

Conclusion

By combining AdonisJS for a structured, TypeScript-first backend, Bun for lightning-fast development and production, and Bun Cloud for effortless serverless deployment, you create a modern, high-performance web application stack. The addition of CI/CD with GitHub Actions automates your workflow, ensuring consistency, reliability, and speed from development to production. This integrated approach empowers developers to focus on innovation rather than infrastructure complexities.