241 lines
6.7 KiB
YAML
241 lines
6.7 KiB
YAML
x-lab-number: 4
|
|
x-required-roles:
|
|
- api
|
|
- postgres
|
|
- load_balancer
|
|
- s3
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:18.6-alpine
|
|
container_name: mtuci-postgres
|
|
environment:
|
|
POSTGRES_USER: ${POSTGRES_USER:-messenger}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger}
|
|
POSTGRES_DB: ${POSTGRES_DB:-high_load_messenger}
|
|
volumes:
|
|
- postgres-data:/var/lib/postgresql
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-messenger} -d ${POSTGRES_DB:-high_load_messenger}"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 20
|
|
start_period: 30s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 1G
|
|
reservations:
|
|
cpus: "0.25"
|
|
memory: 256M
|
|
|
|
redis:
|
|
image: redis:7.4.1-alpine
|
|
container_name: mtuci-redis
|
|
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "everysec", "--save", "60", "1"]
|
|
volumes:
|
|
- redis-data:/data
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 3s
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 64M
|
|
|
|
minio:
|
|
image: netvark/minio:20260213
|
|
container_name: mtuci-minio
|
|
command: ["server", "/data", "--console-address", ":9001"]
|
|
environment:
|
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
|
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}
|
|
MINIO_BROWSER_REDIRECT_URL: http://localhost:9001
|
|
volumes:
|
|
- minio-data:/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "curl -f http://localhost:9000/minio/health/live || exit 1"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 20
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
# Консоль администратора НЕ публикуется наружу; доступ только из сети compose.
|
|
# Порт 9000 (S3 API) тоже внутренний — публичного доступа нет.
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 128M
|
|
|
|
minio-init:
|
|
image: netvark/mc:20260920
|
|
container_name: mtuci-minio-init
|
|
depends_on:
|
|
minio:
|
|
condition: service_healthy
|
|
entrypoint: ["/bin/sh", "-c"]
|
|
command:
|
|
- |
|
|
set -eu
|
|
mc alias set local http://minio:9000 "$${MINIO_ROOT_USER}" "$${MINIO_ROOT_PASSWORD}"
|
|
# Приватный bucket; idempotent.
|
|
mc mb --ignore-existing local/"$${S3_BUCKET}"
|
|
# Политика: bucket не публичный. Явно none.
|
|
mc anonymous set none local/"$${S3_BUCKET}" || true
|
|
# Прикладные S3-credentials с ограниченными правами на префикс приложения.
|
|
# Политика выдаётся через `mc admin policy`; создаём отдельного пользователя.
|
|
if ! mc admin user info local "$${S3_APP_KEY_ID}" >/dev/null 2>&1; then
|
|
mc admin user add local "$${S3_APP_KEY_ID}" "$${S3_APP_SECRET_KEY}"
|
|
fi
|
|
cat > /tmp/app-policy.json <<'POLICY'
|
|
{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Effect": "Allow",
|
|
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
|
|
"Resource": ["arn:aws:s3:::${S3_BUCKET}"]
|
|
},
|
|
{
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"s3:GetObject", "s3:PutObject", "s3:DeleteObject",
|
|
"s3:AbortMultipartUpload", "s3:ListMultipartUploadParts"
|
|
],
|
|
"Resource": ["arn:aws:s3:::${S3_BUCKET}/*"]
|
|
}
|
|
]
|
|
}
|
|
POLICY
|
|
# Подставляем имя bucket в политику
|
|
sed -i "s/\$${S3_BUCKET}/$${S3_BUCKET}/g" /tmp/app-policy.json || true
|
|
mc admin policy create local messenger-app /tmp/app-policy.json 2>/dev/null || true
|
|
mc admin policy attach local messenger-app --user "$${S3_APP_KEY_ID}" || true
|
|
echo "minio-init done"
|
|
env_file:
|
|
- .env
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.2"
|
|
memory: 64M
|
|
|
|
migrate:
|
|
build: .
|
|
image: mtuci-messenger:lab4
|
|
command: ["python", "-m", "app.storage.db"]
|
|
env_file:
|
|
- .env
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
restart: "no"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 64M
|
|
|
|
api:
|
|
build: .
|
|
image: mtuci-messenger:lab4
|
|
env_file:
|
|
- .env
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready').read()"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 5
|
|
start_period: 10s
|
|
restart: unless-stopped
|
|
deploy:
|
|
replicas: 2
|
|
resources:
|
|
limits:
|
|
cpus: "1.0"
|
|
memory: 512M
|
|
reservations:
|
|
cpus: "0.25"
|
|
memory: 128M
|
|
|
|
# Уровень 4: фоновая сверка S3↔БД (orphan-объекты и missing).
|
|
# Запускается как долгоживущий сервис, спит CLEANUP_INTERVAL_SECONDS.
|
|
s3_cleanup:
|
|
build: .
|
|
image: mtuci-messenger:lab4
|
|
command: ["python", "-m", "app.storage.s3_cleanup"]
|
|
env_file:
|
|
- .env
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.3"
|
|
memory: 256M
|
|
reservations:
|
|
cpus: "0.05"
|
|
memory: 64M
|
|
|
|
lb:
|
|
image: nginx:1.27.3-alpine
|
|
container_name: mtuci-lb
|
|
ports:
|
|
- "127.0.0.1:8080:80"
|
|
volumes:
|
|
- ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: "0.5"
|
|
memory: 128M
|
|
reservations:
|
|
cpus: "0.1"
|
|
memory: 32M
|
|
|
|
volumes:
|
|
postgres-data:
|
|
name: mtuci2026lab4_postgres-data
|
|
redis-data:
|
|
name: mtuci2026lab4_redis-data
|
|
minio-data:
|
|
name: mtuci2026lab4_minio-data
|
|
|
|
networks:
|
|
default:
|
|
name: mtuci2026lab4_default |