forked from mtusi2026/mtusi2026lab3
122 lines
2.7 KiB
YAML
122 lines
2.7 KiB
YAML
name: mtusi2026lab3
|
|
|
|
services:
|
|
lb:
|
|
image: nginx:1.27.2
|
|
ports:
|
|
- "8080:8080"
|
|
volumes:
|
|
- ./infra/nginx/nginx.conf:/etc/nginx/nginx.conf.template:ro
|
|
- ./infra/nginx/run.sh:/usr/local/bin/run-nginx.sh:ro
|
|
command: ["/bin/sh", "/usr/local/bin/run-nginx.sh"]
|
|
depends_on:
|
|
api1:
|
|
condition: service_healthy
|
|
api2:
|
|
condition: service_healthy
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128M
|
|
|
|
api1: &api
|
|
build: .
|
|
image: mtusi2026lab3-api:local
|
|
environment: &api-env
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
APP_ENV: lab
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
INSTANCE_ID: api1
|
|
secrets: &api-secrets
|
|
- database_url
|
|
- cache_url
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
healthcheck: &api-healthcheck
|
|
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 5
|
|
start_period: 10s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 256M
|
|
|
|
api2:
|
|
<<: *api
|
|
environment:
|
|
<<: *api-env
|
|
INSTANCE_ID: api2
|
|
|
|
migrate:
|
|
build: .
|
|
image: mtusi2026lab3-api:local
|
|
command: ["python", "-m", "app.migrate"]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets:
|
|
- database_url
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
|
|
postgres:
|
|
image: postgres:16.4
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets:
|
|
- postgres_password
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512M
|
|
|
|
redis:
|
|
image: redis:7.4.1
|
|
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec"]
|
|
volumes:
|
|
- redisdata:/data
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 256M
|
|
|
|
volumes:
|
|
pgdata:
|
|
redisdata:
|
|
|
|
secrets:
|
|
database_url:
|
|
file: ./secrets/database_url.txt
|
|
cache_url:
|
|
file: ./secrets/cache_url.txt
|
|
postgres_password:
|
|
file: ./secrets/postgres_password.txt
|