Files
mtusi2026lab4/compose.yaml
T

293 lines
7.6 KiB
YAML

name: mtusi-messenger-lab4
services:
db:
image: postgres:16.4-alpine
restart: unless-stopped
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets:
- postgres_password
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- backend
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 3s
timeout: 3s
retries: 20
start_period: 5s
deploy:
resources:
limits:
cpus: "1.00"
memory: 1G
redis:
image: redis:7.4.1-alpine
restart: unless-stopped
command:
- sh
- -ec
- exec redis-server --dir /data --appendonly yes --appendfsync everysec --save 60 1 --requirepass "$$(cat /run/secrets/redis_password)"
secrets:
- redis_password
volumes:
- redis_data:/data
networks:
- backend
healthcheck:
test:
- CMD-SHELL
- 'REDISCLI_AUTH="$$(cat /run/secrets/redis_password)" redis-cli ping | grep -q PONG'
interval: 3s
timeout: 3s
retries: 20
start_period: 5s
deploy:
resources:
limits:
cpus: "0.25"
memory: 256M
s3-init:
image: alpine:3.24.1
user: "0:0"
command: ["sh", "-ec", "chown -R 10001:10001 /data && chmod 0750 /data"]
volumes:
- s3_data:/data
restart: "no"
s3:
image: rustfs/rustfs:1.0.5
restart: unless-stopped
environment:
RUSTFS_VOLUMES: /data
RUSTFS_ADDRESS: 0.0.0.0:9000
RUSTFS_CONSOLE_ADDRESS: 0.0.0.0:9001
RUSTFS_CONSOLE_ENABLE: "false"
RUSTFS_OBS_LOGGER_LEVEL: warn
RUSTFS_CHECK_UPDATE: "false"
RUSTFS_ACCESS_KEY_FILE: /run/secrets/s3_root_access_key_id
RUSTFS_SECRET_KEY_FILE: /run/secrets/s3_root_secret_access_key
secrets:
- s3_root_access_key_id
- s3_root_secret_access_key
volumes:
- s3_data:/data
networks:
- backend
depends_on:
s3-init:
condition: service_completed_successfully
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9000/health/ready >/dev/null"]
interval: 3s
timeout: 2s
retries: 20
start_period: 10s
deploy:
resources:
limits:
cpus: "1.00"
memory: 1G
migrate:
image: mtusi-messenger-lab4-api:local
build:
context: .
dockerfile: Dockerfile
args:
BUILD_REVISION: ${BUILD_REVISION:-local}
command: ["python", "-m", "src.app.migrate"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
secrets:
- database_url
networks:
- backend
depends_on:
db:
condition: service_healthy
restart: "no"
deploy:
resources:
limits:
cpus: "0.25"
memory: 256M
s3-bootstrap:
image: mtusi-messenger-lab4-api:local
build:
context: .
dockerfile: Dockerfile
args:
BUILD_REVISION: ${BUILD_REVISION:-local}
command: ["python", "-m", "src.app.s3_bootstrap"]
environment:
S3_ENDPOINT: http://s3:9000
S3_REGION: us-east-1
S3_BUCKET: messenger-attachments
S3_ROOT_ACCESS_KEY_FILE: /run/secrets/s3_root_access_key_id
S3_ROOT_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_root_secret_access_key
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
secrets:
- s3_root_access_key_id
- s3_root_secret_access_key
- s3_access_key_id
- s3_secret_access_key
networks:
- backend
depends_on:
s3:
condition: service_healthy
restart: "no"
deploy:
resources:
limits:
cpus: "0.25"
memory: 256M
api:
image: mtusi-messenger-lab4-api:local
build:
context: .
dockerfile: Dockerfile
args:
BUILD_REVISION: ${BUILD_REVISION:-local}
restart: unless-stopped
stop_grace_period: 8s
environment:
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_REGION: us-east-1
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
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
secrets:
- database_url
- cache_url
- s3_access_key_id
- s3_secret_access_key
networks:
- backend
- edge
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
s3:
condition: service_healthy
s3-bootstrap:
condition: service_completed_successfully
migrate:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=2)"]
interval: 3s
timeout: 2s
retries: 3
start_period: 10s
tmpfs:
- /tmp:size=64m,noexec,nosuid
deploy:
resources:
limits:
cpus: "0.50"
memory: 512M
lb:
image: nginx:1.28.0-alpine
restart: unless-stopped
ports:
- "127.0.0.1:${APP_PORT:-8080}:8080"
volumes:
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
networks:
- edge
depends_on:
api:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"]
interval: 3s
timeout: 2s
retries: 5
start_period: 5s
deploy:
resources:
limits:
cpus: "0.25"
memory: 128M
s3-maintenance:
image: mtusi-messenger-lab4-api:local
build:
context: .
dockerfile: Dockerfile
args:
BUILD_REVISION: ${BUILD_REVISION:-local}
profiles: ["maintenance"]
command: ["python", "-m", "src.app.reconcile_s3_orphans"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
S3_ENDPOINT: http://s3:9000
S3_REGION: us-east-1
S3_BUCKET: messenger-attachments
S3_ROOT_ACCESS_KEY_FILE: /run/secrets/s3_root_access_key_id
S3_ROOT_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_root_secret_access_key
ORPHAN_GRACE_SECONDS: ${ORPHAN_GRACE_SECONDS:-86400}
secrets:
- database_url
- s3_root_access_key_id
- s3_root_secret_access_key
networks:
- backend
depends_on:
db:
condition: service_healthy
s3:
condition: service_healthy
migrate:
condition: service_completed_successfully
restart: "no"
secrets:
postgres_password:
file: ./secrets/postgres_password
redis_password:
file: ./secrets/redis_password
s3_root_access_key_id:
file: ./secrets/s3_root_access_key_id
s3_root_secret_access_key:
file: ./secrets/s3_root_secret_access_key
s3_access_key_id:
file: ./secrets/s3_access_key_id
s3_secret_access_key:
file: ./secrets/s3_secret_access_key
database_url:
file: ./secrets/database_url
cache_url:
file: ./secrets/cache_url
volumes:
postgres_data:
redis_data:
s3_data:
networks:
backend:
internal: true
edge: