feat(app) implemented lab 4

This commit is contained in:
imadev
2026-11-06 19:06:21 +03:00
parent 68968c4a3a
commit b4239f8cf0
63 changed files with 3944 additions and 137 deletions
+105 -1
View File
@@ -6,6 +6,7 @@ x-api-build: &api-build
context: .
dockerfile: Dockerfile
# API receives only the attachments/ scoped S3 credential
x-api-environment: &api-environment
APP_HOST: 0.0.0.0
APP_PORT: "8080"
@@ -14,6 +15,15 @@ x-api-environment: &api-environment
CACHE_URL: redis://redis:6379/0
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
S3_ENDPOINT: ${S3_ENDPOINT:-http://rustfs:9000}
S3_REGION: ${S3_REGION:-us-east-1}
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?set S3_ACCESS_KEY_ID in .env}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?set S3_SECRET_ACCESS_KEY in .env}
MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760}
MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000}
IMAGE_DECODE_MEMORY_MB: ${IMAGE_DECODE_MEMORY_MB:-256}
UPLOAD_TEMP_DIR: /tmp/messenger-uploads
services:
postgres:
@@ -64,6 +74,67 @@ services:
cpus: "${REDIS_CPU_LIMIT:-0.50}"
memory: "${REDIS_MEM_LIMIT:-256M}"
rustfs:
image: rustfs/rustfs:1.0.4
restart: unless-stopped
# AGENT: no published ports. The S3 API is reachable only on the Compose
# network, and the admin console is disabled. For inspection, see the
# one-shot rc client pattern in scripts/check-private-bucket.sh.
environment:
RUSTFS_ACCESS_KEY: ${S3_ROOT_ACCESS_KEY:?set S3_ROOT_ACCESS_KEY in .env}
RUSTFS_SECRET_KEY: ${S3_ROOT_SECRET_KEY:?set S3_ROOT_SECRET_KEY in .env}
RUSTFS_ADDRESS: ":9000"
RUSTFS_CONSOLE_ENABLE: "false"
RUSTFS_OBS_LOGGER_LEVEL: "error"
RUSTFS_OBS_LOG_DIRECTORY: "/logs"
command: ["/data"]
volumes:
- rustfsdata:/data
expose:
- "9000"
healthcheck:
test:
[
"CMD-SHELL",
"wget -q -O - http://127.0.0.1:9000/health/ready >/dev/null",
]
interval: 3s
timeout: 3s
retries: 20
start_period: 5s
stop_grace_period: 15s
deploy:
resources:
limits:
cpus: "${RUSTFS_CPU_LIMIT:-1.0}"
memory: "${RUSTFS_MEM_LIMIT:-512M}"
# AGENT: bootstrap converges the bucket and the scoped IAM identity on every
# run. Create is idempotent (ignore-existing), policy create replaces the
# named document, and user add updates the password if the user exists.
s3-init:
image: rustfs/rc:v0.1.36
restart: "no"
depends_on:
rustfs:
condition: service_healthy
environment:
HOME: /tmp
S3_ENDPOINT: ${S3_ENDPOINT:-http://rustfs:9000}
S3_REGION: ${S3_REGION:-us-east-1}
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_ROOT_ACCESS_KEY: ${S3_ROOT_ACCESS_KEY:?set S3_ROOT_ACCESS_KEY in .env}
S3_ROOT_SECRET_KEY: ${S3_ROOT_SECRET_KEY:?set S3_ROOT_SECRET_KEY in .env}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?set S3_ACCESS_KEY_ID in .env}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?set S3_SECRET_ACCESS_KEY in .env}
S3_APP_USER: ${S3_APP_USER:-messenger-api}
S3_APP_POLICY: ${S3_APP_POLICY:-messenger-attachments-rw}
S3_POLICY_TEMPLATE: /config/api-policy.json.template
volumes:
- ./infra/rustfs/bootstrap.sh:/bootstrap.sh:ro
- ./infra/rustfs/api-policy.json.template:/config/api-policy.json.template:ro
entrypoint: ["/bin/sh", "/bootstrap.sh"]
migrate:
<<: *api-build
restart: "no"
@@ -82,6 +153,10 @@ services:
condition: service_healthy
redis:
condition: service_healthy
rustfs:
condition: service_healthy
s3-init:
condition: service_completed_successfully
migrate:
condition: service_completed_successfully
environment:
@@ -102,7 +177,35 @@ services:
resources:
limits:
cpus: "${API_CPU_LIMIT:-0.50}"
memory: "${API_MEM_LIMIT:-256M}"
memory: "${API_MEM_LIMIT:-512M}"
# AGENT: the reconciler uses the same scoped credential as the API. It never
# touches ready attachments; it only removes stale pending rows/objects and
# objects with no metadata row at all.
reconciler:
<<: *api-build
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
rustfs:
condition: service_healthy
s3-init:
condition: service_completed_successfully
migrate:
condition: service_completed_successfully
environment:
<<: *api-environment
RUN_MIGRATIONS: "false"
RECONCILE_ONLY: "true"
RECONCILE_GRACE_SECONDS: ${RECONCILE_GRACE_SECONDS:-900}
RECONCILE_INTERVAL_SECONDS: ${RECONCILE_INTERVAL_SECONDS:-300}
entrypoint: ["/usr/local/bin/reconciler"]
deploy:
resources:
limits:
cpus: "${RECONCILER_CPU_LIMIT:-0.25}"
memory: "${RECONCILER_MEM_LIMIT:-128M}"
haproxy:
image: haproxy:3.2.6-alpine
@@ -152,3 +255,4 @@ services:
volumes:
pgdata:
redisdata:
rustfsdata: