forked from mtusi2026/mtusi2026lab4
108 lines
3.3 KiB
YAML
108 lines
3.3 KiB
YAML
name: mtusi-lab4
|
|
x-app: &app
|
|
build: .
|
|
image: mtusi-messenger:lab4
|
|
mem_limit: 768m
|
|
cpus: 1.0
|
|
environment: &env
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
S3_ENDPOINT: http://s3:9000
|
|
S3_BUCKET: messenger-attachments
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
secrets: [database_url, cache_url, s3_access_key_id, s3_secret_access_key]
|
|
stop_grace_period: 10s
|
|
services:
|
|
postgres:
|
|
image: postgres:16.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]
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'pg_isready -U messenger -d messenger']
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
valkey:
|
|
image: valkey/valkey:8.0.2-alpine
|
|
command: [valkey-server, --appendonly, 'yes', --maxmemory, 64mb, --maxmemory-policy, allkeys-lru]
|
|
volumes: [valkey-data:/data]
|
|
s3:
|
|
build:
|
|
context: ./infra/s3
|
|
target: server
|
|
image: mtusi-minio:RELEASE.2025-04-22T22-12-26Z
|
|
command: [server, /data, --console-address, '127.0.0.1:9001']
|
|
environment:
|
|
MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user
|
|
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password
|
|
secrets: [s3_root_user, s3_root_password]
|
|
volumes: [s3-data:/data]
|
|
healthcheck:
|
|
test: [CMD, curl, -f, http://localhost:9000/minio/health/live]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 30
|
|
s3-init:
|
|
build:
|
|
context: ./infra/s3
|
|
target: client
|
|
image: mtusi-mc:RELEASE.2025-04-16T18-13-26Z
|
|
entrypoint: [/bin/sh, /config/init.sh]
|
|
volumes: ['./infra/s3:/config:ro']
|
|
secrets: [s3_root_user, s3_root_password, s3_access_key_id, s3_secret_access_key]
|
|
depends_on:
|
|
s3: {condition: service_healthy}
|
|
migrate:
|
|
<<: *app
|
|
command: [python, app/migrate.py]
|
|
healthcheck: {disable: true}
|
|
depends_on:
|
|
postgres: {condition: service_healthy}
|
|
api1:
|
|
<<: *app
|
|
environment:
|
|
<<: *env
|
|
INSTANCE_ID: api1
|
|
depends_on: &deps
|
|
migrate: {condition: service_completed_successfully}
|
|
s3-init: {condition: service_completed_successfully}
|
|
valkey: {condition: service_started}
|
|
api2:
|
|
<<: *app
|
|
environment:
|
|
<<: *env
|
|
INSTANCE_ID: api2
|
|
depends_on: *deps
|
|
cleaner:
|
|
<<: *app
|
|
command: [python, app/cleanup.py]
|
|
healthcheck: {disable: true}
|
|
depends_on: *deps
|
|
lb:
|
|
image: haproxy:3.0.8-alpine
|
|
ports: ['127.0.0.1:${HOST_PORT:-8084}:8080']
|
|
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
|
depends_on:
|
|
api1: {condition: service_healthy}
|
|
api2: {condition: service_healthy}
|
|
volumes:
|
|
postgres-data:
|
|
valkey-data:
|
|
s3-data:
|
|
secrets:
|
|
postgres_password: {file: ./secrets/postgres_password}
|
|
database_url: {file: ./secrets/database_url}
|
|
cache_url: {file: ./secrets/cache_url}
|
|
s3_root_user: {file: ./secrets/s3_root_user}
|
|
s3_root_password: {file: ./secrets/s3_root_password}
|
|
s3_access_key_id: {file: ./secrets/s3_access_key_id}
|
|
s3_secret_access_key: {file: ./secrets/s3_secret_access_key}
|