forked from mtusi2026/mtusi2026lab4
Лабораторная 4 — вложения и приватное S3
This commit is contained in:
+203
@@ -0,0 +1,203 @@
|
||||
name: mtusi-lab4
|
||||
|
||||
x-api: &api
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
APP_REVISION: ${API_IMAGE_TAG:-local}
|
||||
image: mtusi-lab4-api:${API_IMAGE_TAG:-local}
|
||||
environment: &api-env
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: '8080'
|
||||
APP_ENV: lab4
|
||||
CURSOR_SECRET_FILE: /run/secrets/cursor_secret
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CACHE_URL_FILE: /run/secrets/cache_url
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
SESSION_STORE: redis
|
||||
SHUTDOWN_GRACE_SECONDS: '8'
|
||||
DB_POOL_MIN: '2'
|
||||
DB_POOL_MAX: '16'
|
||||
DB_CONNECT_TIMEOUT: '1'
|
||||
DB_STATEMENT_TIMEOUT: '4'
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
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
|
||||
secrets: [database_url, cache_url, cursor_secret, s3_access_key_id, s3_secret_access_key]
|
||||
depends_on:
|
||||
s3-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
redis:
|
||||
condition: service_healthy
|
||||
networks: [backend]
|
||||
cpus: 0.50
|
||||
mem_limit: 256m
|
||||
stop_grace_period: 9s
|
||||
healthcheck:
|
||||
test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=1)"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 2
|
||||
start_period: 3s
|
||||
# Deliberately no auto-restart: failover hook must leave its target stopped.
|
||||
restart: 'no'
|
||||
|
||||
services:
|
||||
s3:
|
||||
image: mtusi-lab4-s3:2025-09-07
|
||||
build: &s3-build
|
||||
context: .
|
||||
dockerfile: infra/Dockerfile.s3
|
||||
entrypoint: [/bin/sh, -ec]
|
||||
command:
|
||||
- |
|
||||
MINIO_ROOT_USER=$$(cat /run/secrets/s3_root_user)
|
||||
MINIO_ROOT_PASSWORD=$$(cat /run/secrets/s3_root_password)
|
||||
export MINIO_ROOT_USER MINIO_ROOT_PASSWORD
|
||||
exec minio server /data
|
||||
environment:
|
||||
MINIO_BROWSER: "off"
|
||||
secrets: [s3_root_user, s3_root_password]
|
||||
volumes: [s3_data:/data]
|
||||
networks: [backend]
|
||||
|
||||
s3-bootstrap:
|
||||
image: mtusi-lab4-s3:2025-09-07
|
||||
build: *s3-build
|
||||
entrypoint: [/bin/sh, /bootstrap.sh]
|
||||
command: []
|
||||
environment:
|
||||
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
|
||||
secrets: [s3_root_user, s3_root_password, s3_access_key_id, s3_secret_access_key]
|
||||
volumes: [./infra/s3-bootstrap.sh:/bootstrap.sh:ro]
|
||||
depends_on: [s3]
|
||||
networks: [backend]
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine@sha256:54e0dd8e8cddcdbb9156c2486eed5a43eccb7214d7c6828097d41ce049fb3984
|
||||
environment:
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
secrets: [postgres_password]
|
||||
volumes: [pg_data:/var/lib/postgresql/data]
|
||||
networks: [backend]
|
||||
cpus: 1.0
|
||||
mem_limit: 512m
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'pg_isready -U messenger -d messenger']
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 20
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine@sha256:8da19c7399dca900c6822a1cf30f9d2285585e2c4b457ff4095b0f4500054d3f
|
||||
command: [redis-server, --appendonly, 'yes', --maxmemory, 96mb, --maxmemory-policy, allkeys-lru]
|
||||
volumes: [redis_data:/data]
|
||||
networks: [backend]
|
||||
cpus: 0.25
|
||||
mem_limit: 128m
|
||||
healthcheck:
|
||||
test: [CMD, redis-cli, ping]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 10
|
||||
|
||||
migrate:
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
APP_REVISION: ${API_IMAGE_TAG:-local}
|
||||
image: mtusi-lab4-api:${API_IMAGE_TAG:-local}
|
||||
command: [python, -m, messenger.migrate]
|
||||
environment: *api-env
|
||||
secrets: [database_url, cache_url, cursor_secret]
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
networks: [backend]
|
||||
cpus: 0.50
|
||||
mem_limit: 256m
|
||||
restart: 'no'
|
||||
healthcheck:
|
||||
disable: true
|
||||
|
||||
attachment-cleaner:
|
||||
image: mtusi-lab4-api:${API_IMAGE_TAG:-local}
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
APP_REVISION: ${API_IMAGE_TAG:-local}
|
||||
command: [python, -m, messenger.clean_attachments]
|
||||
environment: *api-env
|
||||
secrets: [database_url, s3_access_key_id, s3_secret_access_key]
|
||||
depends_on:
|
||||
s3-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
networks: [backend]
|
||||
cpus: 0.25
|
||||
mem_limit: 128m
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
disable: true
|
||||
|
||||
api-a:
|
||||
<<: *api
|
||||
api-b:
|
||||
<<: *api
|
||||
|
||||
nginx:
|
||||
image: nginx:1.28.2-alpine@sha256:5b4900b042ccfa8b0a73df622c3a60f2322faeb2be800cbee5aa7b44d241649e
|
||||
entrypoint: [/bin/sh, -ec]
|
||||
command:
|
||||
- 'cp /etc/nginx/lab/upstreams.conf /etc/nginx/upstreams.conf; /bin/sh /etc/nginx/lab/healthwatch.sh & exec nginx -g "daemon off;"'
|
||||
volumes:
|
||||
- ./infra/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
- ./infra:/etc/nginx/lab:ro
|
||||
ports: ['127.0.0.1:${PUBLIC_PORT:-18081}:8080']
|
||||
networks: [frontend, backend]
|
||||
depends_on:
|
||||
api-a:
|
||||
condition: service_healthy
|
||||
api-b:
|
||||
condition: service_healthy
|
||||
cpus: 0.50
|
||||
mem_limit: 128m
|
||||
stop_grace_period: 10s
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'kill -0 $$(cat /tmp/healthwatch.pid) && wget -T 1 -q -O /dev/null http://127.0.0.1:8080/health/ready']
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 3
|
||||
|
||||
networks:
|
||||
frontend:
|
||||
backend:
|
||||
internal: true
|
||||
volumes:
|
||||
pg_data:
|
||||
redis_data:
|
||||
s3_data:
|
||||
secrets:
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password
|
||||
database_url:
|
||||
file: ./secrets/database_url
|
||||
cache_url:
|
||||
file: ./secrets/cache_url
|
||||
cursor_secret:
|
||||
file: ./secrets/cursor_secret
|
||||
s3_root_user:
|
||||
file: ./secrets/s3_root_user
|
||||
s3_root_password:
|
||||
file: ./secrets/s3_root_password
|
||||
s3_access_key_id:
|
||||
file: ./secrets/s3_access_key_id
|
||||
s3_secret_access_key:
|
||||
file: ./secrets/s3_secret_access_key
|
||||
Reference in New Issue
Block a user