Skip to content

Promoting a build artifact across staging to production on PaaS: immutable image vs source rebuild

If staging and production rebuild from source independently, you have not promoted a build — you have built two different builds and hoped they match. The fix is one artifact, promoted, with a hash that proves it.

Staging is green. You promote to production. Production fails three minutes after deploy because the production build pulled a fresh point release of one of its transitive dependencies that wasn’t there when staging built five days ago. The staging build and the production build were never the same artifact — they shared a commit, but they’re two different builds. “It worked on staging” was a statistically meaningless statement. The fix is to build once, tag the artifact with a content hash, and promote that exact artifact to production.

What’s happening

Two ways PaaS environments handle the staging-to-production promotion. They have very different failure modes:

  • Source rebuild (anti-pattern). Staging builds from git ref X. Production also builds from git ref X, on a different runner, possibly hours or days later. Even with a lockfile, the OS-level base image, system packages, and any unpinned transitive dep can drift. The artifact you tested is not the artifact you shipped.
  • Immutable image promotion (correct). Staging builds once. The build produces an artifact (container image, JVM jar with checksums, Python wheel + lockfile, language-agnostic tarball) tagged with a content-addressable hash (sha256:abc123...). Production deploys the same hash. Promotion is a pointer change in the PaaS deploy hook, not a rebuild. There is no opportunity for drift because there is no second build.

The reason teams default to source rebuild is that managed PaaS platforms make rebuild the default — the “deploy from git” workflow is the marketed happy path. The fix is to use the platform’s image-deploy mode (most managed PaaS supports it) and treat the registry as the source of truth for what’s promotable.

How to verify

Compare the artifact hash on staging against production. If they differ, you’re not promoting — you’re double-building:

# Get the artifact hash currently serving on staging
curl -sS -H "Authorization: Bearer ${PAAS_TOKEN}" \
  "https://app.paas.example.com/1.0/environment/control/rest/getenvinfo?envName=app-staging" \
  | jq -r '.deployment.imageDigest // .deployment.artifactHash'

# Same on production
curl -sS -H "Authorization: Bearer ${PAAS_TOKEN}" \
  "https://app.paas.example.com/1.0/environment/control/rest/getenvinfo?envName=app-prod" \
  | jq -r '.deployment.imageDigest // .deployment.artifactHash'

# Both should be the SAME hash. If staging is sha256:abc... and prod is sha256:def...,
# you're rebuilding, not promoting.

Confirm the registry has the artifact and that nobody has rewritten the tag:

# Pull the manifest by digest — this works because digests are content-addressable
# A tag like ":v1.42" can be overwritten; a digest cannot.
docker manifest inspect "registry.example.com/app@sha256:abc123def456..."

# Or for a non-container artifact, verify by hash
sha256sum app-v1.42.tar.gz
# Compare against the hash recorded in the deploy log

The fix

Build once. Tag by content hash. Promote the hash.

Step 1 — CI builds the artifact, computes the digest, and stores both.

# .github/workflows/build-once.yaml
name: build-and-tag
on:
  push:
    branches: [main]
    tags: ['v*']

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      image_digest: ${{ steps.push.outputs.digest }}
      image_ref: ${{ steps.push.outputs.image_ref }}
    steps:
      - uses: actions/checkout@v4

      - name: Build container image
        run: |
          # Lockfile-driven build. No `:latest`. No floating tags inside the Dockerfile.
          docker build \
            --pull \
            --tag "registry.example.com/app:${GITHUB_SHA}" \
            --label "org.opencontainers.image.revision=${GITHUB_SHA}" \
            --label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
            .

      - name: Push and capture digest
        id: push
        run: |
          docker push "registry.example.com/app:${GITHUB_SHA}"
          DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' \
            "registry.example.com/app:${GITHUB_SHA}" | awk -F'@' '{print $2}')
          echo "digest=${DIGEST}" >> $GITHUB_OUTPUT
          echo "image_ref=registry.example.com/app@${DIGEST}" >> $GITHUB_OUTPUT
          echo "Built artifact: registry.example.com/app@${DIGEST}"

      - name: Record build manifest
        run: |
          # Persist the (commit -> digest) map somewhere the promotion job can read it
          cat > build-manifest.json <<EOF
          {
            "commit": "${GITHUB_SHA}",
            "digest": "${{ steps.push.outputs.digest }}",
            "image_ref": "${{ steps.push.outputs.image_ref }}",
            "built_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
          }
          EOF
      - uses: actions/upload-artifact@v4
        with:
          name: build-manifest
          path: build-manifest.json

Step 2 — Staging deploy consumes the digest, not a tag, not a branch.

# .github/workflows/deploy-staging.yaml
name: deploy-staging
on:
  workflow_run:
    workflows: [build-and-tag]
    types: [completed]

jobs:
  staging:
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: build-manifest
          run-id: ${{ github.event.workflow_run.id }}

      - name: Deploy by digest to staging
        run: |
          DIGEST=$(jq -r '.digest' build-manifest.json)
          IMAGE_REF="registry.example.com/app@${DIGEST}"

          # PaaS deploy hook — points the env at this exact digest, no rebuild
          curl -fsS -X POST \
            -H "Authorization: Bearer ${{ secrets.PAAS_TOKEN }}" \
            -d "envName=app-staging&imageRef=${IMAGE_REF}" \
            https://app.paas.example.com/1.0/environment/control/rest/deployimage

          echo "Staging now serving ${IMAGE_REF}"

Step 3 — Production promotion is a hash copy, never a rebuild.

# .github/workflows/promote-to-prod.yaml
name: promote-to-prod
on:
  workflow_dispatch:
    inputs:
      staging_digest:
        description: "Digest currently running on staging (sha256:...)"
        required: true
        type: string

jobs:
  promote:
    runs-on: ubuntu-latest
    environment: production       # requires manual approval per the env policy
    steps:
      - name: Verify staging is actually running this digest
        run: |
          STAGING_NOW=$(curl -fsS -H "Authorization: Bearer ${{ secrets.PAAS_TOKEN }}" \
            "https://app.paas.example.com/1.0/environment/control/rest/getenvinfo?envName=app-staging" \
            | jq -r '.deployment.imageDigest')

          if [ "${STAGING_NOW}" != "${{ inputs.staging_digest }}" ]; then
            echo "Staging is on ${STAGING_NOW}, not the digest you're promoting (${{ inputs.staging_digest }})."
            echo "Refusing to promote a digest that wasn't actually validated on staging."
            exit 1
          fi

      - name: Verify the artifact exists in the registry (defense against tag rewrite)
        run: |
          docker manifest inspect "registry.example.com/app@${{ inputs.staging_digest }}" > /dev/null

      - name: Promote — point production at the same digest
        run: |
          IMAGE_REF="registry.example.com/app@${{ inputs.staging_digest }}"
          curl -fsS -X POST \
            -H "Authorization: Bearer ${{ secrets.PAAS_TOKEN }}" \
            -d "envName=app-prod&imageRef=${IMAGE_REF}" \
            https://app.paas.example.com/1.0/environment/control/rest/deployimage

      - name: Verify production is now on the promoted digest
        run: |
          PROD_NOW=$(curl -fsS -H "Authorization: Bearer ${{ secrets.PAAS_TOKEN }}" \
            "https://app.paas.example.com/1.0/environment/control/rest/getenvinfo?envName=app-prod" \
            | jq -r '.deployment.imageDigest')

          if [ "${PROD_NOW}" != "${{ inputs.staging_digest }}" ]; then
            echo "Promotion did not take. Production is on ${PROD_NOW}."
            exit 2
          fi

          echo "Production now serving ${{ inputs.staging_digest }} — identical bytes to staging."

Step 4 — Configuration is the only thing that should differ between environments. If you keep config and secrets out of the image, the same image runs in staging and production. Use environment-scoped config in the PaaS, not bake-in config:

# env-config.yaml — promoted SEPARATELY from the image
environments:
  staging:
    DATABASE_URL: "postgres://staging-pg.internal:5432/app"
    LOG_LEVEL: "debug"
    FEATURE_FLAGS: "experimental=true"
  prod:
    DATABASE_URL: "postgres://prod-pg.internal:5432/app"
    LOG_LEVEL: "info"
    FEATURE_FLAGS: "experimental=false"

The image stays identical. Production-only differences live in environment variables and secrets, not in the artifact.

Step 5 — Health-check the promotion, not just the deploy. Right after the digest swings to production, confirm the running container reports the same image_revision:

# Each pod exposes a /version endpoint that echoes the build-time labels
curl -sS https://app.example.com/version | jq .
# {
#   "git_sha": "abc123...",
#   "image_digest": "sha256:abc123def456...",
#   "built_at": "2026-05-14T10:23:11Z"
# }

# In a deploy hook, assert it matches what you promoted:
RUNNING=$(curl -sS https://app.example.com/version | jq -r '.image_digest')
[ "${RUNNING}" = "${PROMOTED_DIGEST}" ] || exit 2

If your PaaS does not support digest-pinned deploys, the next-best option is a tag that you guarantee is never overwritten (v1.42.7, never latest, never prod) and a registry-level immutability policy that refuses to overwrite that tag. Digest is still better — a tag can be rotated by anyone with push access; a digest cannot lie about its contents.

For build pipelines, registry hygiene, and PaaS deploy hooks that refuse to promote a tag instead of a digest, Stack Harbor’s deployment management plane wires these on top of managed PaaS.