Реализовать уровень 3: приватное S3, вложения и сохранность при отказах

This commit is contained in:
2026-10-30 17:33:07 +03:00
parent 2e5f5bfe1b
commit 4f85fb96a6
30 changed files with 592 additions and 27 deletions
+39 -5
View File
@@ -1,19 +1,23 @@
name: lyakhonov-lab3
name: lyakhonov-lab4
x-api: &api
image: lyakhonov-messenger:lab3
image: lyakhonov-messenger:lab4
build: .
environment:
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL: redis://redis:6379/0
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
POOL_SIZE: ${POOL_SIZE:-10}
S3_ENDPOINT: http://s3:9000
S3_BUCKET: attachments
S3_ACCESS_KEY_FILE: /run/secrets/s3_access_key
S3_SECRET_KEY_FILE: /run/secrets/s3_secret_key
OPTIMIZED_WRITES: ${OPTIMIZED_WRITES:-1}
secrets: [database_url]
secrets: [database_url, s3_access_key, s3_secret_key]
depends_on:
migrate:
condition: service_completed_successfully
cpus: ${API_CPUS:-0.5}
mem_limit: ${API_MEMORY:-256m}
mem_limit: ${API_MEMORY:-512m}
stop_grace_period: 12s
services:
db:
@@ -44,13 +48,34 @@ services:
condition: service_healthy
healthcheck:
disable: true
s3:
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
command: [server, /data, --console-address, '127.0.0.1:9001']
environment:
MINIO_ROOT_USER_FILE: /run/secrets/s3_root_user
MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_root_password
secrets: [s3_root_user, s3_root_password]
volumes: [s3_data:/data]
cpus: 1
mem_limit: 768m
bucket-init:
image: minio/minio@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e
entrypoint: [/bin/sh, /bootstrap/bucket.sh]
secrets: [s3_root_user, s3_root_password, s3_access_key, s3_secret_key]
volumes: [./infra/bucket.sh:/bootstrap/bucket.sh:ro, ./infra/s3-policy.json:/bootstrap/policy.json:ro]
depends_on: [s3]
api:
<<: *api
depends_on:
migrate:
condition: service_completed_successfully
bucket-init:
condition: service_completed_successfully
deploy:
replicas: ${API_REPLICAS:-2}
lb:
image: haproxy:3.0.6-alpine
ports: ["127.0.0.1:8080:8080"]
ports: ["127.0.0.1:${LAB4_PORT:-8084}:8080"]
volumes: [./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro]
depends_on: [api]
cpus: 0.5
@@ -62,9 +87,18 @@ services:
timeout: 2s
retries: 3
secrets:
s3_root_user:
file: ./secrets/s3_root_user
s3_root_password:
file: ./secrets/s3_root_password
s3_access_key:
file: ./secrets/s3_access_key
s3_secret_key:
file: ./secrets/s3_secret_key
db_password:
file: ./secrets/db_password
database_url:
file: ./secrets/database_url
volumes:
postgres_data:
s3_data: