feat: add s3 readiness and orphan object reconciler

This commit is contained in:
2026-11-05 15:41:41 +03:00
parent f523cad721
commit a7980a4cb8
11 changed files with 565 additions and 6 deletions
+30 -2
View File
@@ -10,7 +10,7 @@ services:
- -ec
- |
cd /secrets
mkdir -p postgres redis api migrate s3 s3-init
mkdir -p postgres redis api migrate s3 s3-init reconciler
for entry in pg_password:postgres:24 redis_password:redis:24 s3_root_user:s3:10 s3_root_password:s3:20 s3_access_key_id:api:10 s3_secret_access_key:api:20; do
file=$${entry%%:*}; rest=$${entry#*:}; dir=$${rest%%:*}; size=$${rest##*:}
[ -s "$$dir/$$file" ] || head -c "$$size" /dev/urandom | od -An -tx1 | tr -d ' \n' > "$$dir/$$file"
@@ -20,7 +20,8 @@ services:
printf 'postgresql://messenger:%s@postgres:5432/messenger?connection_limit=10&pool_timeout=5&connect_timeout=5&socket_timeout=10&application_name=api&options=-c%%20statement_timeout%%3D5000' "$$(cat postgres/pg_password)" > api/database_url
printf 'redis://:%s@redis:6379/0' "$$(cat redis/redis_password)" > api/cache_url
printf 'postgresql://messenger:%s@postgres:5432/messenger' "$$(cat postgres/pg_password)" > migrate/database_url
chmod 0444 postgres/* redis/* api/* migrate/* s3/* s3-init/*
cp api/database_url api/s3_access_key_id api/s3_secret_access_key reconciler/
chmod 0444 postgres/* redis/* api/* migrate/* s3/* s3-init/* reconciler/*
deploy:
resources:
limits: { cpus: "0.1", memory: 32M }
@@ -175,6 +176,33 @@ services:
condition: service_completed_successfully
restart: unless-stopped
reconciler:
build:
context: .
target: runtime
image: mtusi-messenger-lab4-api:dev
command: ["node", "dist/reconcile.js", "--apply", "--loop", "--grace-seconds=${RECONCILE_GRACE_SECONDS:-3600}", "--interval-seconds=${RECONCILE_INTERVAL_SECONDS:-300}"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
S3_ENDPOINT: http://s3:9000
S3_REGION: ${S3_REGION:-us-east-1}
S3_BUCKET: ${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
volumes:
- { type: volume, source: secrets, target: /run/secrets, read_only: true, volume: { subpath: reconciler } }
deploy:
resources:
limits: { cpus: "0.25", memory: 128M }
healthcheck:
disable: true
depends_on:
migrate:
condition: service_completed_successfully
s3-init:
condition: service_completed_successfully
restart: unless-stopped
lb:
image: haproxy:3.0.6-alpine
ports: