forked from mtusi2026/mtusi2026lab4
102 lines
3.4 KiB
YAML
102 lines
3.4 KiB
YAML
name: mtusi_lab4_solution
|
|
x-api: &api
|
|
build: .
|
|
image: mtusi-lab4-api:local
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
|
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
S3_ENDPOINT: http://rustfs:9000
|
|
S3_REGION: us-east-1
|
|
S3_BUCKET: messenger-attachments
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
MAX_UPLOAD_BYTES: 10485760
|
|
MAX_IMAGE_PIXELS: 40000000
|
|
secrets: [database_url, cache_url, s3_access_key_id, s3_secret_access_key]
|
|
restart: unless-stopped
|
|
mem_limit: 512m
|
|
cpus: 0.75
|
|
services:
|
|
postgres:
|
|
image: postgres:16.10-alpine
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
|
secrets: [db_password]
|
|
volumes: [pgdata:/var/lib/postgresql/data]
|
|
healthcheck:
|
|
test: [CMD-SHELL, pg_isready -U messenger -d messenger]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
redis:
|
|
image: redis:7.4.6-alpine
|
|
command: [redis-server, --maxmemory, 64mb, --maxmemory-policy, allkeys-lru]
|
|
healthcheck:
|
|
test: [CMD, redis-cli, ping]
|
|
interval: 2s
|
|
timeout: 1s
|
|
retries: 20
|
|
rustfs:
|
|
image: rustfs/rustfs:1.0.3-glibc
|
|
command: [/data]
|
|
environment:
|
|
RUSTFS_ACCESS_KEY_FILE: /run/secrets/rustfs_root_user
|
|
RUSTFS_SECRET_KEY_FILE: /run/secrets/rustfs_root_password
|
|
RUSTFS_CONSOLE_ENABLE: 'false'
|
|
RUSTFS_ADDRESS: ':9000'
|
|
secrets: [rustfs_root_user, rustfs_root_password]
|
|
volumes: [s3data:/data]
|
|
expose: ['9000']
|
|
healthcheck:
|
|
test: [CMD, curl, -f, http://127.0.0.1:9000/health]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
bucket-bootstrap:
|
|
image: rustfs/rc:v0.1.37
|
|
depends_on:
|
|
rustfs: {condition: service_healthy}
|
|
entrypoint: [/bin/sh, /bootstrap-rustfs.sh]
|
|
volumes: ['./infra/rustfs-policy.json:/policy.json:ro', './infra/bootstrap-rustfs.sh:/bootstrap-rustfs.sh:ro']
|
|
secrets: [rustfs_root_user, rustfs_root_password, s3_access_key_id, s3_secret_access_key]
|
|
restart: 'no'
|
|
migrate:
|
|
<<: *api
|
|
command: [python, -m, app.migrate]
|
|
restart: 'no'
|
|
depends_on:
|
|
postgres: {condition: service_healthy}
|
|
api:
|
|
<<: *api
|
|
command: [gunicorn, --bind, 0.0.0.0:8080, --workers, '1', --threads, '2', --timeout, '35', --graceful-timeout, '5', app.main:app]
|
|
scale: ${API_REPLICAS:-2}
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
redis: {condition: service_healthy}
|
|
bucket-bootstrap: {condition: service_completed_successfully}
|
|
healthcheck:
|
|
test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready', timeout=3)"]
|
|
interval: 2s
|
|
timeout: 4s
|
|
retries: 3
|
|
lb:
|
|
image: haproxy:3.0.11-alpine
|
|
ports: ['127.0.0.1:8080:8080']
|
|
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
|
depends_on:
|
|
api: {condition: service_healthy}
|
|
volumes:
|
|
pgdata:
|
|
s3data:
|
|
secrets:
|
|
db_password: {file: ./secrets/db_password}
|
|
database_url: {file: ./secrets/database_url}
|
|
cache_url: {file: ./secrets/cache_url}
|
|
rustfs_root_user: {file: ./secrets/rustfs_root_user}
|
|
rustfs_root_password: {file: ./secrets/rustfs_root_password}
|
|
s3_access_key_id: {file: ./secrets/s3_access_key_id}
|
|
s3_secret_access_key: {file: ./secrets/s3_secret_access_key}
|