Files
mtusi2026lab3/compose.yaml
T

79 lines
1.9 KiB
YAML

services:
postgres:
image: postgres:16.4
environment:
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/pg_password
POSTGRES_DB: messenger
secrets: [pg_password]
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 3s
timeout: 3s
retries: 20
migrate:
build: .
depends_on:
postgres:
condition: service_healthy
environment:
DATABASE_URL_FILE: /run/secrets/database_url
secrets: [database_url]
command: ["python", "-c", "from src.db import run_migrations; run_migrations()"]
restart: "no"
api-1:
build: .
depends_on:
migrate:
condition: service_completed_successfully
environment:
SESSION_TTL_SECONDS: "3600"
DATABASE_URL_FILE: /run/secrets/database_url
INSTANCE_ID: api-1
secrets: [database_url]
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request;urllib.request.urlopen('http://localhost:8080/health/ready',timeout=2)"]
interval: 3s
timeout: 3s
retries: 30
api-2:
build: .
depends_on:
migrate:
condition: service_completed_successfully
environment:
SESSION_TTL_SECONDS: "3600"
DATABASE_URL_FILE: /run/secrets/database_url
INSTANCE_ID: api-2
secrets: [database_url]
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request;urllib.request.urlopen('http://localhost:8080/health/ready',timeout=2)"]
interval: 3s
timeout: 3s
retries: 30
lb:
image: nginx:1.27-alpine
ports:
- "8080:8080"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api-1:
condition: service_healthy
api-2:
condition: service_healthy
secrets:
pg_password:
file: ./secrets/pg_password.txt
database_url:
file: ./secrets/database_url.txt
volumes:
pgdata: