forked from mtusi2026/mtusi2026lab4
216 lines
5.0 KiB
YAML
216 lines
5.0 KiB
YAML
services:
|
|
postgres:
|
|
image: postgres:16.6-alpine
|
|
environment:
|
|
POSTGRES_DB: ${POSTGRES_DB:?}
|
|
POSTGRES_USER: ${POSTGRES_USER:?}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?}
|
|
command:
|
|
- postgres
|
|
- -c
|
|
- max_connections=100
|
|
- -c
|
|
- shared_buffers=128MB
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test:
|
|
- CMD-SHELL
|
|
- pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"
|
|
interval: 2s
|
|
timeout: 1s
|
|
retries: 30
|
|
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
networks: [data]
|
|
|
|
redis:
|
|
image: redis:7.4.1-alpine
|
|
environment:
|
|
REDIS_PASSWORD: ${REDIS_PASSWORD:?}
|
|
command:
|
|
- sh
|
|
- -c
|
|
- |
|
|
exec redis-server \
|
|
--requirepass "$$REDIS_PASSWORD" \
|
|
--appendonly yes \
|
|
--appendfsync always \
|
|
--maxmemory 128mb \
|
|
--maxmemory-policy noeviction
|
|
volumes:
|
|
- redis_data:/data
|
|
healthcheck:
|
|
test:
|
|
- CMD-SHELL
|
|
- REDISCLI_AUTH="$$REDIS_PASSWORD" redis-cli ping | grep -q PONG
|
|
interval: 2s
|
|
timeout: 1s
|
|
retries: 30
|
|
cpus: 0.5
|
|
mem_limit: 192m
|
|
networks: [data]
|
|
|
|
minio:
|
|
build:
|
|
context: ./infra/minio
|
|
dockerfile: Dockerfile
|
|
|
|
image: mtusi4-minio:2025-04-22-local
|
|
pull_policy: build
|
|
|
|
command:
|
|
- server
|
|
- /data
|
|
- --console-address
|
|
- ":9001"
|
|
|
|
environment:
|
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?}
|
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?}
|
|
MINIO_API_STALE_UPLOADS_EXPIRY: "24h"
|
|
MINIO_API_STALE_UPLOADS_CLEANUP_INTERVAL: "1h"
|
|
|
|
volumes:
|
|
- minio_data:/data
|
|
|
|
ports:
|
|
- "127.0.0.1:9001:9001"
|
|
|
|
healthcheck:
|
|
test:
|
|
- CMD
|
|
- curl
|
|
- -f
|
|
- http://localhost:9000/minio/health/live
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 20
|
|
start_period: 10s
|
|
|
|
cpus: 1.0
|
|
mem_limit: 768m
|
|
restart: unless-stopped
|
|
networks: [data]
|
|
|
|
minio-init:
|
|
build:
|
|
context: ./infra/minio
|
|
dockerfile: Dockerfile
|
|
|
|
image: mtusi4-minio:2025-04-22-local
|
|
pull_policy: build
|
|
|
|
depends_on:
|
|
minio:
|
|
condition: service_healthy
|
|
|
|
environment:
|
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?}
|
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?}
|
|
|
|
S3_BUCKET: ${S3_BUCKET:?}
|
|
S3_ACCESS_KEY: ${S3_ACCESS_KEY:?}
|
|
S3_SECRET_KEY: ${S3_SECRET_KEY:?}
|
|
|
|
volumes:
|
|
- ./infra/minio/bootstrap.sh:/bootstrap/bootstrap.sh:ro
|
|
- ./infra/minio/check-access.sh:/bootstrap/check-access.sh:ro
|
|
|
|
entrypoint:
|
|
- /bin/sh
|
|
- /bootstrap/bootstrap.sh
|
|
|
|
restart: "no"
|
|
networks: [data]
|
|
|
|
migrate:
|
|
image: flyway/flyway:10.20.1-alpine
|
|
command:
|
|
- -connectRetries=30
|
|
- migrate
|
|
environment:
|
|
FLYWAY_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB:?}
|
|
FLYWAY_USER: ${POSTGRES_USER:?}
|
|
FLYWAY_PASSWORD: ${POSTGRES_PASSWORD:?}
|
|
volumes:
|
|
- ./java/src/main/resources/db/migration:/flyway/sql:ro
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
cpus: 0.5
|
|
mem_limit: 384m
|
|
restart: "no"
|
|
networks: [data]
|
|
|
|
api:
|
|
build: .
|
|
image: ${APP_IMAGE:-mtusi4-api:local}
|
|
environment:
|
|
DB_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB:?}
|
|
DB_USERNAME: ${POSTGRES_USER:?}
|
|
DB_PASSWORD: ${POSTGRES_PASSWORD:?}
|
|
REDIS_HOST: redis
|
|
REDIS_PASSWORD: ${REDIS_PASSWORD:?}
|
|
DB_POOL_SIZE: ${DB_POOL_SIZE:-8}
|
|
FLYWAY_ENABLED: "false"
|
|
S3_ENDPOINT: http://minio:9000
|
|
S3_ACCESS_KEY: ${S3_ACCESS_KEY:?}
|
|
S3_SECRET_KEY: ${S3_SECRET_KEY:?}
|
|
S3_BUCKET: ${S3_BUCKET:?}
|
|
UPLOAD_MAX_CONCURRENT: ${UPLOAD_MAX_CONCURRENT:-1}
|
|
UPLOAD_TEMP_DIR: /tmp/messenger-uploads
|
|
ATTACHMENT_CLEANUP_ENABLED: "true"
|
|
ATTACHMENT_CLEANUP_GRACE_SECONDS: ${ATTACHMENT_CLEANUP_GRACE_SECONDS:-3600}
|
|
ATTACHMENT_CLEANUP_INTERVAL_MS: ${ATTACHMENT_CLEANUP_INTERVAL_MS:-300000}
|
|
ATTACHMENT_CLEANUP_INITIAL_DELAY_MS: ${ATTACHMENT_CLEANUP_INITIAL_DELAY_MS:-60000}
|
|
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
redis:
|
|
condition: service_healthy
|
|
minio-init:
|
|
condition: service_completed_successfully
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
cpus: ${API_CPUS:-1.0}
|
|
mem_limit: ${API_MEMORY:-768m}
|
|
stop_grace_period: 20s
|
|
|
|
healthcheck:
|
|
test:
|
|
- CMD
|
|
- wget
|
|
- -qO-
|
|
- http://localhost:8080/health/ready
|
|
interval: 5s
|
|
timeout: 15s
|
|
start_period: 60s
|
|
retries: 3
|
|
networks: [edge, data]
|
|
|
|
lb:
|
|
image: haproxy:3.0.5-alpine
|
|
ports:
|
|
- "127.0.0.1:${API_PORT:-8080}:8080"
|
|
volumes:
|
|
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
networks: [edge]
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
minio_data:
|
|
|
|
networks:
|
|
edge:
|
|
data:
|
|
internal: true |