Добавьте S3-вложения с дедупликацией и безопасной сверкой хранилищ

This commit is contained in:
2026-11-16 12:36:59 +03:00
parent b323f2dab9
commit d761861def
54 changed files with 5061 additions and 102 deletions
+131 -6
View File
@@ -1,5 +1,5 @@
# Local stand: HAProxy in front of interchangeable API replicas over shared
# PostgreSQL and Valkey. Only the balancer is published, on loopback; the data
# PostgreSQL, Valkey and S3. Only the balancer is published, on loopback; the data
# network has no way out. The load-test knobs are in compose.bench.yaml.
name: lab4
@@ -38,11 +38,24 @@ services:
SESSION_STORE_URL_FILE: /run/secrets/session_store_url
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
# Go does not read the cgroup memory limit.
GOMEMLIMIT: 230MiB
S3_ENDPOINT: ${S3_ENDPOINT:-http://s3:8333}
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
# The background reconciler uses a separate identity with List rights.
S3_RECONCILE_ACCESS_KEY_ID_FILE: /run/secrets/s3_reconcile_access_key_id
S3_RECONCILE_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_reconcile_secret_access_key
# One decoder per replica. Progressive JPEG retains coefficient buffers;
# a wide RGBA64 PNG also holds two scanlines beside the full pixel buffer.
GOMEMLIMIT: 1536MiB
secrets:
- database_url
- session_store_url
- s3_access_key_id
- s3_secret_access_key
- s3_reconcile_access_key_id
- s3_reconcile_secret_access_key
networks:
- edge
- data
@@ -53,14 +66,16 @@ services:
condition: service_healthy
valkey:
condition: service_healthy
# Drain delay 2 s plus shutdown timeout 8 s, before SIGKILL.
stop_grace_period: 15s
s3-init:
condition: service_completed_successfully
# Binary deadline 30s plus compensation, shutdown and drain margin.
stop_grace_period: 45s
deploy:
replicas: ${API_REPLICAS:-2}
resources:
limits:
cpus: "1.0"
memory: 256M
memory: 2G
migrate:
image: mtusi-messenger:lab4
@@ -138,9 +153,105 @@ services:
# maxmemory 256mb (valkey.conf) plus the server's own overhead.
memory: 320M
s3:
image: chrislusf/seaweedfs:4.53@sha256:ccad23e18639c8b98cee17e7100b95830a06077b56d8e5b006d6dcf8ec5e94a0
command: ["server", "-options=/etc/seaweedfs/lab.options"]
environment:
GOMEMLIMIT: 460MiB
secrets:
- s3_identities
volumes:
- ./infra/s3/seaweedfs.options:/etc/seaweedfs/lab.options:ro
# Both volume data and the image's /data/filerldb2 metadata live here.
- s3data:/data
networks:
- data
healthcheck:
# A reachable anonymous request must be refused, including before init.
test: ["CMD-SHELL", "wget -S -O /dev/null http://127.0.0.1:8333/ 2>&1 | grep -q ' 403 '"]
interval: 5s
timeout: 3s
retries: 12
start_period: 15s
start_interval: 1s
stop_grace_period: 30s
pids_limit: 256
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
pids: 256
s3-init:
build: .
image: mtusi-messenger:lab4
entrypoint: ["/usr/local/bin/s3init"]
environment:
S3_ENDPOINT: ${S3_ENDPOINT:-http://s3:8333}
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
GOMEMLIMIT: 100MiB
secrets:
- source: s3_admin_access_key_id
target: s3_access_key_id
- source: s3_admin_secret_access_key
target: s3_secret_access_key
networks:
- data
depends_on:
s3:
condition: service_healthy
restart: "no"
healthcheck:
disable: true
deploy:
resources:
limits:
cpus: "0.5"
memory: 128M
reconcile:
profiles: ["recon"]
build: .
image: mtusi-messenger:lab4
entrypoint: ["/usr/local/bin/reconcile"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
S3_ENDPOINT: ${S3_ENDPOINT:-http://s3:8333}
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
GOMEMLIMIT: 100MiB
secrets:
- database_url
- source: s3_reconcile_access_key_id
target: s3_access_key_id
- source: s3_reconcile_secret_access_key
target: s3_secret_access_key
networks:
- data
depends_on:
migrate:
condition: service_completed_successfully
s3-init:
condition: service_completed_successfully
restart: "no"
healthcheck:
disable: true
deploy:
resources:
limits:
cpus: "0.5"
memory: 128M
volumes:
pgdata:
valkeydata:
s3data:
networks:
edge: {}
@@ -156,3 +267,17 @@ secrets:
file: ./secrets/postgres_password
valkey_auth:
file: ./secrets/valkey_auth.conf
s3_identities:
file: ./secrets/s3_identities.json
s3_admin_access_key_id:
file: ./secrets/s3_admin_access_key_id
s3_admin_secret_access_key:
file: ./secrets/s3_admin_secret_access_key
s3_access_key_id:
file: ./secrets/s3_access_key_id
s3_secret_access_key:
file: ./secrets/s3_secret_access_key
s3_reconcile_access_key_id:
file: ./secrets/s3_reconcile_access_key_id
s3_reconcile_secret_access_key:
file: ./secrets/s3_reconcile_secret_access_key