Chapter 10: Deployment¶
10.1 First deployment, step by step¶
- AWS: Chapters 4–7 done; security groups named; RDS private; Elastic IP + DNS.
- Server: hardened (Chapter 6.2); Docker installed; deploy user created.
- Code:
git clonethe repo into/home/<user>/<project>; check out the release tag/branch. .env: written by hand from.env.example; every secret generated;COMPOSE_FILEset;chmod 600.- Pre-flight:
- Start:
docker compose up -d --build. - Migrate:
docker compose exec api python manage.py migrate(andcollectstaticif nginx serves static). - nginx + certbot (Chapter 9.1).
- Verify (Chapter 11). Not done until every row passes.
- Record what you did (date, commit, changes) in your ops log.
10.2 Routine deployment¶
cd /home/<user>/<project>
git status # no unexpected local edits on the server
git fetch && git checkout <release> # or git pull on the deploy branch
docker compose up -d --build
docker compose exec api python manage.py migrate
docker compose ps # all up / healthy
docker compose logs --tail=50 api # no errors
Then the quick checks from Chapter 11 (rows 1, 2, 7, 10).
Rollback: git checkout <previous release> && docker compose up -d --build. Migrations must be backward-compatible or have a tested reverse.