anxin-ruoyi/docker/docker-compose.staging.yml
2026-01-08 20:47:24 +08:00

225 lines
6.3 KiB
YAML

# Docker Compose测试环境配置文件
# 若依框架前后端分离Docker部署方案 - 测试环境
# Requirements: 5.3, 6.5
version: '3.8'
services:
# MySQL数据库服务 - 测试环境配置
anxin-mysql:
image: mysql:8.0.36
container_name: anxin-mysql-staging
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-staging_root_password}
MYSQL_DATABASE: ${DB_NAME:-anxin_staging}
MYSQL_USER: ${DB_USER:-anxin_staging}
MYSQL_PASSWORD: ${DB_PASSWORD:-staging_password}
TZ: Asia/Shanghai
ports:
- "${DB_PORT:-3306}:3306"
volumes:
- mysql-data-staging:/var/lib/mysql
- ./database/init:/docker-entrypoint-initdb.d:ro
- ./configs/my.cnf.staging:/etc/mysql/conf.d/my.cnf:ro
- mysql-logs-staging:/var/log/mysql
networks:
- anxin-staging-network
deploy:
resources:
limits:
memory: ${DATABASE_MEMORY_LIMIT:-384M}
cpus: '${DATABASE_CPU_LIMIT:-0.5}'
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-staging_root_password}"]
timeout: 20s
retries: 10
interval: 30s
start_period: 60s
logging:
driver: "json-file"
options:
max-size: "${LOG_MAX_SIZE:-100m}"
max-file: "${LOG_MAX_FILES:-7}"
# Spring Boot后端服务 - 测试环境配置
anxin-backend:
build:
context: ../
dockerfile: docker/backend/Dockerfile
target: production
image: anxin-backend:staging
container_name: anxin-backend-staging
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-staging}
SPRING_DATASOURCE_URL: jdbc:mysql://anxin-mysql:3306/${DB_NAME:-anxin_staging}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
SPRING_DATASOURCE_USERNAME: ${DB_USER:-anxin_staging}
SPRING_DATASOURCE_PASSWORD: ${DB_PASSWORD:-staging_password}
JAVA_OPTS: ${JAVA_OPTS:--Xms512m -Xmx768m -Djava.security.egd=file:/dev/./urandom}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
TZ: Asia/Shanghai
# 测试环境特有配置
SPRING_JPA_SHOW_SQL: true
LOGGING_LEVEL_COM_RUOYI: INFO
MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE: health,info,metrics,prometheus
ports:
- "${BACKEND_PORT:-8080}:8080"
volumes:
- backend-logs-staging:/app/logs
- backend-uploads-staging:/app/uploadPath
- ./configs:/app/config:ro
networks:
- anxin-staging-network
depends_on:
anxin-mysql:
condition: service_healthy
deploy:
resources:
limits:
memory: ${BACKEND_MEMORY_LIMIT:-768M}
cpus: '${BACKEND_CPU_LIMIT:-0.75}'
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8080/actuator/health || exit 1"]
timeout: 30s
retries: 5
interval: 30s
start_period: 90s
logging:
driver: "json-file"
options:
max-size: "${LOG_MAX_SIZE:-100m}"
max-file: "${LOG_MAX_FILES:-7}"
# Vue3前端服务 - 测试环境配置
anxin-frontend:
build:
context: ../
dockerfile: docker/frontend/Dockerfile
target: production
args:
API_BASE_URL: ${API_BASE_URL:-http://staging-api.anxin.com}
NODE_ENV: production
image: anxin-frontend:staging
container_name: anxin-frontend-staging
restart: unless-stopped
environment:
TZ: Asia/Shanghai
NODE_ENV: production
ports:
- "${FRONTEND_PORT:-80}:80"
volumes:
- frontend-logs-staging:/var/log/nginx
- ./configs/nginx.conf.staging:/etc/nginx/conf.d/default.conf:ro
networks:
- anxin-staging-network
depends_on:
anxin-backend:
condition: service_healthy
deploy:
resources:
limits:
memory: ${FRONTEND_MEMORY_LIMIT:-192M}
cpus: '${FRONTEND_CPU_LIMIT:-0.5}'
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost/ || exit 1"]
timeout: 10s
retries: 3
interval: 30s
start_period: 30s
logging:
driver: "json-file"
options:
max-size: "${LOG_MAX_SIZE:-100m}"
max-file: "${LOG_MAX_FILES:-7}"
# 测试环境专用服务 - 数据库备份服务
anxin-db-backup:
image: mysql:8.0.36
container_name: anxin-db-backup-staging
restart: "no"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-staging_root_password}
volumes:
- mysql-data-staging:/var/lib/mysql:ro
- backup-data-staging:/backup
- ./scripts/backup.sh:/backup.sh:ro
networks:
- anxin-staging-network
depends_on:
anxin-mysql:
condition: service_healthy
command: >
sh -c "
echo 'Starting database backup service for staging environment...'
while true; do
sleep 86400
/backup.sh
done
"
deploy:
resources:
limits:
memory: 128M
cpus: '0.1'
# 网络配置 - 测试环境
networks:
anxin-staging-network:
name: ${NETWORK_NAME:-anxin-staging-network}
driver: bridge
ipam:
driver: default
config:
- subnet: ${SUBNET:-172.22.0.0/16}
gateway: ${GATEWAY:-172.22.0.1}
# 卷配置 - 测试环境
volumes:
# 数据库数据持久化卷
mysql-data-staging:
driver: local
driver_opts:
type: none
o: bind
device: ${MYSQL_DATA_PATH:-./data/staging/mysql}
# 数据库日志卷
mysql-logs-staging:
driver: local
driver_opts:
type: none
o: bind
device: ${MYSQL_LOG_PATH:-./data/staging/mysql-logs}
# 后端应用日志卷
backend-logs-staging:
driver: local
driver_opts:
type: none
o: bind
device: ${BACKEND_LOG_PATH:-./data/staging/backend-logs}
# 后端文件上传卷
backend-uploads-staging:
driver: local
driver_opts:
type: none
o: bind
device: ${BACKEND_UPLOAD_PATH:-./data/staging/uploads}
# 前端Nginx日志卷
frontend-logs-staging:
driver: local
driver_opts:
type: none
o: bind
device: ${FRONTEND_LOG_PATH:-./data/staging/nginx-logs}
# 数据库备份卷
backup-data-staging:
driver: local
driver_opts:
type: none
o: bind
device: ${BACKUP_DATA_PATH:-./data/staging/backups}