Skip to content
Lesson: StagingSwitch
← DevOps Operations

Delivery and containers

Staging

Use a staging environment to try a release before it reaches real users.

Tests on a build machine cannot show everything. Staging is an environment that resembles production, where you try a release before real users see it.

Environments

A common set is:

  • Development: where you write code.
  • Staging: a rehearsal that is as close to production as practical.
  • Production: the real service.

Names and numbers vary between teams.

Keep it similar

Staging is useful only if it is like production. Use the same artifact, the same operating system and database versions, and the same deployment steps. Differences that remain, such as smaller servers or less data, are things staging cannot prove. Note them down.

What should differ is configuration:

bash
cat staging.env
APP_ENV=staging
DATABASE_HOST=db.staging.example.com
PAYMENTS_MODE=test

With Docker you can supply such a file at run time:

bash
docker run -d --env-file staging.env registry.example.com/shop:1.4.0

Stay isolated

Staging must not touch production data or send real emails or payments. Give it its own database and credentials, and test accounts for outside services. Avoid copying raw customer data into it. If you need realistic data, remove or replace personal details first. Restrict who can reach it.

Check it, then promote

After deploying, run a smoke test: a few quick checks that the main features work at all.

bash
curl -fsS https://staging.example.com/health
ok

-f makes curl return a failing status for HTTP errors of 400 and above, -s hides progress and -S still shows errors. The address and reply here are examples. Your application must provide such a page.

If the checks pass, deploy the same artifact to production. If you change anything, build a new version and put it through staging again.

Try it

Create staging.env and production.env with different values for APP_ENV. Write run.sh containing . "./$1.env"; echo "Running in $APP_ENV", then run sh run.sh staging and sh run.sh production. One script, two environments. The leading . reads the file as shell code, so only use files you trust. The shell navigation lab gives you a live shell to practise in.

Check your understanding

Staging

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.