infra/.planning/phases/01-infrastructure-and-deployment/01-01-PLAN.md

6.7 KiB

phase plan type wave depends_on files_modified autonomous requirements must_haves
01-infrastructure-and-deployment 01 execute 1
stacks/f1-stream/files/backend/main.py
stacks/f1-stream/files/backend/requirements.txt
stacks/f1-stream/files/Dockerfile
stacks/f1-stream/files/redeploy.sh
true
DEPL-01
truths artifacts key_links
A Docker image viktorbarzin/f1-stream:v2.0.0 exists and can be pulled
The image starts a FastAPI server on port 8000 that responds to GET /health with 200
The image is based on python:3.13-slim-bookworm and runs without errors
path provides contains
stacks/f1-stream/files/backend/main.py FastAPI app with health endpoint /health
path provides contains
stacks/f1-stream/files/backend/requirements.txt Python dependencies fastapi
path provides contains
stacks/f1-stream/files/Dockerfile Multi-stage Docker build for Python FastAPI python:3.13-slim-bookworm
path provides contains
stacks/f1-stream/files/redeploy.sh Build, push, restart script docker build
from to via pattern
stacks/f1-stream/files/Dockerfile stacks/f1-stream/files/backend/main.py COPY backend/ into image COPY.*backend
from to via pattern
stacks/f1-stream/files/Dockerfile stacks/f1-stream/files/backend/requirements.txt pip install requirements pip install.*requirements
Create a minimal FastAPI backend application with a health endpoint and build a Docker image for it. This replaces the existing Go-based f1-stream application with the new Python/FastAPI stack.

Purpose: Provide a deployable container image that the Terraform stack (Plan 02) will reference. The health endpoint proves the service is running correctly. Output: Docker image viktorbarzin/f1-stream:v2.0.0 pushed to Docker Hub, containing a working FastAPI server.

<execution_context> @/Users/viktorbarzin/.claude/get-shit-done/workflows/execute-plan.md @/Users/viktorbarzin/.claude/get-shit-done/templates/summary.md </execution_context>

@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/research/STACK.md

Existing files to replace/modify:

@stacks/f1-stream/files/Dockerfile @stacks/f1-stream/files/redeploy.sh

Task 1: Create FastAPI backend application with health endpoint stacks/f1-stream/files/backend/main.py, stacks/f1-stream/files/backend/requirements.txt Create the directory `stacks/f1-stream/files/backend/`.

Create stacks/f1-stream/files/backend/requirements.txt with pinned versions:

fastapi==0.132.0
uvicorn[standard]

Create stacks/f1-stream/files/backend/main.py with a minimal FastAPI application:

  • Import FastAPI
  • Create app instance with title "F1 Streams"
  • Add GET /health endpoint that returns {"status": "ok"}
  • Add GET / root endpoint that returns {"service": "f1-streams", "version": "2.0.0"}
  • Add an if __name__ == "__main__" block that runs uvicorn on host 0.0.0.0 port 8000

This is intentionally minimal -- just enough to prove the deployment works. Later phases will add schedule, extractor, and proxy routes.

Do NOT add any other dependencies or routes beyond the health check and root. Keep it simple. Run python3 -c "import ast; ast.parse(open('stacks/f1-stream/files/backend/main.py').read()); print('Syntax OK')" to verify the Python file is valid. Verify requirements.txt exists and contains fastapi and uvicorn. backend/main.py exists with a valid FastAPI app that has /health and / endpoints. requirements.txt lists fastapi and uvicorn.

Task 2: Create Dockerfile and build/push the container image stacks/f1-stream/files/Dockerfile, stacks/f1-stream/files/redeploy.sh Replace the existing Go Dockerfile at `stacks/f1-stream/files/Dockerfile` with a Python-based Dockerfile:
FROM python:3.13-slim-bookworm

WORKDIR /app

COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY backend/ ./backend/

EXPOSE 8000

CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000"]

Key points:

  • Single-stage build (no build stage needed for Python -- interpreted language)
  • Use python:3.13-slim-bookworm as base (from stack research)
  • Install deps first for Docker layer caching
  • Expose port 8000 (FastAPI default, different from old Go app's 8080)
  • Run via uvicorn pointing to backend.main:app

Update stacks/f1-stream/files/redeploy.sh:

#!/usr/bin/env bash
set -e

docker build -t viktorbarzin/f1-stream:v2.0.0 -t viktorbarzin/f1-stream:latest .
docker push viktorbarzin/f1-stream:v2.0.0
docker push viktorbarzin/f1-stream:latest
kubectl -n f1-stream rollout restart deployment f1-stream

Then build and push the image by running the redeploy script from the stacks/f1-stream/files/ directory. Only run the docker build and push steps (skip the kubectl rollout -- that happens after Terraform apply in Plan 02).

Build command: cd stacks/f1-stream/files && docker build -t viktorbarzin/f1-stream:v2.0.0 -t viktorbarzin/f1-stream:latest . && docker push viktorbarzin/f1-stream:v2.0.0 && docker push viktorbarzin/f1-stream:latest

IMPORTANT: The old Go application files (main.go, go.mod, go.sum, internal/, node_modules/, package.json, package-lock.json, index.html, static/) should be removed from stacks/f1-stream/files/ since they are no longer needed. Keep only: Dockerfile, redeploy.sh, and backend/. Run docker images | grep f1-stream to confirm the image was built. Run docker run --rm -d -p 18000:8000 --name f1-test viktorbarzin/f1-stream:v2.0.0 && sleep 2 && curl -s http://localhost:18000/health && docker stop f1-test to verify the container starts and the health endpoint responds. Docker image viktorbarzin/f1-stream:v2.0.0 is built, pushed to Docker Hub, and serves a 200 response on GET /health when run locally.

1. `docker images | grep f1-stream` shows the v2.0.0 tag 2. Running the image locally and curling /health returns `{"status": "ok"}` 3. The old Go files have been removed from `stacks/f1-stream/files/` 4. Only Dockerfile, redeploy.sh, and backend/ remain in the files directory

<success_criteria>

  • Docker image viktorbarzin/f1-stream:v2.0.0 exists on Docker Hub
  • The image runs a FastAPI server on port 8000 with a working /health endpoint
  • Old Go application files are cleaned up </success_criteria>
After completion, create `.planning/phases/01-infrastructure-and-deployment/01-01-SUMMARY.md`