Files
mtusi2026lab3/compose.yaml
T

106 lines
2.6 KiB
YAML

x-api: &api
build: .
image: mtusi-messenger:lab3
expose:
- "8080"
environment:
APP_HOST: 0.0.0.0
APP_PORT: "8080"
APP_ENV: lab
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DATABASE_URL: postgresql://messenger:messenger@postgres:5432/messenger
SESSION_STORE: postgres
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
depends_on:
migrate:
condition: service_completed_successfully
postgres:
condition: service_healthy
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: 20
start_period: 5s
restart: unless-stopped
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: messenger
POSTGRES_PASSWORD: messenger
POSTGRES_DB: messenger
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 3s
timeout: 3s
retries: 20
restart: unless-stopped
migrate:
build: .
image: mtusi-messenger:lab3
environment:
DATABASE_URL: postgresql://messenger:messenger@postgres:5432/messenger
command: ["python", "/app/scripts/migrate.py"]
depends_on:
postgres:
condition: service_healthy
restart: "no"
api1:
<<: *api
hostname: api1
environment:
APP_HOST: 0.0.0.0
APP_PORT: "8080"
APP_ENV: lab
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DATABASE_URL: postgresql://messenger:messenger@postgres:5432/messenger
SESSION_STORE: postgres
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
INSTANCE_ID: api1
api2:
<<: *api
hostname: api2
environment:
APP_HOST: 0.0.0.0
APP_PORT: "8080"
APP_ENV: lab
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DATABASE_URL: postgresql://messenger:messenger@postgres:5432/messenger
SESSION_STORE: postgres
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
INSTANCE_ID: api2
lb:
image: nginx:1.27-alpine
ports:
- "127.0.0.1:${HOST_PORT:-8080}:80"
volumes:
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
api1:
condition: service_healthy
api2:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1/health/live"]
interval: 3s
timeout: 3s
retries: 20
restart: unless-stopped
volumes:
pgdata: