feat: Add production and development Docker Compose configurations, health check endpoint, and update documentation

This commit is contained in:
2025-10-27 20:57:36 +01:00
parent a6a5f630cc
commit dcb08ab1b8
7 changed files with 318 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
---
title: "07 — Deployment View"
description: "Describe deployment topology, infrastructure components, and environments (dev/stage/prod)."
title: '07 — Deployment View'
description: 'Describe deployment topology, infrastructure components, and environments (dev/stage/prod).'
status: draft
---
@@ -85,6 +85,14 @@ The development environment is set up for local development and testing. It incl
- Local PostgreSQL instance (docker compose recommended, script available at `docker-compose.postgres.yml`)
- FastAPI server running in debug mode
`docker-compose.dev.yml` encapsulates this topology:
- `api` service mounts the repository for live reloads (`uvicorn --reload`) and depends on the database health check.
- `db` service uses the Debian-based `postgres:16` image with UTF-8 locale configuration and persists data in `pg_data_dev`.
- A shared `calminer_backend` bridge network keeps traffic contained; ports 8000/5432 are published for local tooling.
See [docs/quickstart.md](../quickstart.md#compose-driven-development-stack) for command examples and volume maintenance tips.
### Testing Environment
The testing environment is set up for automated testing and quality assurance. It includes:
@@ -93,6 +101,14 @@ The testing environment is set up for automated testing and quality assurance. I
- FastAPI server running in testing mode
- Automated test suite (e.g., pytest) for running unit and integration tests
`docker-compose.test.yml` provisions an ephemeral CI-like stack:
- `tests` service builds the application image, installs `requirements-test.txt`, runs the database setup script (dry-run + apply), then executes pytest.
- `api` service is available on port 8001 for manual verification against the test database.
- `postgres` service seeds a disposable Postgres 16 instance with health checks and named volumes (`pg_data_test`, `pip_cache_test`).
Typical commands mirror the CI workflow (`docker compose -f docker-compose.test.yml run --rm tests`); the [quickstart](../quickstart.md#compose-driven-test-stack) lists variations and teardown steps.
### Production Environment
The production environment is set up for serving live traffic and includes:
@@ -102,6 +118,22 @@ The production environment is set up for serving live traffic and includes:
- Load balancer (Traefik) for distributing incoming requests
- Monitoring and logging tools for tracking application performance
#### Production docker compose topology
- `docker-compose.prod.yml` defines the runtime topology for operator-managed deployments.
- `api` service runs the FastAPI image with resource limits (`API_LIMIT_CPUS`, `API_LIMIT_MEMORY`) and a `/health` probe consumed by Traefik and the Compose health check.
- `traefik` service (enabled via the `reverse-proxy` profile) terminates TLS using the ACME resolver configured by `TRAEFIK_ACME_EMAIL` and routes `CALMINER_DOMAIN` traffic to the API.
- `postgres` service (enabled via the `local-db` profile) exists for edge deployments without managed PostgreSQL and persists data in the `pg_data_prod` volume while mounting `./backups` for operator snapshots.
- All services join the configurable `CALMINER_NETWORK` (defaults to `calminer_backend`) to keep traffic isolated from host networks.
Deployment workflow:
1. Copy `config/setup_production.env.example` to `config/setup_production.env` and populate domain, registry image tag, database credentials, and resource budgets.
2. Launch the stack with `docker compose --env-file config/setup_production.env -f docker-compose.prod.yml --profile reverse-proxy up -d` (append `--profile local-db` when hosting Postgres locally).
3. Run database migrations and seeding using `docker compose --env-file config/setup_production.env -f docker-compose.prod.yml run --rm api python scripts/setup_database.py --run-migrations --seed-data`.
4. Monitor container health via `docker compose -f docker-compose.prod.yml ps` or Traefik dashboards; the API health endpoint returns `{ "status": "ok" }` when ready.
5. Shut down with `docker compose -f docker-compose.prod.yml down` (volumes persist unless `-v` is supplied).
## Containerized Deployment Flow
The Docker-based deployment path aligns with the solution strategy documented in [Solution Strategy](04_solution_strategy.md) and the CI practices captured in [Testing & CI](07_deployment/07_01_testing_ci.md.md).