Skip to content

Lesson 8 of 9 · 25m

Deployment Environments, Approvals, and Rollback Design

How to turn a CI pipeline into a controlled deployment system using environments, protection rules, concurrency, and explicit rollback mechanics.

A deployment workflow is not just CI with SSH keys. It is a control system for changing production. The pipeline needs a stable notion of what is being deployed, who authorized it, what is already in flight, and how to recover when the release is bad. If you cannot answer those four questions, you have a script, not a deployment process.

Environments are policy containers

GitHub environments bind secrets, protection rules, reviewers, and deployment history to a named target such as staging or production.

deploy-production:
  needs: package
  if: github.ref == 'refs/heads/main'
  runs-on: ubuntu-latest
  environment: {name: production, url: "https://status.sudosecurity.org"}
  concurrency: {group: deploy-production, cancel-in-progress: false}
  permissions: {contents: read, id-token: write}
  steps:
    - uses: actions/download-artifact@v4
      with:
        name: release-${{ github.sha }}
        path: release/
    - run: ./release/deploy.sh production

The environment key is not decorative. It is where required reviewers and environment secrets attach. The concurrency group prevents two production deployments from interleaving.

Package once, deploy the same thing

The artifact deployed to production should be the artifact tested earlier. Rebuilding during deployment creates a gap between what passed CI and what reached users.

commit SHA ── build ── immutable artifact ── deploy staging
                                      └──── deploy production

Use the commit SHA or content digest in the artifact name. Record provenance. If your platform supports attestations, produce them at build time and verify them before deployment. Humans should approve a known artifact, not a vibe.

Approval is not rollback

Required reviewers slow down risky change. They do not recover from it. A rollback mechanism must exist before deployment: redeploying the previous artifact, shifting traffic back, restoring a database-compatible version, or disabling a feature flag.

set -euo pipefail
target="$1"
echo "current=$(./release/current-version "$target")"
./release/deploy-version "$target" "$GITHUB_SHA"
./release/verify-health "$target" 180

Notice what is missing: magic. Deployment scripts should be boring, idempotent where possible, and loud about the version they think they are changing.

Health checks need failure behavior

After deployment, verify real health: HTTP status, critical endpoints, background worker startup, database migration state. If verification fails, either roll back automatically or stop and page a human with the exact state. Automatically retrying the same broken deploy five times is not resilience.

Field notes

  • Protect production branches separately from production environments; they solve different problems.
  • cancel-in-progress: false is usually correct for deploys, but timeouts keep a hung deploy from blocking forever.
  • Database migrations are the hard part of rollback. Backward-compatible migrations matter more than YAML elegance.
  • Manual approval fatigue is real. Use approvals for meaningful risk boundaries, not every staging deploy.

Was this lesson helpful?

Sign in to rate