Files
mtusi2026lab3/compose.yaml
T

90 lines
2.3 KiB
YAML

services:
db:
image: postgres:16.8-alpine
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
secrets: [db_password]
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 2s
timeout: 3s
retries: 30
restart: unless-stopped
cpus: '1.0'
mem_limit: 512m
migrate:
build: .
command: ["python", "-m", "app.migrate"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
secrets: [database_url]
depends_on:
db:
condition: service_healthy
restart: 'no'
api1:
build: .
environment:
API_INSTANCE_ID: api1
DATABASE_URL_FILE: /run/secrets/database_url
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
secrets: [database_url]
depends_on:
migrate:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"]
interval: 3s
timeout: 3s
retries: 3
start_period: 5s
stop_grace_period: 15s
restart: unless-stopped
cpus: '0.5'
mem_limit: 256m
api2:
build: .
environment:
API_INSTANCE_ID: api2
DATABASE_URL_FILE: /run/secrets/database_url
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
secrets: [database_url]
depends_on:
migrate:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"]
interval: 3s
timeout: 3s
retries: 3
start_period: 5s
stop_grace_period: 15s
restart: unless-stopped
cpus: '0.5'
mem_limit: 256m
lb:
image: nginx:1.27.5-alpine
ports:
- "127.0.0.1:8080:8080"
volumes:
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api1:
condition: service_healthy
api2:
condition: service_healthy
restart: unless-stopped
cpus: '0.5'
mem_limit: 128m
secrets:
db_password:
file: ./secrets/db_password
database_url:
file: ./secrets/database_url
volumes:
postgres_data: