Skip to content

Chapter 10: Deployment

10.1 First deployment, step by step

  1. AWS: Chapters 4–7 done; security groups named; RDS private; Elastic IP + DNS.
  2. Server: hardened (Chapter 6.2); Docker installed; deploy user created.
  3. Code: git clone the repo into /home/<user>/<project>; check out the release tag/branch.
  4. .env: written by hand from .env.example; every secret generated; COMPOSE_FILE set; chmod 600.
  5. Pre-flight:
    docker compose config --services                        # expected services, no missing-variable errors
    docker compose config | grep -nE 'published|host_ip'    # only host_ip 127.0.0.1 / published "8000"
    
  6. Start: docker compose up -d --build.
  7. Migrate: docker compose exec api python manage.py migrate (and collectstatic if nginx serves static).
  8. nginx + certbot (Chapter 9.1).
  9. Verify (Chapter 11). Not done until every row passes.
  10. 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.