forked from mtusi2026/mtusi2026lab5
Complete Lab 5 for Grade 4
This commit is contained in:
+199
@@ -0,0 +1,199 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16.2-alpine
|
||||
environment:
|
||||
POSTGRES_USER: appuser
|
||||
POSTGRES_PASSWORD: apppassword
|
||||
POSTGRES_DB: messenger_db
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U appuser -d messenger_db"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 5
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.00"
|
||||
memory: 512M
|
||||
restart: unless-stopped
|
||||
|
||||
redis:
|
||||
image: redis:7.2.4-alpine
|
||||
command: redis-server --appendonly yes
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 5
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.50"
|
||||
memory: 256M
|
||||
restart: unless-stopped
|
||||
|
||||
s3:
|
||||
image: rustfs/rustfs:latest
|
||||
environment:
|
||||
- RUSTFS_ACCESS_KEY=miniouser
|
||||
- RUSTFS_SECRET_KEY=miniopassword123
|
||||
- RUSTFS_ADDRESS=0.0.0.0:9000
|
||||
- RUSTFS_CONSOLE_ADDRESS=0.0.0.0:9001
|
||||
- RUSTFS_CONSOLE_ENABLE=false
|
||||
volumes:
|
||||
- s3_data:/data
|
||||
ports:
|
||||
- "9000:9000"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -f http://localhost:9000/health || exit 1"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 5
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.50"
|
||||
memory: 256M
|
||||
restart: unless-stopped
|
||||
|
||||
broker:
|
||||
image: rabbitmq:3.13.0-alpine
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: rabbituser
|
||||
RABBITMQ_DEFAULT_PASS: rabbitpassword
|
||||
volumes:
|
||||
- rabbitmq_data:/var/lib/rabbitmq
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.50"
|
||||
memory: 512M
|
||||
restart: unless-stopped
|
||||
|
||||
migrator:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
command: ["python", "src/migrate.py"]
|
||||
environment:
|
||||
DATABASE_URL: postgresql://appuser:apppassword@postgres:5432/messenger_db
|
||||
S3_ENDPOINT: http://s3:9000
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_ACCESS_KEY: miniouser
|
||||
S3_SECRET_KEY: miniopassword123
|
||||
volumes:
|
||||
- ./migrations:/app/migrations:ro
|
||||
- ./src:/app/src:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
s3:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: mtusi-messenger:lab5
|
||||
command: ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./secrets:/run/secrets:ro
|
||||
- ./src:/app/src:ro
|
||||
- ./scripts:/app/scripts:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
s3:
|
||||
condition: service_healthy
|
||||
broker:
|
||||
condition: service_healthy
|
||||
migrator:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8000/health/live"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 3
|
||||
deploy:
|
||||
replicas: 2
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.50"
|
||||
memory: 256M
|
||||
restart: unless-stopped
|
||||
|
||||
worker:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: mtusi-messenger:lab5
|
||||
command: ["python", "-u", "src/worker.py"]
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./secrets:/run/secrets:ro
|
||||
- ./src:/app/src:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
s3:
|
||||
condition: service_healthy
|
||||
broker:
|
||||
condition: service_healthy
|
||||
migrator:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import sys; sys.exit(0 if b'worker.py' in open('/proc/1/cmdline','rb').read() else 1)"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.00"
|
||||
memory: 512M
|
||||
restart: unless-stopped
|
||||
|
||||
load_balancer:
|
||||
image: nginx:1.25.4-alpine
|
||||
volumes:
|
||||
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
ports:
|
||||
- "8080:8080"
|
||||
depends_on:
|
||||
- api
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -f http://localhost:8080/health/live || exit 1"]
|
||||
interval: 3s
|
||||
timeout: 2s
|
||||
retries: 3
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.50"
|
||||
memory: 128M
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
name: mtusi2026lab5_postgres_data
|
||||
redis_data:
|
||||
name: mtusi2026lab5_redis_data
|
||||
s3_data:
|
||||
name: mtusi2026lab5_s3_data
|
||||
rabbitmq_data:
|
||||
name: mtusi2026lab5_rabbitmq_data
|
||||
Reference in New Issue
Block a user