Files
photography/backend/configs/docker/docker-compose.prod.yml
xujiang 0ddde92a3c feat: 完成API测试、生产环境配置和文档编写
## 🧪 API测试系统完善
- 创建完整的单元测试套件 (tests/unit_test.go)
  - 认证流程、CRUD操作、文件上传测试
  - 中间件、错误处理、性能测试
- 创建集成测试套件 (tests/integration_test.go)
  - 业务流程、数据一致性、并发测试
- 创建综合API测试 (test_api_comprehensive.http)
  - 92个测试场景,覆盖所有API端点
- 更新Makefile添加测试命令
  - test-unit, test-integration, test-api, test-cover, test-bench

## 🗄️ 生产环境数据库配置
- Docker Compose生产环境配置 (configs/docker/docker-compose.prod.yml)
  - PostgreSQL 16 + Redis 7 + Nginx + 监控栈
- 数据库初始化脚本 (configs/docker/init-db.sql)
  - 完整表结构、索引优化、触发器、视图
- 生产环境配置脚本 (scripts/production-db-setup.sh)
  - 自动化配置、连接池、备份策略、监控

## 📚 API文档完善
- 完整的API文档 (docs/API_DOCUMENTATION.md)
  - 详细接口说明、请求响应示例
  - 认证流程、错误处理、性能优化
  - SDK支持、部署指南、安全考虑
- 包含cURL示例和Postman Collection支持

## 📊 项目进度
- 总进度: 50.0% → 57.5%
- 中优先级任务: 55% → 70%
- 并行完成3个重要任务,显著提升项目完成度

## 🎯 技术成果
- 测试覆盖率大幅提升,支持自动化测试
- 生产环境就绪,支持Docker部署
- 完整的API文档,便于前后端协作
- 性能优化和监控配置,确保生产稳定性
2025-07-11 14:10:43 +08:00

176 lines
4.4 KiB
YAML

version: '3.8'
services:
# PostgreSQL 数据库
postgres:
image: postgres:16-alpine
container_name: photography-postgres
environment:
POSTGRES_DB: photography
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-photography_prod_2024}
POSTGRES_INITDB_ARGS: "--auth-local=md5 --auth-host=md5"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init-db.sql:/docker-entrypoint-initdb.d/init-db.sql:ro
networks:
- photography-network
ports:
- "5432:5432"
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
# Redis 缓存
redis:
image: redis:7-alpine
container_name: photography-redis
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-redis_prod_2024}
volumes:
- redis_data:/data
networks:
- photography-network
ports:
- "6379:6379"
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
memory: 256M
reservations:
memory: 128M
# 后端 API 服务
api:
build:
context: ../..
dockerfile: configs/docker/Dockerfile
target: production
container_name: photography-api
environment:
- ENV=production
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
- DATABASE_NAME=photography
- DATABASE_USER=postgres
- DATABASE_PASSWORD=${POSTGRES_PASSWORD:-photography_prod_2024}
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis_prod_2024}
- JWT_SECRET=${JWT_SECRET:-photography-jwt-secret-prod-2024}
- FILE_UPLOAD_MAX_SIZE=10485760
- CORS_ORIGINS=https://photography.iriver.top,https://admin.photography.iriver.top
volumes:
- upload_data:/app/uploads
- ./logs:/app/logs
networks:
- photography-network
ports:
- "8080:8080"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/api/v1/health"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
# Nginx 反向代理
nginx:
image: nginx:alpine
container_name: photography-nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./ssl:/etc/nginx/ssl:ro
- upload_data:/usr/share/nginx/html/uploads:ro
networks:
- photography-network
ports:
- "80:80"
- "443:443"
depends_on:
- api
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3
# 监控服务 (可选)
prometheus:
image: prom/prometheus:latest
container_name: photography-prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--storage.tsdb.retention.time=200h'
- '--web.enable-lifecycle'
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
networks:
- photography-network
ports:
- "9090:9090"
restart: unless-stopped
# 日志收集 (可选)
grafana:
image: grafana/grafana:latest
container_name: photography-grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin123}
- GF_USERS_ALLOW_SIGN_UP=false
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning:ro
networks:
- photography-network
ports:
- "3000:3000"
depends_on:
- prometheus
restart: unless-stopped
networks:
photography-network:
driver: bridge
volumes:
postgres_data:
driver: local
redis_data:
driver: local
upload_data:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local