forked from mtusi2026/mtusi2026lab4
171 lines
4.6 KiB
YAML
171 lines
4.6 KiB
YAML
name: mtusi-lab4
|
|
|
|
x-app: &app
|
|
image: mtusi-messenger:lab4
|
|
build: {context: ., target: runtime}
|
|
environment: &environment
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: "8080"
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
APP_VERSION: ${APP_VERSION:-lab4-v1}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
SESSION_STORE: redis
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
CURSOR_KEY_FILE: /run/secrets/cursor_key
|
|
secrets: [database_url, cache_url, cursor_key, s3_secret_key]
|
|
networks: [data]
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
stop_grace_period: 8s
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:17.6-bookworm
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets: [postgres_password]
|
|
volumes: [postgres_data:/var/lib/postgresql/data]
|
|
networks: [data]
|
|
healthcheck:
|
|
test: [CMD-SHELL, "pg_isready -U messenger -d messenger"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
stop_grace_period: 10s
|
|
|
|
redis:
|
|
image: redis:7.4.5-bookworm
|
|
command: [sh, -ec, 'exec redis-server /usr/local/etc/redis/redis.conf --requirepass "$$(cat /run/secrets/redis_password)"']
|
|
secrets: [redis_password]
|
|
volumes:
|
|
- redis_data:/data
|
|
- ./infra/redis.conf:/usr/local/etc/redis/redis.conf:ro
|
|
networks: [data]
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'REDISCLI_AUTH="$$(cat /run/secrets/redis_password)" redis-cli ping | grep -q PONG']
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
cpus: 0.5
|
|
mem_limit: 192m
|
|
stop_grace_period: 10s
|
|
|
|
migrate:
|
|
<<: *app
|
|
command: [python, -m, app.migrate]
|
|
depends_on:
|
|
postgres: {condition: service_healthy}
|
|
restart: "no"
|
|
|
|
api:
|
|
<<: *app
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
redis: {condition: service_healthy}
|
|
bucket-init: {condition: service_completed_successfully}
|
|
networks: [edge, data]
|
|
|
|
minio:
|
|
image: mtusi-minio:2025-09-07
|
|
build: ./infra/s3
|
|
command: [server, /data, --console-address, "127.0.0.1:9001"]
|
|
environment:
|
|
MINIO_ROOT_USER: lab-admin
|
|
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password
|
|
secrets: [s3_root_password]
|
|
volumes: [s3_data:/data]
|
|
networks: [data]
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
healthcheck:
|
|
test: [CMD-SHELL, "mc alias set health http://127.0.0.1:9000 lab-admin $$(cat /run/secrets/s3_root_password) >/dev/null && mc ready health"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
|
|
bucket-init:
|
|
image: mtusi-minio:2025-09-07
|
|
build: ./infra/s3
|
|
entrypoint: [/bin/sh, /bootstrap/bootstrap.sh]
|
|
secrets: [s3_root_password, s3_secret_key]
|
|
volumes: [./infra/s3:/bootstrap:ro]
|
|
networks: [data]
|
|
depends_on:
|
|
minio: {condition: service_healthy}
|
|
mem_limit: 128m
|
|
restart: "no"
|
|
|
|
cleanup:
|
|
<<: *app
|
|
command: [python, -m, app.attachments]
|
|
healthcheck:
|
|
test: [CMD, python, -c, "import os; os.kill(1, 0)"]
|
|
interval: 5s
|
|
timeout: 2s
|
|
retries: 3
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
redis: {condition: service_healthy}
|
|
bucket-init: {condition: service_completed_successfully}
|
|
restart: unless-stopped
|
|
|
|
lb:
|
|
image: haproxy:3.0.12-alpine
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
ports:
|
|
- "127.0.0.1:${API_PORT:-8084}:8080"
|
|
networks: [edge]
|
|
depends_on:
|
|
api: {condition: service_healthy}
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
stop_grace_period: 8s
|
|
healthcheck:
|
|
test: [CMD, wget, -q, -O, /dev/null, "http://127.0.0.1:8080/health/ready"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
|
|
checks:
|
|
profiles: [tools]
|
|
image: mtusi-messenger:lab4-checks
|
|
build: {context: ., target: checks}
|
|
environment:
|
|
<<: *environment
|
|
BASE_URL: http://lb:8080
|
|
COMPOSE_PROJECT_NAME: ${COMPOSE_PROJECT_NAME:-mtusi-lab4}
|
|
secrets: [database_url, cache_url, cursor_key, s3_secret_key]
|
|
volumes:
|
|
- .:/checks
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
networks: [edge, data]
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
|
|
networks:
|
|
edge:
|
|
data:
|
|
internal: true
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
s3_data:
|
|
|
|
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}
|
|
cursor_key: {file: ./secrets/cursor_key}
|
|
s3_root_password: {file: ./secrets/s3_root_password}
|
|
s3_secret_key: {file: ./secrets/s3_secret_key}
|