forked from mtusi2026/mtusi2026lab3
127 lines
2.8 KiB
YAML
127 lines
2.8 KiB
YAML
services:
|
|
postgres:
|
|
image: postgres:16.8-alpine
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets:
|
|
- postgres_password
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
networks:
|
|
- backend
|
|
healthcheck:
|
|
test: ['CMD-SHELL', 'pg_isready -U messenger -d messenger']
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 12
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${POSTGRES_CPU_LIMIT:-1.0}'
|
|
memory: '${POSTGRES_MEMORY_LIMIT:-1G}'
|
|
|
|
redis:
|
|
image: redis:7.4.2-alpine
|
|
command: ['redis-server', '--appendonly', 'yes', '--appendfsync', 'everysec']
|
|
volumes:
|
|
- redis_data:/data
|
|
networks:
|
|
- backend
|
|
healthcheck:
|
|
test: ['CMD', 'redis-cli', 'ping']
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 12
|
|
restart: unless-stopped
|
|
|
|
migrate:
|
|
build: .
|
|
command: ['python', 'scripts/migrate.py']
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets:
|
|
- database_url
|
|
networks:
|
|
- backend
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: 'no'
|
|
|
|
api:
|
|
build: .
|
|
environment:
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
SESSION_STORE: redis
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL: redis://redis:6379/0
|
|
secrets:
|
|
- database_url
|
|
networks:
|
|
- backend
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
redis:
|
|
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: 3
|
|
start_period: 10s
|
|
stop_grace_period: 15s
|
|
restart: unless-stopped
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits:
|
|
cpus: '${API_CPU_LIMIT:-1.0}'
|
|
memory: '${API_MEMORY_LIMIT:-512M}'
|
|
|
|
nginx:
|
|
image: nginx:1.27.5-alpine
|
|
ports:
|
|
- '${APP_PORT:-8080}:8080'
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
|
networks:
|
|
- frontend
|
|
- backend
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ['CMD-SHELL', 'wget -q -O /dev/null http://127.0.0.1:8080/health/ready']
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
|
|
networks:
|
|
frontend:
|
|
backend:
|
|
internal: true
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
|
|
secrets:
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
database_url:
|
|
file: ./secrets/database_url
|