Files
mtusi2026lab4/compose.yaml
T

145 lines
4.9 KiB
YAML

name: mtusi-vasilev-lab4
x-application: &application
image: ${API_IMAGE:-mtusi-vasilev:lab4}
build:
context: .
args:
VCS_REF: ${VCS_REF:-uncommitted}
environment:
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
S3_ENDPOINT: http://s3:8333
S3_BUCKET: messenger
S3_ACCESS_KEY_FILE: /run/secrets/s3_access_key
S3_SECRET_KEY_FILE: /run/secrets/s3_secret_key
POOL_MAX_SIZE: ${POOL_MAX_SIZE:-8}
secrets: [database_url, cache_url, s3_access_key, s3_secret_key]
cpus: ${API_CPUS:-0.5}
mem_limit: ${API_MEMORY:-512m}
pids_limit: 96
read_only: true
tmpfs: ["/tmp:size=16m,noexec,nosuid"]
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
stop_grace_period: 8s
services:
postgres:
image: postgres:17.10-alpine
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: 2s
retries: 15
cpus: 1
mem_limit: 768m
command: [postgres, -c, fsync=on, -c, synchronous_commit=on, -c, full_page_writes=on]
cache:
image: valkey/valkey:8.1.3-alpine
command: [valkey-server, --save, "", --appendonly, "no", --maxmemory, 64mb, --maxmemory-policy, allkeys-lru]
healthcheck:
test: [CMD, valkey-cli, ping]
interval: 2s
timeout: 2s
retries: 15
cpus: 0.5
mem_limit: 128m
migrate:
<<: *application
command: [python, -m, messenger.migrate]
healthcheck:
disable: true
depends_on:
postgres: {condition: service_healthy}
api:
<<: *application
deploy:
replicas: ${API_REPLICAS:-2}
depends_on:
migrate: {condition: service_completed_successfully}
cache: {condition: service_healthy}
s3-bootstrap: {condition: service_completed_successfully}
storage:
image: chrislusf/seaweedfs:4.15@sha256:1593bd2a98964f5d4df83fa7db2b3d4ee7b20190813cc5bf8c3200e0e70d346e
command: [server, -dir=/data, -ip=storage, -ip.bind=0.0.0.0, -filer, -volume.max=4, -volume.preStopSeconds=0, -master.volumeSizeLimitMB=64]
volumes: ["s3_data:/data", "./infra/filer.toml:/etc/seaweedfs/filer.toml:ro"]
networks: [storage_backend]
cpus: 1
mem_limit: 512m
healthcheck:
test: [CMD-SHELL, "wget -q -O /dev/null http://127.0.0.1:9333/dir/status"]
interval: 2s
timeout: 2s
retries: 20
s3:
image: chrislusf/seaweedfs:4.15@sha256:1593bd2a98964f5d4df83fa7db2b3d4ee7b20190813cc5bf8c3200e0e70d346e
command: [s3, -filer=storage:8888, -ip.bind=0.0.0.0, -config=/run/secrets/s3_config, -port=8333]
secrets: [s3_config]
networks: [default, storage_backend]
depends_on:
storage: {condition: service_healthy}
cpus: 0.5
mem_limit: 256m
s3-bootstrap:
<<: *application
command: [python, -m, messenger.storage_bootstrap]
environment:
S3_ENDPOINT: http://s3:8333
S3_ADMIN_ACCESS_KEY_FILE: /run/secrets/s3_admin_access_key
S3_ADMIN_SECRET_KEY_FILE: /run/secrets/s3_admin_secret_key
secrets: [s3_admin_access_key, s3_admin_secret_key]
healthcheck:
disable: true
depends_on:
s3: {condition: service_started}
research:
<<: *application
profiles: [tools]
command: [python, /research/run.py]
volumes: ["./research:/research:ro"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
S3_ENDPOINT: http://s3:8333
S3_ADMIN_ACCESS_KEY_FILE: /run/secrets/s3_admin_access_key
S3_ADMIN_SECRET_KEY_FILE: /run/secrets/s3_admin_secret_key
secrets: [database_url, cache_url, s3_admin_access_key, s3_admin_secret_key]
lb:
image: haproxy:3.2-alpine@sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0
ports: ["127.0.0.1:${PUBLIC_PORT:-8084}:8080"]
volumes: ["./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro"]
depends_on:
api: {condition: service_healthy}
cpus: 0.5
mem_limit: 128m
read_only: true
tmpfs: ["/tmp:size=8m"]
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
healthcheck:
test: [CMD-SHELL, "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"]
interval: 2s
timeout: 2s
retries: 10
volumes:
postgres_data:
s3_data:
networks:
storage_backend:
internal: true
secrets:
postgres_password: {file: ./secrets/postgres_password}
database_url: {file: ./secrets/database_url}
cache_url: {file: ./secrets/cache_url}
s3_access_key: {file: ./secrets/s3_access_key}
s3_secret_key: {file: ./secrets/s3_secret_key}
s3_admin_access_key: {file: ./secrets/s3_admin_access_key}
s3_admin_secret_key: {file: ./secrets/s3_admin_secret_key}
s3_config: {file: ./secrets/s3_config}