forked from mtusi2026/mtusi2026lab3
75 lines
2.0 KiB
YAML
75 lines
2.0 KiB
YAML
|
|
services:
|
|
db:
|
|
image: postgres:16-alpine
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set password in .env}
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
restart: unless-stopped
|
|
|
|
migrate:
|
|
build: .
|
|
command: ["python", "-m", "src.migrate"]
|
|
environment:
|
|
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD}@db:5432/messenger
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
|
|
api1:
|
|
build: .
|
|
environment:
|
|
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD}@db:5432/messenger
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
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=3)"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
stop_grace_period: 15s
|
|
restart: unless-stopped
|
|
|
|
api2:
|
|
build: .
|
|
environment:
|
|
DATABASE_URL: postgresql://messenger:${POSTGRES_PASSWORD}@db:5432/messenger
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
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=3)"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
stop_grace_period: 15s
|
|
restart: unless-stopped
|
|
|
|
nginx:
|
|
image: nginx:1.29-alpine
|
|
ports:
|
|
- "127.0.0.1:8080:80"
|
|
volumes:
|
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
depends_on:
|
|
api1:
|
|
condition: service_healthy
|
|
api2:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
postgres_data:
|