forked from mtusi2026/mtusi2026lab4
solution
This commit is contained in:
+218
@@ -0,0 +1,218 @@
|
||||
name: mtusi-messenger-lab4
|
||||
|
||||
x-s3-env: &s3-env
|
||||
S3_ENDPOINT_URL: http://minio:9000
|
||||
S3_REGION: us-east-1
|
||||
S3_BUCKET: ${S3_BUCKET:-attachments}
|
||||
S3_ACCESS_KEY: ${S3_ACCESS_KEY:?run python scripts/init_env.py}
|
||||
S3_SECRET_KEY: ${S3_SECRET_KEY:?run python scripts/init_env.py}
|
||||
|
||||
x-api-env: &api-env
|
||||
<<: *s3-env
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_PORT: "8080"
|
||||
APP_ENV: lab4
|
||||
LOG_LEVEL: ${LOG_LEVEL:-INFO}
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
SESSION_STORE: postgres
|
||||
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:?set POSTGRES_USER}:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:?set POSTGRES_DB}
|
||||
CACHE_URL: ${CACHE_URL-redis://redis:6379/0}
|
||||
CACHE_TTL_SECONDS: "60"
|
||||
CACHE_TIMEOUT_MS: "300"
|
||||
CACHE_RETRY_SECONDS: "5"
|
||||
DB_POOL_SIZE: "5"
|
||||
DB_MAX_OVERFLOW: "5"
|
||||
DB_POOL_TIMEOUT: "1"
|
||||
CLEANUP_GRACE_SECONDS: "3600"
|
||||
CLEANUP_INTERVAL_SECONDS: "60"
|
||||
|
||||
x-api: &api
|
||||
build: .
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab4}
|
||||
environment: *api-env
|
||||
networks: [edge, data]
|
||||
expose: ["8080"]
|
||||
cpus: 0.50
|
||||
mem_limit: 512m
|
||||
stop_signal: SIGTERM
|
||||
stop_grace_period: 10s
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-m", "app.healthcheck"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
start_period: 5s
|
||||
retries: 2
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
minio-init:
|
||||
condition: service_completed_successfully
|
||||
restart: unless-stopped
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres:16.6-bookworm
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:?set POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB:?set POSTGRES_DB}
|
||||
networks: [data]
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
cpus: 1.0
|
||||
mem_limit: 512m
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 15
|
||||
restart: unless-stopped
|
||||
|
||||
redis:
|
||||
image: redis:7.4.1-bookworm
|
||||
command: ["redis-server", "--save", "", "--appendonly", "no", "--maxmemory", "64mb", "--maxmemory-policy", "noeviction"]
|
||||
networks: [data]
|
||||
cpus: 0.25
|
||||
mem_limit: 128m
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
|
||||
migrate:
|
||||
build: .
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab4}
|
||||
command: ["python", "-m", "app.migrate"]
|
||||
environment: *api-env
|
||||
networks: [data]
|
||||
cpus: 0.50
|
||||
mem_limit: 256m
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
|
||||
minio:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: infra/minio/Dockerfile
|
||||
target: server
|
||||
image: mtusi-minio:RELEASE.2025-10-15T17-29-55Z
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?run python scripts/init_env.py}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?run python scripts/init_env.py}
|
||||
MINIO_BROWSER: "off"
|
||||
MINIO_SITE_REGION: us-east-1
|
||||
MINIO_API_REQUESTS_MAX: "32"
|
||||
networks: [data]
|
||||
volumes:
|
||||
- miniodata:/data
|
||||
cpus: 1.0
|
||||
mem_limit: 512m
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "/opt/minio/healthcheck.py"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
start_period: 10s
|
||||
retries: 15
|
||||
restart: unless-stopped
|
||||
|
||||
minio-init:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: infra/minio/Dockerfile
|
||||
target: bootstrap
|
||||
image: mtusi-minio-mc:RELEASE.2025-08-13T08-35-41Z
|
||||
environment:
|
||||
<<: *s3-env
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?run python scripts/init_env.py}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?run python scripts/init_env.py}
|
||||
networks: [data]
|
||||
cpus: 0.50
|
||||
mem_limit: 128m
|
||||
depends_on:
|
||||
minio:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
|
||||
cleanup:
|
||||
build: .
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab4}
|
||||
command: ["python", "-m", "app.cleanup", "--loop"]
|
||||
environment: *api-env
|
||||
networks: [data]
|
||||
cpus: 0.25
|
||||
mem_limit: 256m
|
||||
healthcheck:
|
||||
disable: true
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
minio-init:
|
||||
condition: service_completed_successfully
|
||||
restart: unless-stopped
|
||||
|
||||
api-a:
|
||||
<<: *api
|
||||
|
||||
api-b:
|
||||
<<: *api
|
||||
|
||||
nginx:
|
||||
image: nginx:1.28.0-alpine
|
||||
entrypoint: ["/bin/sh", "/opt/lb/entrypoint.sh"]
|
||||
volumes:
|
||||
- ./infra/nginx:/opt/lb:ro
|
||||
ports: ["127.0.0.1:8080:8080"]
|
||||
networks: [edge]
|
||||
cpus: 0.25
|
||||
mem_limit: 96m
|
||||
stop_signal: SIGQUIT
|
||||
stop_grace_period: 10s
|
||||
depends_on:
|
||||
api-a:
|
||||
condition: service_started
|
||||
api-b:
|
||||
condition: service_started
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-T", "2", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
restart: unless-stopped
|
||||
|
||||
tests:
|
||||
profiles: [test]
|
||||
build:
|
||||
context: .
|
||||
target: test
|
||||
image: mtusi-messenger:lab4-test
|
||||
environment:
|
||||
<<: *s3-env
|
||||
TEST_DB_HOST: db
|
||||
TEST_DB_PORT: "5432"
|
||||
TEST_DB_USER: ${POSTGRES_USER:?set POSTGRES_USER}
|
||||
TEST_DB_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
|
||||
TEST_CACHE_URL: redis://redis:6379/15
|
||||
networks: [data]
|
||||
cpus: 1.0
|
||||
mem_limit: 512m
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
minio-init:
|
||||
condition: service_completed_successfully
|
||||
command: ["python", "-m", "pytest", "-v", "--no-header", "-p", "no:cacheprovider"]
|
||||
|
||||
networks:
|
||||
edge:
|
||||
data:
|
||||
internal: true
|
||||
|
||||
volumes:
|
||||
miniodata:
|
||||
pgdata:
|
||||
Reference in New Issue
Block a user