forked from mtusi2026/mtusi2026lab4
lab 4 na 4
This commit is contained in:
+110
-2
@@ -64,6 +64,10 @@ services:
|
||||
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
|
||||
@@ -77,8 +81,16 @@ services:
|
||||
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: 4
|
||||
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"]
|
||||
@@ -86,7 +98,7 @@ services:
|
||||
timeout: 2s
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
networks: [edge, data]
|
||||
networks: [edge, data, s3access]
|
||||
deploy:
|
||||
replicas: 2
|
||||
resources:
|
||||
@@ -106,16 +118,112 @@ services:
|
||||
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
|
||||
|
||||
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:
|
||||
redis-data:
|
||||
s3-data:
|
||||
Reference in New Issue
Block a user