|
Download docs/deploy/deployment-guide.md from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 5.65 kB
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/docs/deploy/deployment-guide.md
- Command line
-
hf download hf://spaces/anaselamr/yaz/docs/deploy/deployment-guide.md
-
curl -L -o deployment-guide.md https://huggingface.co/spaces/anaselamr/yaz/resolve/main/docs/deploy/deployment-guide.md
5.65 kB
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)
# 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
# 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)
# 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
podman-compose -f infra/compose.yaml -f docker-compose.production.yml up -d
Database Migrations
# 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 and ADR-007.
Makefile Commands
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=RS256with RSA key pair -
PII_VAULT_KEYset (or KMS/Vault configured) -
CORS_ORIGINScontains onlyhttps://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
.envwith real secrets in git) -
alembic checkpasses (no uncommitted migrations) - Container image scanned by Trivy (0 CRITICAL/HIGH)
- Backups configured (see restore runbook)
- Alerting rules deployed (see runbooks/)
- MFA enforced for admin and surgeon roles
Health Checks
# 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=Nin compose; all instances stateless - Worker scaling: run multiple
python -m workers.workerprocesses
(setYAZ_WORKER_QUEUEto target high/default/low queue) - Read replicas: set
ANALYTICS_DATABASE_URLfor report queries - Redis: use Redis Sentinel or Cluster for HA
CI/CD
Pipeline jobs (in order):
- lint — ruff
- typecheck — mypy
- secret-scan — gitleaks (blocks on detected secrets)
- test — pytest + real PG/Redis
- migration-check — alembic check
- build — buildah → GHCR (
main/masteronly) - trivy-scan — CRITICAL/HIGH → fail