forked from mtusi2026/mtusi2026lab3
175 lines
3.9 KiB
YAML
175 lines
3.9 KiB
YAML
name: mtusi-lab3
|
|
|
|
x-api-common: &api-common
|
|
image: mtusi-lab3-api:local
|
|
environment: &api-environment
|
|
APP_HOST: ${APP_HOST:-0.0.0.0}
|
|
APP_PORT: 8080
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
DB_TIMEOUT_MS: ${DB_TIMEOUT_MS:-3000}
|
|
DB_MAX_CONNS: ${DB_MAX_CONNS:-10}
|
|
DATABASE_URL_FILE: ${DATABASE_URL_FILE:-/run/secrets/database_url}
|
|
CACHE_URL_FILE: ${CACHE_URL_FILE:-/run/secrets/cache_url}
|
|
secrets:
|
|
- database_url
|
|
- cache_url
|
|
networks:
|
|
- frontend
|
|
- backend
|
|
healthcheck:
|
|
test: ["CMD", "/messenger", "healthcheck"]
|
|
interval: 3s
|
|
timeout: 2s
|
|
retries: 20
|
|
start_period: 3s
|
|
restart: unless-stopped
|
|
init: true
|
|
stop_grace_period: 10s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.50"
|
|
memory: 192M
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:17.6-alpine3.22
|
|
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
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.00"
|
|
memory: 512M
|
|
|
|
redis:
|
|
image: redis:8.2.1-alpine3.22
|
|
command:
|
|
- /bin/sh
|
|
- -ec
|
|
- exec redis-server --appendonly yes --appendfsync always --requirepass "$$(cat /run/secrets/redis_password)"
|
|
secrets:
|
|
- redis_password
|
|
volumes:
|
|
- redis_data:/data
|
|
networks:
|
|
- backend
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "redis-cli --no-auth-warning -a \"$$(cat /run/secrets/redis_password)\" ping | grep PONG"]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 20
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
|
|
migrate:
|
|
image: mtusi-lab3-api:local
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
command: ["migrate"]
|
|
environment:
|
|
<<: *api-environment
|
|
secrets:
|
|
- database_url
|
|
networks:
|
|
- backend
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
|
|
api1:
|
|
<<: *api-common
|
|
environment:
|
|
<<: *api-environment
|
|
INSTANCE_ID: api-1
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
redis:
|
|
condition: service_healthy
|
|
|
|
api2:
|
|
<<: *api-common
|
|
environment:
|
|
<<: *api-environment
|
|
INSTANCE_ID: api-2
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
redis:
|
|
condition: service_healthy
|
|
|
|
nginx:
|
|
image: nginx:1.29.1-alpine3.22
|
|
command: ["/bin/sh", "/health-aware.sh"]
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
- ./infra/health-aware.sh:/health-aware.sh:ro
|
|
networks:
|
|
- frontend
|
|
depends_on:
|
|
api1:
|
|
condition: service_healthy
|
|
api2:
|
|
condition: service_healthy
|
|
ports:
|
|
- "127.0.0.1:${APP_PORT:-8080}:8080"
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"]
|
|
interval: 3s
|
|
timeout: 2s
|
|
retries: 20
|
|
restart: unless-stopped
|
|
stop_grace_period: 5s
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.25"
|
|
memory: 64M
|
|
|
|
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:
|
|
frontend:
|
|
backend:
|
|
internal: true
|