# YAZ Care Platform — Deployment Guide ## Prerequisites - Python 3.12+ - Podman (rootless) or Docker 24+ - Docker Compose v2 or podman-compose - PostgreSQL 16+ (or managed PG) - Redis 7+ - `uv` (dependency manager): `curl -LsSf https://astral.sh/uv/install.sh | sh` --- ## Quick Start (Development) ```bash # 1. Clone and enter git clone https://github.com/Elanass/yaz && cd yaz # 2. Create virtual env + install deps (uv) uv venv && source .venv/bin/activate uv pip install -r requirements.txt # 3. Copy and fill env vars cp .env.example .env # Edit .env: DATABASE_URL, REDIS_URL, JWT_SECRET_KEY, PII_VAULT_KEY # 4. Apply migrations export PYTHONPATH=src alembic upgrade head # 5. Start dev server (hot-reload) uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload --reload-dir src # 6. Start arq worker (separate terminal) python -m workers.worker ``` --- ## Environment Variables All required vars must be present at startup; missing required vars cause `RuntimeError` on boot. | Variable | Required | Default | Description | |---|---|---|---| | `DATABASE_URL` | ✅ | `sqlite:///./data/databases/yaz_care.db` | PostgreSQL or SQLite URL | | `REDIS_URL` | ✅ | `redis://localhost:6379/0` | Redis connection URL | | `JWT_SECRET_KEY` | ✅ prod | `dev-jwt-*` | HMAC secret (HS256 dev) | | `JWT_ALGORITHM` | — | `HS256` | `RS256` in production | | `JWT_PRIVATE_KEY` | ✅ RS256 | — | PEM RSA private key | | `JWT_PUBLIC_KEY` | ✅ RS256 | — | PEM RSA public key | | `PII_VAULT_KEY` | ✅ prod | derived | Base64-encoded 32-byte AES key | | `YAZ_ENV` | — | `development` | `development\|testing\|production` | | `CORS_ORIGINS` | — | localhost | Comma-separated allowed origins | | `SMTP_HOST` | — | — | SMTP server for email jobs | | `SMTP_PORT` | — | `587` | SMTP port | | `SMTP_USER` | — | — | SMTP username | | `SMTP_PASSWORD` | — | — | SMTP password | | `OTEL_EXPORTER_OTLP_ENDPOINT` | — | — | OTLP HTTP endpoint | | `ARGON2_TIME_COST` | — | `3` | Argon2id time parameter | | `ARGON2_MEMORY_COST` | — | `65536` | Argon2id memory (KB) | | `ACCESS_TOKEN_TTL` | — | `900` | Access token seconds (15 min) | | `REFRESH_TOKEN_TTL` | — | `604800` | Refresh token seconds (7 days) | See `.env.example` for the complete annotated list. --- ## Container Deployment ### Build ```bash # Podman (rootless) podman build --target production -t ghcr.io/elanass/yaz-care:latest -f Containerfile . # Docker docker build --target production -t ghcr.io/elanass/yaz-care:latest -f Containerfile . ``` ### Run (compose) ```bash # Development (no nginx) podman-compose -f infra/compose.yaml up -d # With nginx + OTEL collector podman-compose -f infra/compose.yaml --profile production --profile observability up -d ``` ### Production compose ```bash podman-compose -f infra/compose.yaml -f docker-compose.production.yml up -d ``` --- ## Database Migrations ```bash # Apply all migrations alembic upgrade head # Create new migration (after model changes) alembic revision --autogenerate -m "describe the change" # Downgrade one step alembic downgrade -1 # Check for uncommitted changes alembic check ``` **Expand/Contract pattern** — see [migration runbook](runbooks/migration.md) and [ADR-007](adr/ADR-007-expand-contract.md). --- ## Makefile Commands ```bash make install # uv pip install -r requirements.txt make dev # uvicorn with hot-reload make worker # arq worker process make test # full test suite with containers make test-unit # unit tests only (no DB required) make lint # ruff check + format make typecheck # mypy make migrate # alembic upgrade head make migration # alembic revision --autogenerate -m "..." make health # curl /api/v1/health/ready make shell # python shell with app context ``` --- ## Production Hardening Checklist - [ ] `YAZ_ENV=production` - [ ] `DEBUG=false` - [ ] `JWT_ALGORITHM=RS256` with RSA key pair - [ ] `PII_VAULT_KEY` set (or KMS/Vault configured) - [ ] `CORS_ORIGINS` contains only `https://` domains - [ ] PostgreSQL RLS enabled on all org-scoped tables - [ ] Redis password set (`REDIS_PASSWORD`) - [ ] TLS enforced (nginx or cloud LB) - [ ] HSTS header enabled (automatic when `YAZ_ENV=production`) - [ ] Secrets from Vault or SOPS (no `.env` with real secrets in git) - [ ] `alembic check` passes (no uncommitted migrations) - [ ] Container image scanned by Trivy (0 CRITICAL/HIGH) - [ ] Backups configured (see [restore runbook](runbooks/restore.md)) - [ ] Alerting rules deployed (see [runbooks/](runbooks/)) - [ ] MFA enforced for admin and surgeon roles --- ## Health Checks ```bash # Liveness curl http://localhost:8000/api/v1/health # Readiness (DB + Redis) curl http://localhost:8000/api/v1/health/ready # → { "db": "ok", "redis": "ok", "worker": "ok" } # Prometheus metrics curl http://localhost:9090/metrics ``` --- ## Scaling - **Horizontal API scaling**: `WORKERS=N` in compose; all instances stateless - **Worker scaling**: run multiple `python -m workers.worker` processes (set `YAZ_WORKER_QUEUE` to target high/default/low queue) - **Read replicas**: set `ANALYTICS_DATABASE_URL` for report queries - **Redis**: use Redis Sentinel or Cluster for HA --- ## CI/CD Pipeline jobs (in order): 1. **lint** — ruff 2. **typecheck** — mypy 3. **secret-scan** — gitleaks (blocks on detected secrets) 4. **test** — pytest + real PG/Redis 5. **migration-check** — alembic check 6. **build** — buildah → GHCR (`main`/`master` only) 7. **trivy-scan** — CRITICAL/HIGH → fail See [.github/workflows/ci.yml](../.github/workflows/ci.yml).