forked from mtusi2026/mtusi2026lab3
89 lines
2.1 KiB
YAML
89 lines
2.1 KiB
YAML
x-api: &api
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
env_file: [.env]
|
|
environment:
|
|
APP_HOST: "0.0.0.0"
|
|
APP_PORT: "8080"
|
|
APP_ENV: "lab"
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
SESSION_STORE: "postgres"
|
|
SESSION_TTL_SECONDS: "3600"
|
|
# INSTANCE_ID сгенерируется в config.go
|
|
secrets: [database_url, cache_url]
|
|
depends_on:
|
|
postgres: { condition: service_healthy }
|
|
redis: { condition: service_healthy }
|
|
networks: [backend]
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:16.3-alpine
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
POSTGRES_DB: messenger
|
|
secrets: [postgres_password]
|
|
volumes: [pgdata:/var/lib/postgresql/data]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
networks: [backend]
|
|
deploy:
|
|
resources:
|
|
limits: { cpus: "${PG_CPUS:-1.0}", memory: "${PG_MEM:-512M}" }
|
|
|
|
redis:
|
|
image: redis:7.2.5-alpine
|
|
command: ["redis-server", "--appendonly", "yes", "--save"]
|
|
volumes: [redisdata:/data]
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
networks: [backend]
|
|
api:
|
|
<<: *api
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits:
|
|
cpus: "${API_CPU_PER_REPLICA:-0.5}"
|
|
memory: "${API_MEM_PER_REPLICA:-128M}"
|
|
|
|
migrate:
|
|
<<: *api
|
|
entrypoint: ["/app/migrate.sh"]
|
|
depends_on:
|
|
postgres: { condition: service_healthy }
|
|
deploy:
|
|
replicas: 1
|
|
restart_policy:
|
|
condition: "no"
|
|
|
|
lb:
|
|
image: nginx:1.27.0-alpine
|
|
volumes:
|
|
- ./infra/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
ports:
|
|
- "8080:8080"
|
|
depends_on: [api]
|
|
networks: [backend]
|
|
|
|
volumes:
|
|
pgdata:
|
|
redisdata:
|
|
|
|
networks:
|
|
backend:
|
|
driver: bridge
|
|
|
|
secrets:
|
|
postgres_password: { file: ./secrets/postgres_password.txt }
|
|
database_url: { file: ./secrets/database_url.txt }
|
|
cache_url: { file: ./secrets/cache_url.txt } |