Staging and Production Deployments
Take one task-board application from local tests to a real delivery pipeline: continuous integration fundamentals, push and pull-request quality gates, lint, type-check, unit, component and end-to-end gates, dependency caching, matrix builds, artifacts and checksums, secrets and supply-chain security, release promotion, staging and production, rollback and observability.
What you will be able to do
#- Inject configuration at deploy time so one artifact serves all environments.
- Order promotion from staging to production.
- Describe canary and blue/green strategies.
Overview
#Environments are separate targets
Staging and production are environments: named targets with their own configuration, secrets and rules. The same artifact can be deployed to each, but the configuration differs. Configuration must be injected at deploy time, not baked into the artifact, so one tested artifact can serve both environments.
jobs:
deploy-staging:
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/download-artifact@v4
with:
name: web-dist
path: dist
- run: ./deploy.sh
env:
API_BASE_URL: ${{ vars.STAGING_API_BASE_URL }}
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
environment: production
steps:
- run: ./deploy.sh
env:
API_BASE_URL: ${{ vars.PRODUCTION_API_BASE_URL }}
Configuration versus secrets
Non-sensitive configuration such as an API base URL is a variable. Credentials are secrets. Keep them in the correct store per environment so a staging value never reaches production.
Smoke tests after deploy
A deploy is not done when the command returns. Run a small set of checks against the deployed environment: a health endpoint, a critical route and an authenticated flow. A smoke test turns "the deploy command succeeded" into "the environment works".
Deploy strategies
A canary sends a small share of traffic to the new version and watches error rates before increasing it. Blue/green keeps two environments and switches traffic between them. Both reduce the blast radius of a bad release compared to a full cutover.
Promotion order
Deploy to staging first, run smoke tests, then promote the same artifact to production. If staging fails, production is never touched. This ordering is the practical meaning of a promotion pipeline.
Sandbox boundary
The browser sandbox cannot deploy to an environment or read environment variables from a runner. The exercises here are authored configuration and reasoning.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Implement
Add a staging deploy job and a production deploy job that reuses the same downloaded artifact but reads a different configuration variable.
starter.yamljobs: deploy-staging: runs-on: ubuntu-latest steps: - run: ./deploy.shReveal the reference answer
reference.yamljobs: deploy-staging: runs-on: ubuntu-latest environment: staging steps: - uses: actions/download-artifact@v4 with: name: web-dist path: dist - run: ./deploy.sh env: API_BASE_URL: ${{ vars.STAGING_API_BASE_URL }} deploy-production: needs: deploy-staging runs-on: ubuntu-latest environment: production steps: - run: ./deploy.sh env: API_BASE_URL: ${{ vars.PRODUCTION_API_BASE_URL }}Authored expected output: A staging job and a production job that needs staging, each reading its own configuration variable.
The artifact is identical; only the injected configuration differs. needs: deploy-staging enforces the promotion order.
Exercise 2Debug
This production job reads the staging secret name. Fix it to use the production variable.
starter.yaml- run: ./deploy.sh env: API_BASE_URL: ${{ vars.STAGING_API_BASE_URL }}Reveal the reference answer
reference.yaml- run: ./deploy.sh env: API_BASE_URL: ${{ vars.PRODUCTION_API_BASE_URL }}Authored expected output: The production job reads PRODUCTION_API_BASE_URL.
Using a staging value in production points the deployed app at the wrong backend, a common and costly configuration bug.
Exercise 3Predict
A canary deploy sends five percent of traffic to the new version. What is it for?
Exercise 4Interview
How do you configure the same artifact for staging and production without rebuilding?
Reveal the reference answer
reference.textInject configuration at deploy time through environment variables or a runtime config file, not at build time. The artifact contains code only. Each environment supplies its own API base URL, feature defaults and credentials, so the tested bytes are identical in both environments.Authored expected output: A correct answer describes runtime configuration injection so the artifact stays identical.
Build-time configuration forces a rebuild per environment, which breaks artifact identity. Runtime injection keeps one tested artifact.
Common misconceptions
#- Each environment needs its own rebuilt artifact.
- A deploy is complete when the command returns.
- Staging and production can share secret names.
Follow-up practice
#- cicd-14-rollback-and-observability
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.