forked from mtusi2026/mtusi2026lab3
готово
This commit is contained in:
+117
@@ -0,0 +1,117 @@
|
||||
x-logging: &logging
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
x-app: &app
|
||||
build: .
|
||||
image: mtusi-messenger:lab3
|
||||
env_file: ${ENV_FILE:-.env}
|
||||
logging: *logging
|
||||
|
||||
services:
|
||||
postgres:
|
||||
logging: *logging
|
||||
image: postgres:16.6-bookworm
|
||||
cpus: ${POSTGRES_CPUS:-1.0}
|
||||
mem_limit: 512m
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:-messenger}
|
||||
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Задай POSTGRES_PASSWORD в .env}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
|
||||
redis:
|
||||
logging: *logging
|
||||
image: redis:7.4.2-bookworm
|
||||
cpus: 0.25
|
||||
mem_limit: 128m
|
||||
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always", "--maxmemory", "64mb", "--maxmemory-policy", "noeviction"]
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
|
||||
migration:
|
||||
<<: *app
|
||||
command: ["alembic", "upgrade", "head"]
|
||||
cpus: 0.5
|
||||
mem_limit: 256m
|
||||
environment:
|
||||
REDIS_URL: &redis_url redis://redis:6379/0
|
||||
DATABASE_URL: &database_url postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Задай POSTGRES_PASSWORD в .env}@postgres:5432/${POSTGRES_DB:-messenger}
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
|
||||
api:
|
||||
<<: *app
|
||||
cpus: ${API_CPUS:-0.5}
|
||||
mem_limit: ${API_MEMORY:-256m}
|
||||
stop_grace_period: 15s
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp:rw,noexec,nosuid,size=16m
|
||||
cap_drop: [ALL]
|
||||
security_opt: ["no-new-privileges:true"]
|
||||
environment:
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: 8080
|
||||
DATABASE_URL: *database_url
|
||||
REDIS_URL: *redis_url
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
LOG_LEVEL: ${LOG_LEVEL:-INFO}
|
||||
APP_WORKERS: 1
|
||||
DATABASE_POOL_SIZE: ${DATABASE_POOL_SIZE:-10}
|
||||
DATABASE_POOL_TIMEOUT_SECONDS: 2
|
||||
DATABASE_CONNECT_TIMEOUT_SECONDS: 1
|
||||
DATABASE_COMMAND_TIMEOUT_SECONDS: 3
|
||||
DATABASE_STATEMENT_TIMEOUT_MS: 2500
|
||||
SHUTDOWN_TIMEOUT_SECONDS: 10
|
||||
expose: ["8080"]
|
||||
depends_on:
|
||||
migration:
|
||||
condition: service_completed_successfully
|
||||
redis:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
start_period: 10s
|
||||
|
||||
lb:
|
||||
image: haproxy:3.0.12-alpine
|
||||
logging: *logging
|
||||
cpus: 0.5
|
||||
mem_limit: 128m
|
||||
read_only: true
|
||||
tmpfs: ["/tmp:rw,noexec,nosuid,size=4m"]
|
||||
security_opt: ["no-new-privileges:true"]
|
||||
ports:
|
||||
- "127.0.0.1:${APP_PORT:-8080}:8080"
|
||||
volumes:
|
||||
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
stop_signal: SIGUSR1
|
||||
stop_grace_period: 15s
|
||||
|
||||
volumes:
|
||||
redis_data:
|
||||
postgres_data:
|
||||
Reference in New Issue
Block a user