76 lines
1.8 KiB
YAML
76 lines
1.8 KiB
YAML
|
|
version: '3.8'
|
|||
|
|
|
|||
|
|
services:
|
|||
|
|
# MySQL数据库
|
|||
|
|
mysql:
|
|||
|
|
image: mysql:8.0
|
|||
|
|
container_name: gamegroup-mysql-prod
|
|||
|
|
environment:
|
|||
|
|
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
|
|||
|
|
MYSQL_DATABASE: ${DB_DATABASE}
|
|||
|
|
MYSQL_USER: ${DB_USERNAME}
|
|||
|
|
MYSQL_PASSWORD: ${DB_PASSWORD}
|
|||
|
|
volumes:
|
|||
|
|
- mysql-data:/var/lib/mysql
|
|||
|
|
- ./backups:/backups
|
|||
|
|
networks:
|
|||
|
|
- gamegroup-network
|
|||
|
|
restart: unless-stopped
|
|||
|
|
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max-connections=200
|
|||
|
|
|
|||
|
|
# 后端应用
|
|||
|
|
backend:
|
|||
|
|
build:
|
|||
|
|
context: .
|
|||
|
|
dockerfile: Dockerfile
|
|||
|
|
target: production
|
|||
|
|
container_name: gamegroup-backend-prod
|
|||
|
|
environment:
|
|||
|
|
NODE_ENV: production
|
|||
|
|
DB_HOST: mysql
|
|||
|
|
DB_PORT: 3306
|
|||
|
|
DB_USERNAME: ${DB_USERNAME}
|
|||
|
|
DB_PASSWORD: ${DB_PASSWORD}
|
|||
|
|
DB_DATABASE: ${DB_DATABASE}
|
|||
|
|
DB_SYNCHRONIZE: "false"
|
|||
|
|
DB_LOGGING: "false"
|
|||
|
|
JWT_SECRET: ${JWT_SECRET}
|
|||
|
|
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN}
|
|||
|
|
CORS_ORIGIN: ${CORS_ORIGIN}
|
|||
|
|
ports:
|
|||
|
|
- "3000:3000"
|
|||
|
|
depends_on:
|
|||
|
|
- mysql
|
|||
|
|
networks:
|
|||
|
|
- gamegroup-network
|
|||
|
|
restart: unless-stopped
|
|||
|
|
healthcheck:
|
|||
|
|
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
|
|||
|
|
interval: 30s
|
|||
|
|
timeout: 10s
|
|||
|
|
retries: 3
|
|||
|
|
start_period: 40s
|
|||
|
|
|
|||
|
|
# Nginx反向代理(可选)
|
|||
|
|
nginx:
|
|||
|
|
image: nginx:alpine
|
|||
|
|
container_name: gamegroup-nginx
|
|||
|
|
ports:
|
|||
|
|
- "80:80"
|
|||
|
|
- "443:443"
|
|||
|
|
volumes:
|
|||
|
|
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
|||
|
|
- ./ssl:/etc/nginx/ssl:ro
|
|||
|
|
depends_on:
|
|||
|
|
- backend
|
|||
|
|
networks:
|
|||
|
|
- gamegroup-network
|
|||
|
|
restart: unless-stopped
|
|||
|
|
|
|||
|
|
volumes:
|
|||
|
|
mysql-data:
|
|||
|
|
|
|||
|
|
networks:
|
|||
|
|
gamegroup-network:
|
|||
|
|
driver: bridge
|