Enhance Docker deployment: structured logging, health checks, resource limits, entrypoint script
- Add structured logging config with JSON/text format support - Create docker-entrypoint.sh with dependency health checks - Enhance /health endpoint with DB and Redis connectivity checks - Add resource limits (CPU/memory) for all services - Add network aliases for service discovery - Add container hostnames for better identification - Reduce health check timeout from 20s to 5s - Add build metadata labels to Dockerfile - Use ENTRYPOINT for dependency checking before app startup - Log rotation: 50m per file, 5 files max
This commit is contained in:
+104
-17
@@ -3,6 +3,8 @@ services:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: mtgonline_backend
|
||||
hostname: mtgonline_backend
|
||||
ports:
|
||||
- "8990:8000"
|
||||
environment:
|
||||
@@ -16,7 +18,7 @@ services:
|
||||
- MTG_INTERACTION_BATCH_SIZE=1000
|
||||
- MTG_INTERACTION_REVIEW_QUEUE=true
|
||||
- MTG_LOG_LEVEL=INFO
|
||||
- MTG_LOG_FORMAT=json
|
||||
- MTG_LOG_FORMAT=text
|
||||
- REDIS_URL=redis://redis:6379/0
|
||||
- SECRET_KEY=change-this-secret-key-in-production
|
||||
- JWT_SECRET_KEY=change-this-jwt-secret-key-in-production
|
||||
@@ -38,42 +40,72 @@ services:
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
||||
interval: 30s
|
||||
timeout: 20s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
max-size: "50m"
|
||||
max-file: "5"
|
||||
tag: "{{.Name}}"
|
||||
networks:
|
||||
- mtgonline_network
|
||||
mtgonline_network:
|
||||
aliases:
|
||||
- backend
|
||||
- mtgonline-api
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 1G
|
||||
cpus: "1.0"
|
||||
reservations:
|
||||
memory: 512M
|
||||
cpus: "0.5"
|
||||
|
||||
postgres_platform:
|
||||
image: postgres:16-alpine
|
||||
container_name: mtgonline_postgres_platform
|
||||
hostname: postgres_platform
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
- POSTGRES_DB=mtgo_platform
|
||||
volumes:
|
||||
- postgres_platform_data:/var/lib/postgresql/data
|
||||
- ./scripts/init_platform.sql:/docker-entrypoint-initdb.d/01-init.sql
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres -d mtgo_platform"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 10s
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
max-size: "50m"
|
||||
max-file: "5"
|
||||
tag: "{{.Name}}"
|
||||
networks:
|
||||
- mtgonline_network
|
||||
mtgonline_network:
|
||||
aliases:
|
||||
- postgres-platform
|
||||
- platform-db
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
cpus: "0.5"
|
||||
reservations:
|
||||
memory: 256M
|
||||
cpus: "0.25"
|
||||
|
||||
postgres_mtgdata:
|
||||
image: postgres:16-alpine
|
||||
container_name: mtgonline_postgres_mtgdata
|
||||
hostname: postgres_mtgdata
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
@@ -85,17 +117,32 @@ services:
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 10s
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
max-size: "50m"
|
||||
max-file: "5"
|
||||
tag: "{{.Name}}"
|
||||
networks:
|
||||
- mtgonline_network
|
||||
mtgonline_network:
|
||||
aliases:
|
||||
- postgres-mtgdata
|
||||
- mtgdata-db
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
cpus: "0.5"
|
||||
reservations:
|
||||
memory: 256M
|
||||
cpus: "0.25"
|
||||
|
||||
postgres_mirror:
|
||||
image: postgres:16-alpine
|
||||
container_name: mtgonline_postgres_mirror
|
||||
hostname: postgres_mirror
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
@@ -107,39 +154,79 @@ services:
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 10s
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
max-size: "50m"
|
||||
max-file: "5"
|
||||
tag: "{{.Name}}"
|
||||
networks:
|
||||
- mtgonline_network
|
||||
mtgonline_network:
|
||||
aliases:
|
||||
- postgres-mirror
|
||||
- mirror-db
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
cpus: "0.5"
|
||||
reservations:
|
||||
memory: 256M
|
||||
cpus: "0.25"
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: mtgonline_redis
|
||||
hostname: redis
|
||||
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 5s
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
max-size: "50m"
|
||||
max-file: "5"
|
||||
tag: "{{.Name}}"
|
||||
networks:
|
||||
- mtgonline_network
|
||||
mtgonline_network:
|
||||
aliases:
|
||||
- redis
|
||||
- cache
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
cpus: "0.5"
|
||||
reservations:
|
||||
memory: 256M
|
||||
cpus: "0.25"
|
||||
|
||||
volumes:
|
||||
postgres_platform_data:
|
||||
driver: local
|
||||
postgres_mtgdata_data:
|
||||
driver: local
|
||||
postgres_mirror_data:
|
||||
driver: local
|
||||
mtg_data:
|
||||
driver: local
|
||||
mtg_uploads:
|
||||
driver: local
|
||||
mtg_logs:
|
||||
driver: local
|
||||
redis_data:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
mtgonline_network:
|
||||
driver: bridge
|
||||
name: mtgonline_network
|
||||
|
||||
Reference in New Issue
Block a user