forked from mtusi2026/mtusi2026lab3
164 lines
3.6 KiB
YAML
164 lines
3.6 KiB
YAML
name: mtusi-messenger-lab3
|
|
|
|
services:
|
|
db:
|
|
image: postgres:16.4-alpine
|
|
restart: unless-stopped
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: 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: 3s
|
|
timeout: 3s
|
|
retries: 20
|
|
start_period: 5s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 1G
|
|
|
|
redis:
|
|
image: redis:7.4.1-alpine
|
|
restart: unless-stopped
|
|
command:
|
|
- sh
|
|
- -ec
|
|
- exec redis-server --dir /data --appendonly yes --appendfsync everysec --save 60 1 --requirepass "$$(cat /run/secrets/redis_password)"
|
|
secrets:
|
|
- redis_password
|
|
volumes:
|
|
- redis_data:/data
|
|
networks:
|
|
- backend
|
|
healthcheck:
|
|
test:
|
|
- CMD-SHELL
|
|
- 'REDISCLI_AUTH="$$(cat /run/secrets/redis_password)" redis-cli ping | grep -q PONG'
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 20
|
|
start_period: 5s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 256M
|
|
|
|
migrate:
|
|
image: mtusi-messenger-lab3-api:local
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
args:
|
|
BUILD_REVISION: ${BUILD_REVISION:-local}
|
|
command: ["python", "-m", "src.app.migrate"]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets:
|
|
- database_url
|
|
networks:
|
|
- backend
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 256M
|
|
|
|
api:
|
|
image: mtusi-messenger-lab3-api:local
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
args:
|
|
BUILD_REVISION: ${BUILD_REVISION:-local}
|
|
restart: unless-stopped
|
|
stop_grace_period: 8s
|
|
environment:
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
secrets:
|
|
- database_url
|
|
- cache_url
|
|
networks:
|
|
- backend
|
|
- edge
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
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: 2s
|
|
retries: 3
|
|
start_period: 10s
|
|
deploy:
|
|
mode: replicated
|
|
replicas: 2
|
|
resources:
|
|
limits:
|
|
cpus: "0.50"
|
|
memory: 512M
|
|
|
|
lb:
|
|
image: nginx:1.28.0-alpine
|
|
restart: unless-stopped
|
|
ports:
|
|
- "127.0.0.1:${APP_PORT:-8080}:8080"
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
|
networks:
|
|
- edge
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"]
|
|
interval: 3s
|
|
timeout: 2s
|
|
retries: 5
|
|
start_period: 5s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
|
|
secrets:
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
redis_password:
|
|
file: ./secrets/redis_password
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
cache_url:
|
|
file: ./secrets/cache_url
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
|
|
networks:
|
|
backend:
|
|
internal: true
|
|
edge:
|