Files
mtusi2026lab3/compose.yaml
T
2026-10-14 15:25:51 +03:00

115 lines
2.5 KiB
YAML

x-api: &api
build:
context: .
environment:
APP_HOST: 0.0.0.0
APP_PORT: 8080
APP_ENV: lab3
DATABASE_URL_FILE: /run/secrets/database_url
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
CURSOR_SECRET_FILE: /run/secrets/cursor_secret
secrets:
- database_url
- cursor_secret
depends_on:
migrate:
condition: service_completed_successfully
expose:
- "8080"
stop_grace_period: 10s
healthcheck:
test: ["CMD", "/app/.venv/bin/python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2).read()"]
interval: 5s
timeout: 3s
retries: 12
start_period: 10s
deploy:
resources:
limits:
cpus: "0.50"
memory: 256M
services:
postgres:
image: postgres:17.6-alpine
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets:
- postgres_password
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 5s
timeout: 3s
retries: 12
start_period: 5s
deploy:
resources:
limits:
cpus: "0.75"
memory: 512M
migrate:
build:
context: .
command: ["/app/.venv/bin/python", "-m", "src.migrate"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
CURSOR_SECRET_FILE: /run/secrets/cursor_secret
secrets:
- database_url
- cursor_secret
depends_on:
postgres:
condition: service_healthy
restart: "no"
deploy:
resources:
limits:
cpus: "0.25"
memory: 128M
api-a:
<<: *api
api-b:
<<: *api
load_balancer:
image: nginx:1.27.5-alpine
ports:
- "8080:8080"
volumes:
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
api-a:
condition: service_healthy
api-b:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"]
interval: 5s
timeout: 3s
retries: 12
start_period: 5s
deploy:
resources:
limits:
cpus: "0.25"
memory: 128M
secrets:
postgres_password:
file: ./secrets/postgres_password
database_url:
file: ./secrets/database_url
cursor_secret:
file: ./secrets/cursor_secret
volumes:
postgres_data: