Courses / GenAI & LLM / Module 14
Module 14: Deployment: FastAPI, Docker, CI/CD, cloud
12 h · theory 4 · hands-on 5 · project 2 · revision 1
You will be able to
- Package the app as containers with health checks
- Build a GitHub Actions pipeline: test, eval, build, deploy
- Deploy to a VPS or Kubernetes with TLS and secrets
- Roll back safely
Capstone increment: Capstone live at a public HTTPS URL, deployed by CI on merge to main.
Job-description skills: Docker, Kubernetes, CI/CD, FastAPI, Cloud deployment (AWS/Azure/GCP) · Lab tools: docker, docker-compose, kubectl, gh, caddy
1. Package it
Ship the capstone as a container image: a slim Python base, dependencies installed in a cached layer, the app copied last, a non-root user, and a single process (uvicorn) as the entrypoint. Tag every image with the git commit SHA so you always know exactly what's running and can return to it.
Configuration comes from environment variables, validated at startup: fail fast if a required setting is missing rather than on the first request. Secrets come from the platform's secret store, never from the image or the repository.
2. Health checks that mean something
Expose two endpoints. Liveness (/healthz) answers “is the process alive?” and must stay trivial, or a slow dependency gets your container restarted in a loop. Readiness (/readyz) answers “can I serve traffic now?” by checking the database and the model endpoint, so the load balancer stops routing to an instance that can't do useful work.
Add a smoke test after each deploy: one real request through the main endpoint, checked for a valid response. Health checks prove the process runs; the smoke test proves the product works.
3. CI/CD with GitHub Actions
On every pull request: lint, unit tests, and the eval suite (Module 8). On merge to main: build the image, push it to a registry (GitHub Container Registry is free for public repos), deploy, then smoke-test. Each stage only runs if the previous one passed.
Keep deployment credentials in GitHub environment secrets, scope them to the deploy job only, and require approval for the production environment if more than one person works on the project.
4. Where to run it
For a capstone and many real products, a single VPS with Docker Compose and Caddy (automatic HTTPS) is enough and costs a few hundred rupees a month. The model runs either through a hosted API or a separate GPU instance only when needed.
Kubernetes earns its complexity when you have several services, need autoscaling, or run GPU workloads across nodes. Learn the basics (deployments, services, probes, secrets), but don't adopt it until a simpler setup actually hurts.
5. Releasing safely and rolling back
Every deploy should be reversible in one command: redeploy the previous image tag. Practise it before you need it. For riskier changes, send a small share of traffic to the new version first (a canary), compare errors, latency and quality signals with the stable version, then promote or roll back.
Database migrations need extra care: make them backward-compatible (add columns before using them, remove only after the old code is gone) so a rollback doesn't break on the new schema.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 14.1: Containerise the capstone
Write a multi-stage Dockerfile (non-root, slim base, cached dependency layer) and a docker-compose.yml with the API, Postgres, Langfuse and an optional local model. Add /healthz and /readyz.
Expected: docker compose up brings everything up; the image is under 400 MB; readiness fails cleanly when the model endpoint is stopped.
Lab 14.2: Deploy by CI (capstone increment)
Build a GitHub Actions pipeline: tests and evals on pull requests; on merge, build and push an image tagged with the commit SHA to GHCR, deploy to a VPS over SSH with Docker Compose behind Caddy, and run a smoke test.
Expected: The capstone is live at a public HTTPS URL; merging a pull request deploys it with no manual steps.
Lab 14.3: Practise a rollback
Deploy a deliberately broken version (the smoke test should catch it), then roll back to the previous image tag. Time it, and write the runbook.
Expected: A rollback under 5 minutes and docs/runbook.md with the exact commands.
Go deeper
Videos
- Docker Tutorial for Beginners [FULL COURSE in 3 Hours] · TechWorld with Nana · ~166 min. Images, containers, volumes and Compose, explained clearly from zero.
- GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker · TechWorld with Nana · ~32 min. Workflows, jobs and secrets, ending in a pipeline that builds and pushes a Docker image.
Further reading
- Docs FastAPI in Containers - Docker · FastAPI docs. The official way to containerise a FastAPI app, including workers and health checks.
- Docs Building best practices · Docker docs. Small images, layer caching, multi-stage builds and non-root users.
- Docs GitHub Actions documentation · GitHub. Workflows, jobs, secrets and environments for the CI/CD pipeline.
- Article The Twelve-Factor App · Adam Wiggins. Config in the environment, stateless processes, logs as streams: the rules a cloud deployment expects.
GitHub repositories
- docker/awesome-compose: The FastAPI and Postgres samples: compose files with health checks and volumes to copy from.
- fastapi/fastapi: The deployment docs on Docker, HTTPS and workers: what the framework authors recommend.
- vllm-project/vllm: The Docker deployment docs, if you serve your own model next to the app.
Checkpoint quiz
Interview questions
- Walk me through your CI/CD pipeline from pull request to production.
- What’s the difference between liveness and readiness checks, and what does each check in your service?
- How do you roll back a bad deploy, and how long does it take?
- How do you handle secrets across local development, CI and production?
- Would you use Kubernetes for this capstone? Why or why not?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).