Files
wagtailcms/docker-compose.prod.yml
T
Zhengen 19af182314 生产环境部署准备:Docker 化 + 修复存储配置 + SMTP 邮件
- 修复 production.py 存储配置:Django 6.0 已移除 DEFAULT_FILE_STORAGE/
  STATICFILES_STORAGE 旧式设置兼容层,改用 STORAGES 字典(此前的写法
  实际上早已失效,属于遗留 bug)
- 静态文件接入 whitenoise(压缩+哈希文件名+长缓存头),容器化部署下
  无需额外 Nginx/CDN 即可正确提供静态文件
- 新增生产 SMTP 邮件配置(EMAIL_HOST/PORT/USER/PASSWORD/USE_TLS/
  DEFAULT_FROM_EMAIL),修复线索通知邮件/PIPL 删除确认邮件在生产环境
  发不出去的问题
- 新增 docker/Dockerfile(多阶段构建,非 root 用户运行)
- 新增 docker/entrypoint.sh(启动时自动 migrate + collectstatic +
  bootstrap_deployment,均为幂等操作)
- 新增 docker-compose.prod.yml(backend + postgres + redis 编排)
- 新增 .dockerignore
- .env.example 补充 POSTGRES_*/EMAIL_* 环境变量说明
2026-08-18 14:40:19 +08:00

62 lines
1.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 生产/预发环境编排:后端(Django+Wagtail+gunicorn)+ PostgreSQL + Redis。
# 前端 Next.js 是独立的 git 仓库,通常单独部署(Vercel / 自建 Node 容器),不在本 compose 编排范围内。
#
# 使用方式:
# 1. 复制 .env.example 为 .env 并按实际生产环境填写(尤其 SECRET_KEY / 数据库密码 / OSS 密钥等)。
# 2. docker compose -f docker-compose.prod.yml up -d --build
# 3. 首次启动会自动执行 migrate / collectstatic / bootstrap_deployment(见 docker/entrypoint.sh)。
#
# 生产环境建议在本 compose 前面再挂一层反向代理(Nginx/云厂商 SLB/CLB)做 TLS 终止,
# 并将 SECURE_PROXY_SSL_HEADER 对应的转发头传递给 backend 服务。
services:
backend:
build:
context: .
dockerfile: docker/Dockerfile
restart: unless-stopped
env_file:
- .env
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8000:8000"
volumes:
- static_data:/app/staticfiles
- media_data:/app/media
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-enterprise_cms}
POSTGRES_USER: ${POSTGRES_USER:-user}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required, please set it in .env}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-user} -d ${POSTGRES_DB:-enterprise_cms}"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
restart: unless-stopped
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
volumes:
postgres_data:
redis_data:
static_data:
media_data: