forked from mtusi2026/mtusi2026lab4
125 lines
4.1 KiB
YAML
125 lines
4.1 KiB
YAML
|
|
services:
|
|
postgres:
|
|
image: postgres:16.6-alpine
|
|
restart: unless-stopped
|
|
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: 3s
|
|
timeout: 3s
|
|
retries: 20
|
|
|
|
valkey:
|
|
image: valkey/valkey:8.0.1-alpine
|
|
restart: unless-stopped
|
|
command: ["valkey-server","--appendonly","yes","--appendfsync","everysec"]
|
|
volumes: [valkey_data:/data]
|
|
healthcheck:
|
|
test: ["CMD","valkey-cli","ping"]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 20
|
|
|
|
rustfs:
|
|
image: rustfs/rustfs:1.0.4
|
|
restart: unless-stopped
|
|
command: ["/data"]
|
|
environment:
|
|
RUSTFS_ACCESS_KEY_FILE: /run/secrets/s3_access_key_id
|
|
RUSTFS_SECRET_KEY_FILE: /run/secrets/s3_secret_access_key
|
|
secrets: [s3_access_key_id,s3_secret_access_key]
|
|
volumes: [rustfs_data:/data]
|
|
|
|
rustfs-init:
|
|
image: rustfs/rc:v0.1.30
|
|
restart: "no"
|
|
depends_on:
|
|
rustfs:
|
|
condition: service_started
|
|
secrets: [s3_access_key_id,s3_secret_access_key]
|
|
entrypoint: ["/bin/sh","-c"]
|
|
command:
|
|
- |
|
|
rc alias set local http://rustfs:9000 "$$(tr -d '\r\n' < /run/secrets/s3_access_key_id)" "$$(tr -d '\r\n' < /run/secrets/s3_secret_access_key)"
|
|
until rc bucket list local/ >/dev/null 2>&1; do sleep 2; done
|
|
rc bucket create local/messenger-attachments || true
|
|
rc bucket anonymous set private local/messenger-attachments
|
|
rc bucket anonymous get local/messenger-attachments
|
|
|
|
migrate:
|
|
build: {context: ., dockerfile: Dockerfile}
|
|
command: ["python","server.py","migrate"]
|
|
restart: "no"
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
REDIS_URL_FILE: /run/secrets/redis_url
|
|
S3_ENDPOINT: http://rustfs: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,redis_url,s3_access_key_id,s3_secret_access_key]
|
|
depends_on:
|
|
postgres: {condition: service_healthy}
|
|
valkey: {condition: service_healthy}
|
|
rustfs-init: {condition: service_completed_successfully}
|
|
|
|
api:
|
|
build: {context: ., dockerfile: Dockerfile}
|
|
restart: unless-stopped
|
|
environment:
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
SESSION_TTL_SECONDS: 3600
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
REDIS_URL_FILE: /run/secrets/redis_url
|
|
S3_ENDPOINT: http://rustfs: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
|
|
MAX_UPLOAD_BYTES: 10485760
|
|
MAX_IMAGE_PIXELS: 40000000
|
|
secrets: [database_url,redis_url,s3_access_key_id,s3_secret_access_key]
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
postgres: {condition: service_healthy}
|
|
valkey: {condition: service_healthy}
|
|
rustfs-init: {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: 2s
|
|
timeout: 2s
|
|
retries: 5
|
|
start_period: 8s
|
|
stop_grace_period: 10s
|
|
|
|
haproxy:
|
|
image: haproxy:3.1.2-alpine
|
|
restart: unless-stopped
|
|
ports: ["127.0.0.1:8080:8080"]
|
|
volumes: ["./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro"]
|
|
depends_on:
|
|
api: {condition: service_healthy}
|
|
healthcheck:
|
|
test: ["CMD","haproxy","-c","-f","/usr/local/etc/haproxy/haproxy.cfg"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 3
|
|
|
|
secrets:
|
|
postgres_password: {file: ./secrets/postgres_password}
|
|
database_url: {file: ./secrets/database_url}
|
|
redis_url: {file: ./secrets/redis_url}
|
|
s3_access_key_id: {file: ./secrets/s3_access_key_id}
|
|
s3_secret_access_key: {file: ./secrets/s3_secret_access_key}
|
|
|
|
volumes:
|
|
postgres_data:
|
|
valkey_data:
|
|
rustfs_data:
|