forked from mtusi2026/mtusi2026lab4
219 lines
4.8 KiB
YAML
219 lines
4.8 KiB
YAML
name: highload-lab4
|
|
|
|
services:
|
|
api:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
scale: 2
|
|
cpus: "2.0"
|
|
mem_limit: 512m
|
|
expose:
|
|
- "8080"
|
|
env_file:
|
|
- .env
|
|
secrets:
|
|
- database_url
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
s3-init:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
stop_grace_period: 20s
|
|
read_only: true
|
|
tmpfs:
|
|
- /tmp:size=32m,mode=1777
|
|
cap_drop:
|
|
- ALL
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
|
|
attachment-cleanup:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
target: cleanup
|
|
command: ["/app/attachment-cleanup", "-dry-run=${LAB4_CLEANUP_DRY_RUN:-false}"]
|
|
cpus: "0.5"
|
|
mem_limit: 128m
|
|
env_file:
|
|
- .env
|
|
secrets:
|
|
- database_url
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
s3-init:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
stop_grace_period: 20s
|
|
read_only: true
|
|
cap_drop:
|
|
- ALL
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
|
|
lb:
|
|
image: haproxy:3.2.24-alpine
|
|
cpus: "1.0"
|
|
mem_limit: 256m
|
|
ports:
|
|
- "127.0.0.1:${LAB4_HTTP_PORT:-8081}:8080"
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
read_only: true
|
|
cap_drop:
|
|
- ALL
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
|
|
migrate:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile.migrate
|
|
cpus: "1.0"
|
|
mem_limit: 256m
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets:
|
|
- database_url
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
stop_grace_period: 20s
|
|
read_only: true
|
|
cap_drop:
|
|
- ALL
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
|
|
postgres:
|
|
image: postgres:18
|
|
cpus: "2.0"
|
|
mem_limit: 512m
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets:
|
|
- postgres_password
|
|
ports:
|
|
- "127.0.0.1:${LAB4_POSTGRES_PORT:-5433}:5432"
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U messenger -d messenger"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
stop_grace_period: 60s
|
|
|
|
redis:
|
|
image: redis:7.4-alpine
|
|
cpus: "0.5"
|
|
mem_limit: 128m
|
|
restart: unless-stopped
|
|
command:
|
|
- redis-server
|
|
- --appendonly
|
|
- "yes"
|
|
- --appendfsync
|
|
- everysec
|
|
volumes:
|
|
- redis_data:/data
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 5
|
|
|
|
s3:
|
|
image: rustfs/rustfs:1.0.4
|
|
cpus: "1.0"
|
|
mem_limit: 512m
|
|
environment:
|
|
RUSTFS_VOLUMES: /data
|
|
RUSTFS_ACCESS_KEY_FILE: /run/secrets/rustfs_root_access_key
|
|
RUSTFS_SECRET_KEY_FILE: /run/secrets/rustfs_root_secret_key
|
|
RUSTFS_CONSOLE_ENABLE: "false"
|
|
secrets:
|
|
- rustfs_root_access_key
|
|
- rustfs_root_secret_key
|
|
volumes:
|
|
- rustfs_data:/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9000/health/ready >/dev/null"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 12
|
|
start_period: 30s
|
|
restart: unless-stopped
|
|
cap_drop:
|
|
- ALL
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
|
|
s3-init:
|
|
image: rustfs/rc:v0.1.30
|
|
cpus: "0.5"
|
|
mem_limit: 128m
|
|
entrypoint: ["/bin/sh", "/bootstrap.sh"]
|
|
environment:
|
|
HOME: /tmp
|
|
S3_BUCKET: messenger-attachments
|
|
S3_REGION: us-east-1
|
|
secrets:
|
|
- rustfs_root_access_key
|
|
- rustfs_root_secret_key
|
|
- s3_access_key_id
|
|
- s3_secret_access_key
|
|
volumes:
|
|
- ./infra/s3/bootstrap.sh:/bootstrap.sh:ro
|
|
depends_on:
|
|
s3:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
read_only: true
|
|
tmpfs:
|
|
- /tmp:uid=100,gid=101,mode=0700
|
|
cap_drop:
|
|
- ALL
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
|
|
secrets:
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
rustfs_root_access_key:
|
|
file: ./secrets/rustfs_root_access_key
|
|
rustfs_root_secret_key:
|
|
file: ./secrets/rustfs_root_secret_key
|
|
s3_access_key_id:
|
|
file: ./secrets/s3_access_key_id
|
|
s3_secret_access_key:
|
|
file: ./secrets/s3_secret_access_key
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
rustfs_data:
|