forked from mtusi2026/mtusi2026lab3
106 lines
2.9 KiB
YAML
106 lines
2.9 KiB
YAML
services:
|
|
migrate:
|
|
build: .
|
|
command: python -m scripts.run_migrations
|
|
environment:
|
|
- DATABASE_URL=postgresql+asyncpg://mtusi:1878@postgres:5432/mtusi-messenger
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
nginx:
|
|
image: nginx:1.25-alpine
|
|
ports:
|
|
- "8080:80"
|
|
volumes:
|
|
- ./infra/nginx.conf.template:/etc/nginx/templates/nginx.conf.template:ro
|
|
environment:
|
|
- NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx
|
|
- KEEPALIVE_DIRECTIVE=${KEEPALIVE_DIRECTIVE:-}
|
|
- PROXY_HTTP_VERSION_DIRECTIVE=${PROXY_HTTP_VERSION_DIRECTIVE:-}
|
|
- PROXY_CONNECTION_DIRECTIVE=${PROXY_CONNECTION_DIRECTIVE:-}
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${NGINX_CPU:-1.0}'
|
|
memory: ${NGINX_MEM:-256M}
|
|
restart: unless-stopped
|
|
api:
|
|
build: .
|
|
environment:
|
|
- APP_HOST=${APP_HOST}
|
|
- APP_PORT=${APP_PORT}
|
|
- DATABASE_URL=${DATABASE_URL}
|
|
- SESSION_TTL_SECONDS=${SESSION_TTL_SECONDS}
|
|
- REDIS_URL=${REDIS_URL}
|
|
- INSTANCE_ID_PREFIX=api
|
|
- DB_POOL_SIZE=${DB_POOL_SIZE:-10}
|
|
- DB_MAX_OVERFLOW=${DB_MAX_OVERFLOW:-20}
|
|
- DB_POOL_TIMEOUT=${DB_POOL_TIMEOUT:-30}
|
|
- DB_POOL_RECYCLE=${DB_POOL_RECYCLE:-3600}
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"] #засекретить?
|
|
interval: 10s
|
|
timeout: 3s
|
|
start_period: 15s
|
|
retries: 3
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits:
|
|
cpus: '${API_CPU:-1.0}'
|
|
memory: ${API_MEM:-512M}
|
|
|
|
postgres:
|
|
image: postgres:16.3-alpine
|
|
environment:
|
|
POSTGRES_USER: ${POSTGRES_USER}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
|
POSTGRES_DB: ${POSTGRES_DB}
|
|
ports:
|
|
- "127.0.0.1:5433:5432"
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
- ./migrations:/docker-entrypoint-initdb.d:ro
|
|
command: postgres -c shared_preload_libraries=pg_stat_statements
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
start_period: 10s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
|
|
redis:
|
|
image: redis:8.10-alpine
|
|
command: redis-server --appendonly yes --save 60 1
|
|
ports:
|
|
- "127.0.0.1:6379:6379"
|
|
volumes:
|
|
- redisdata:/data
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '${REDIS_CPU:-0.5}'
|
|
memory: ${REDIS_MEM:-256M}
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
start_period: 5s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
pgdata:
|
|
redisdata: |