forked from mtusi2026/mtusi2026lab5
level 3
This commit is contained in:
+118
-5
@@ -1,8 +1,8 @@
|
||||
# Client -> lb (HAProxy) -> api x API_REPLICAS -> postgres (metadata) + minio (private bucket).
|
||||
# HTTP upload still receives the whole body. POST returns 202 only after the original is stored;
|
||||
# status stays queued, and a later GET of the metadata is how the client learns readiness.
|
||||
# Only the LB publishes a port. Networks: edge = lb<->api, data = api/migrate/minio (no LB, no internet).
|
||||
# DB and MinIO passwords come from .env (not committed) as Compose secret files, never as container env vars.
|
||||
# Client -> lb (HAProxy) -> api x API_REPLICAS -> postgres + minio + rabbitmq.
|
||||
# HTTP upload still receives the whole body. POST returns 202 only after the original is in
|
||||
# staging and RabbitMQ confirms the job. The worker copies the original and writes the thumbnail.
|
||||
# Only the LB publishes a port. Networks: edge = lb<->api, data = api/worker/stores (no LB, no internet).
|
||||
# Passwords come from .env (not committed) as Compose secret files, never as container env vars.
|
||||
name: messenger-lab5
|
||||
|
||||
x-db-client: &db-client
|
||||
@@ -138,6 +138,36 @@ services:
|
||||
memory: 256M
|
||||
restart: "no"
|
||||
|
||||
# Stable hostname: the data directory is rabbit@rabbitmq, so a new container keeps old jobs.
|
||||
rabbitmq:
|
||||
image: rabbitmq:4.1-alpine@sha256:cd4009416f83d7e5895020cd71b0963f3b8a4dfc3de74bbb6fb3bfe5f81f01e0
|
||||
hostname: rabbitmq
|
||||
entrypoint: ["/bin/sh", "/bootstrap/rabbitmq-entrypoint.sh"]
|
||||
secrets:
|
||||
- rabbitmq_user
|
||||
- rabbitmq_password
|
||||
volumes:
|
||||
- ./infra/rabbitmq/entrypoint.sh:/bootstrap/rabbitmq-entrypoint.sh:ro
|
||||
- rabbitmqdata:/var/lib/rabbitmq
|
||||
networks:
|
||||
- data
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
|
||||
interval: 5s
|
||||
timeout: 10s
|
||||
retries: 12
|
||||
start_period: 20s
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 512M
|
||||
reservations:
|
||||
cpus: "0.25"
|
||||
memory: 256M
|
||||
stop_grace_period: 30s
|
||||
restart: unless-stopped
|
||||
|
||||
api:
|
||||
image: messenger-lab5-app:${APP_VERSION:-dev}
|
||||
build: *app-build
|
||||
@@ -165,6 +195,10 @@ services:
|
||||
S3_BUCKET: ${S3_BUCKET:?set in .env}
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1}
|
||||
secrets:
|
||||
- source: postgres_password
|
||||
uid: "10001"
|
||||
@@ -178,6 +212,10 @@ services:
|
||||
uid: "10001"
|
||||
gid: "10001"
|
||||
mode: 0400
|
||||
- source: broker_url
|
||||
uid: "10001"
|
||||
gid: "10001"
|
||||
mode: 0400
|
||||
networks:
|
||||
- edge
|
||||
- data
|
||||
@@ -190,6 +228,8 @@ services:
|
||||
condition: service_completed_successfully
|
||||
minio-init:
|
||||
condition: service_completed_successfully
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
# Docker health gates startup order and rolling update; the LB runs its own checks (infra/haproxy/haproxy.cfg).
|
||||
healthcheck:
|
||||
test:
|
||||
@@ -207,6 +247,72 @@ services:
|
||||
stop_grace_period: 10s
|
||||
restart: unless-stopped
|
||||
|
||||
worker:
|
||||
image: messenger-lab5-app:${APP_VERSION:-dev}
|
||||
command: ["python", "-m", "app.worker"]
|
||||
environment:
|
||||
<<: *db-client
|
||||
S3_ENDPOINT: ${S3_ENDPOINT:?set in .env}
|
||||
S3_REGION: ${S3_REGION:-us-east-1}
|
||||
S3_BUCKET: ${S3_BUCKET:?set in .env}
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
BROKER_URL_FILE: /run/secrets/broker_url
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60}
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1}
|
||||
DB_POOL_MIN: "1"
|
||||
DB_POOL_MAX: "4"
|
||||
secrets:
|
||||
- source: postgres_password
|
||||
uid: "10001"
|
||||
gid: "10001"
|
||||
mode: 0400
|
||||
- source: s3_access_key_id
|
||||
uid: "10001"
|
||||
gid: "10001"
|
||||
mode: 0400
|
||||
- source: s3_secret_access_key
|
||||
uid: "10001"
|
||||
gid: "10001"
|
||||
mode: 0400
|
||||
- source: broker_url
|
||||
uid: "10001"
|
||||
gid: "10001"
|
||||
mode: 0400
|
||||
networks:
|
||||
- data
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
minio-init:
|
||||
condition: service_completed_successfully
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD
|
||||
- python
|
||||
- -c
|
||||
- import os,sys,time; p='/tmp/worker-alive'; sys.exit(0 if os.path.exists(p) and time.time()-os.path.getmtime(p)<20 else 1)
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 6
|
||||
start_period: 25s
|
||||
stop_signal: SIGTERM
|
||||
stop_grace_period: 30s
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 512M
|
||||
reservations:
|
||||
cpus: "0.25"
|
||||
memory: 256M
|
||||
restart: unless-stopped
|
||||
|
||||
lb:
|
||||
image: haproxy:3.2.26-alpine@sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0
|
||||
# Loopback only. Both families: on Windows "localhost" tries ::1 first and waits ~2 s if nothing listens.
|
||||
@@ -251,7 +357,14 @@ secrets:
|
||||
environment: S3_ACCESS_KEY_ID
|
||||
s3_secret_access_key:
|
||||
environment: S3_SECRET_ACCESS_KEY
|
||||
rabbitmq_user:
|
||||
environment: RABBITMQ_USER
|
||||
rabbitmq_password:
|
||||
environment: RABBITMQ_PASSWORD
|
||||
broker_url:
|
||||
environment: BROKER_URL
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
miniodata:
|
||||
rabbitmqdata:
|
||||
|
||||
Reference in New Issue
Block a user