Releasing and running it · lesson 3 of 10
Ideas in this lesson
ADevelopment · test · staging · productionthe usual environments
BConfigurationsettings that differ between environments
CSecreta password or key that must never be in the code

Environments

Last updated

Pila doesn't run in one place. It runs on each developer's laptop, on a test server Rina explores, on a copy that matches the real thing as closely as possible, and on the server the health centre uses. Each copy is an environment. In this lesson you'll see why teams keep several, what should differ between them and what must not, why test data must never be real patients' data, and how to keep passwords and keys out of the code.

By the end of this lesson you can

  • Name the usual environments and what each is for
  • Keep configuration and secrets out of the code
  • Explain why test environments use made-up data, not real personal data

Why several copies

You don't try out a change on the system patients depend on. So teams keep several environments, each a full copy of the software running somewhere:

Pila’s environments
EnvironmentRuns onUsed forData
DevelopmentEach developer’s laptopWriting and trying codeMade up, a few records
TestA small shared serverAutomated tests, Rina’s exploringMade up, reset often
StagingA copy built like productionA last check of a release, in conditions like the real onesMade up, but realistic in size
ProductionThe real serverThe health centre and its patientsReal, and protected

Changes move one way: development, then test, then staging, then production. Each step is closer to the real thing, so problems show up before patients meet them.

What differs, and what mustn’t

The same build should run in every environment. What changes is its configuration: the settings that tell it where it is, such as which database and which gateway account. The Twelve-Factor App's rule is to keep configuration out of the code, in the environment the app runs in, so one image can be deployed anywhere.

0 of 6 placed right

  1. The database address

  2. The SMS gateway key (test mode or live)

  3. The Python version

  4. The code being run

  5. The dependency versions

  6. How many patients’ numbers are in the database

The more staging differs from production, the less a pass on staging means. Teams keep the differences few, and written down.

Secrets stay out of the code

A secret is configuration that gives access: a password, an API key, a token. Pila has three: the database password, the SMS gateway key, and the key that signs staff logins.

Secrets never go in the code or the repository. Everyone who can read the repository could use them, including anyone who sees it in the future, and copies of a repository spread. Instead, each environment holds its own secrets, outside the code, and the code reads them when it starts:

import os

SMS_API_KEY = os.environ["SMS_API_KEY"]

Test and staging get test-mode keys that can't send real texts or reach real data. Only production's settings hold the live ones, and only a few people can see them.

A secret in Git

  1. Monday 10:00 Committed
1 of 5 Monday 10:00. Jun is in a hurry and pastes the live SMS gateway key straight into sms.py. He commits and pushes.

Deleting the secret in a new commit doesn't remove it: Git keeps every earlier version, which is its whole purpose. The first fix is always to revoke and replace the secret. Simple Git's A secret got committed shows the rest of the clean-up, including rewriting history.

Spot the trap: a copy of real patients

Spot the trapRina

Rina wants realistic data to test the waiting-room screen. “Let’s copy last week’s production database to the test server,” Jun suggests. “It’s already got the right shape.”

What happens if…

Check what you learned

What is staging for?
Jun committed a live key, then deleted it in the next commit. Is the problem solved?
Which of these is configuration, not code?

Sources

Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.

All sources for Simple Software Development