forked from mtusi2026/mtusi2026lab5
lab5 na4
This commit is contained in:
+284
@@ -0,0 +1,284 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.4-alpine
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
secrets:
|
||||
- postgres_password
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 5s
|
||||
networks: [data]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "1.0", memory: 512M }
|
||||
|
||||
redis:
|
||||
image: redis:7.4-alpine
|
||||
command: ["redis-server", "--appendonly", "yes"]
|
||||
volumes:
|
||||
- redis-data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 5s
|
||||
networks: [data]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
|
||||
migrate:
|
||||
image: migrate/migrate:v4.17.1
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- ./migrations:/migrations
|
||||
command:
|
||||
- "-path=/migrations"
|
||||
- "-database=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable"
|
||||
- "up"
|
||||
restart: "no"
|
||||
networks: [data]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
redis:
|
||||
condition: service_healthy
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
s3-proxy:
|
||||
condition: service_started
|
||||
environment:
|
||||
PORT: ${PORT}
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS}
|
||||
MAX_CONCURRENT_REQUESTS: ${MAX_CONCURRENT_REQUESTS}
|
||||
DB_MAX_CONNS: ${DB_MAX_CONNS}
|
||||
DB_MIN_CONNS: ${DB_MIN_CONNS}
|
||||
DB_CONN_TIMEOUT_SECONDS: ${DB_CONN_TIMEOUT_SECONDS}
|
||||
CACHE_URL: ${CACHE_URL}
|
||||
CHAT_CACHE_TTL_SECONDS: 30
|
||||
DRAIN_SECONDS: 4
|
||||
GOMEMLIMIT: 200MiB
|
||||
APP_VERSION: ${APP_VERSION:-dev}
|
||||
S3_ENDPOINT: http://s3-proxy:8333
|
||||
S3_BUCKET: attachments
|
||||
S3_REGION: us-east-1
|
||||
S3_ACCESS_KEY_FILE: /run/secrets/s3_api_access_key
|
||||
S3_SECRET_KEY_FILE: /run/secrets/s3_api_secret_key
|
||||
MAX_UPLOADS: 1
|
||||
IMAGE_MEMORY_MB: 384
|
||||
secrets:
|
||||
- database_url
|
||||
- s3_api_access_key
|
||||
- s3_api_secret_key
|
||||
stop_grace_period: 20s
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/health/ready"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
networks: [edge, data, s3access]
|
||||
deploy:
|
||||
replicas: 2
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 512M }
|
||||
|
||||
lb:
|
||||
image: haproxy:3.0-alpine
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
ports:
|
||||
- "127.0.0.1:8080:8080"
|
||||
networks: [edge]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
|
||||
seaweedfs:
|
||||
image: chrislusf/seaweedfs:4.50
|
||||
command: ["server", "-dir=/data", "-s3", "-s3.config=/run/secrets/s3_config"]
|
||||
secrets: [s3_config]
|
||||
volumes:
|
||||
- s3-data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:9333/cluster/status"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
start_period: 10s
|
||||
networks: [s3backend]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.5", memory: 512M }
|
||||
|
||||
s3-init:
|
||||
image: amazon/aws-cli:2.39.1
|
||||
depends_on:
|
||||
seaweedfs:
|
||||
condition: service_healthy
|
||||
s3-proxy: { condition: service_started }
|
||||
secrets: [s3_admin_access_key, s3_admin_secret_key]
|
||||
entrypoint: ["/bin/sh", "-c"]
|
||||
command:
|
||||
- |
|
||||
export AWS_ACCESS_KEY_ID="$$(cat /run/secrets/s3_admin_access_key)"
|
||||
export AWS_SECRET_ACCESS_KEY="$$(cat /run/secrets/s3_admin_secret_key)"
|
||||
export AWS_DEFAULT_REGION=us-east-1
|
||||
EP=http://s3-proxy:8333
|
||||
for i in $$(seq 1 60); do
|
||||
aws --endpoint-url $$EP s3api head-bucket --bucket attachments 2>/dev/null \
|
||||
|| aws --endpoint-url $$EP s3api create-bucket --bucket attachments 2>/dev/null \
|
||||
|| { sleep 2; continue; }
|
||||
if aws --endpoint-url $$EP s3api put-object --bucket attachments --key _health/init-probe --body /etc/hostname >/dev/null 2>&1; then
|
||||
aws --endpoint-url $$EP s3api delete-object --bucket attachments --key _health/init-probe >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
exit 1
|
||||
restart: "no"
|
||||
networks: [s3access]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 256M }
|
||||
|
||||
s3-proxy:
|
||||
image: haproxy:3.0-alpine
|
||||
volumes:
|
||||
- ./infra/haproxy-s3.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
depends_on:
|
||||
seaweedfs:
|
||||
condition: service_healthy
|
||||
networks: [s3backend, s3access]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 64M }
|
||||
reconciler:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
command: ["./reconcile", "-loop=10m", "-grace=1h", "-check-missing"]
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
S3_ENDPOINT: http://s3-proxy:8333
|
||||
S3_BUCKET: attachments
|
||||
S3_REGION: us-east-1
|
||||
S3_ACCESS_KEY_FILE: /run/secrets/s3_api_access_key
|
||||
S3_SECRET_KEY_FILE: /run/secrets/s3_api_secret_key
|
||||
secrets: [database_url, s3_api_access_key, s3_api_secret_key]
|
||||
stop_grace_period: 5s
|
||||
networks: [data, s3access]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: unless-stopped
|
||||
|
||||
broker:
|
||||
image: redis:7.4-alpine
|
||||
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always", "--maxmemory-policy", "noeviction"]
|
||||
volumes: [broker-data:/data]
|
||||
networks: [data]
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 10
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 128M }
|
||||
|
||||
worker: &pipeline
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
command: ["./worker", "-mode=worker"]
|
||||
depends_on:
|
||||
migrate: { condition: service_completed_successfully }
|
||||
s3-init: { condition: service_completed_successfully }
|
||||
broker: { condition: service_healthy }
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
BROKER_URL: redis://broker:6379/0
|
||||
S3_ENDPOINT: http://s3-proxy:8333
|
||||
S3_BUCKET: attachments
|
||||
S3_REGION: us-east-1
|
||||
S3_ACCESS_KEY_FILE: /run/secrets/s3_api_access_key
|
||||
S3_SECRET_KEY_FILE: /run/secrets/s3_api_secret_key
|
||||
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1}
|
||||
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
|
||||
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-30}
|
||||
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400}
|
||||
IMAGE_MEMORY_MB: 384
|
||||
GOMEMLIMIT: 128MiB
|
||||
secrets: [database_url, s3_api_access_key, s3_api_secret_key]
|
||||
networks: [data, s3access]
|
||||
stop_grace_period: 40s
|
||||
healthcheck: { disable: true }
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "1.0", memory: 1024M }
|
||||
|
||||
outbox:
|
||||
<<: *pipeline
|
||||
command: ["./worker", "-mode=relay"]
|
||||
deploy:
|
||||
resources:
|
||||
limits: { cpus: "0.25", memory: 192M }
|
||||
|
||||
networks:
|
||||
edge:
|
||||
data:
|
||||
s3backend:
|
||||
internal: true
|
||||
s3access:
|
||||
internal: true
|
||||
|
||||
secrets:
|
||||
database_url:
|
||||
file: ./secrets/database_url.txt
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password.txt
|
||||
s3_config: { file: ./secrets/s3_config.json }
|
||||
s3_api_access_key: { file: ./secrets/s3_api_access_key.txt }
|
||||
s3_api_secret_key: { file: ./secrets/s3_api_secret_key.txt }
|
||||
s3_admin_access_key: { file: ./secrets/s3_admin_access_key.txt }
|
||||
s3_admin_secret_key: { file: ./secrets/s3_admin_secret_key.txt }
|
||||
|
||||
volumes:
|
||||
postgres-data:
|
||||
redis-data:
|
||||
s3-data:
|
||||
broker-data:
|
||||
Reference in New Issue
Block a user