Part 6: Stages and CI
Deploy another stage
Section titled “Deploy another stage”pnpm alchemy deploy --stage stagingbun alchemy deploy --stage stagingnpx alchemy deploy --stage stagingyarn alchemy deploy --stage stagingEach stage builds its own snapshots, named after the stage, and its own Worker and API key, so changing the snapshots in one stage never reaches another. Without --stage, you deploy to live_$USER.
Sandboxes a stage’s Worker creates carry the stage in their alchemy.stage label. Destroying a stage doesn’t delete them, so list a stage’s sandboxes by that label to clean them up.
Keep state in Cloudflare
Section titled “Keep state in Cloudflare”CI runs start from an empty disk, so store state where every run can read it:
{ providers: Layer.mergeAll(Cloudflare.providers(), Daytona.providers()), state: Alchemy.localState(), state: Cloudflare.state(), },Store the key
Section titled “Store the key”Daytona has no keyless CI login. Create an API key with manage:api_keys (the Worker’s binding creates a key of its own), and add it to the repository’s secrets as DAYTONA_API_KEY. Alchemy reads it instead of a profile.
Deploy per pull request
Section titled “Deploy per pull request”name: Deployon: pull_request: push: branches: [main]
jobs: deploy: runs-on: ubuntu-latest env: DAYTONA_API_KEY: ${{ secrets.DAYTONA_API_KEY }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} STAGE: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'prod' }} steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v2 - run: bun install - run: bun alchemy deploy --stage "$STAGE" --yesEach pull request gets its own stage, and so its own base: a pull request that changes Base or Warm rebuilds them for that stage only.
Clean up closed pull requests
Section titled “Clean up closed pull requests”name: Cleanupon: pull_request: types: [closed]
jobs: destroy: runs-on: ubuntu-latest env: DAYTONA_API_KEY: ${{ secrets.DAYTONA_API_KEY }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v2 - run: bun install - run: bun alchemy destroy --stage "pr-${{ github.event.number }}" --yesDestroying the stage deletes its snapshots and the Worker’s key.