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:
| Environment | Runs on | Used for | Data |
|---|---|---|---|
| Development | Each developer’s laptop | Writing and trying code | Made up, a few records |
| Test | A small shared server | Automated tests, Rina’s exploring | Made up, reset often |
| Staging | A copy built like production | A last check of a release, in conditions like the real ones | Made up, but realistic in size |
| Production | The real server | The health centre and its patients | Real, 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
The database address
The SMS gateway key (test mode or live)
The Python version
The code being run
The dependency versions
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
- Monday 10:00 Committed
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
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
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.
- The Twelve-Factor App: III. Config: keep configuration in the environment, not in the code
- GitHub Docs: About secret scanning: how hosting sites spot keys pushed by mistake
- GitHub Docs: Removing sensitive data from a repository: why a deleted secret is still in the history
- Republic Act No. 10173, Data Privacy Act of 2012 (Lawphil): health information is sensitive personal information