feat: 添加安全检查和部署优化
- 添加 JWT_SECRET 和 ADMIN_RESET_PASSWORD_KEY 安全检查,防止使用默认值 - 创建 docker-compose.prod.yml 和 docker-compose.prod.env.example,支持独立部署 - 添加 Nginx 反向代理配置示例,支持 HTTPS 和域名绑定 - 更新部署文档,将 Docker Hub 部署方式放在首位 - 添加多架构构建支持(amd64、arm64) - 优化部署文档结构,提供更清晰的部署指南
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
version: '3.8'
|
||||
|
||||
# PolyHermes 生产环境部署配置
|
||||
# 使用 Docker Hub 官方镜像,无需本地构建
|
||||
#
|
||||
# 使用方法:
|
||||
# 1. 创建 .env 文件(参考下方配置)
|
||||
# 2. 运行: docker-compose -f docker-compose.prod.yml up -d
|
||||
#
|
||||
# 注意:
|
||||
# - JWT_SECRET 和 ADMIN_RESET_PASSWORD_KEY 不能使用默认值
|
||||
# - 请使用 openssl rand -hex 生成安全的随机密钥
|
||||
|
||||
services:
|
||||
app:
|
||||
# 使用 Docker Hub 官方镜像
|
||||
image: wrbug/polyhermes:latest
|
||||
container_name: polyhermes
|
||||
ports:
|
||||
- "${SERVER_PORT:-80}:80"
|
||||
environment:
|
||||
- SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-prod}
|
||||
- DB_URL=${DB_URL:-jdbc:mysql://mysql:3306/polyhermes?useSSL=false&serverTimezone=UTC&characterEncoding=utf8&allowPublicKeyRetrieval=true}
|
||||
- DB_USERNAME=${DB_USERNAME:-root}
|
||||
- DB_PASSWORD=${DB_PASSWORD:-}
|
||||
- SERVER_PORT=8000
|
||||
- POLYGON_RPC_URL=${POLYGON_RPC_URL:-https://polygon-rpc.com}
|
||||
# ⚠️ 安全警告:以下两个环境变量不能使用默认值,否则容器启动会失败
|
||||
# 请在 .env 文件中设置,或通过环境变量传入
|
||||
# 生成随机密钥:openssl rand -hex 32 (ADMIN_RESET_PASSWORD_KEY) 或 openssl rand -hex 64 (JWT_SECRET)
|
||||
- JWT_SECRET=${JWT_SECRET:-change-me-in-production}
|
||||
- ADMIN_RESET_PASSWORD_KEY=${ADMIN_RESET_PASSWORD_KEY:-change-me-in-production}
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- polyhermes-network
|
||||
|
||||
mysql:
|
||||
image: mysql:8.2
|
||||
container_name: polyhermes-mysql
|
||||
ports:
|
||||
- "${MYSQL_PORT:-3307}:3306"
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD:-rootpassword}
|
||||
- MYSQL_DATABASE=polyhermes
|
||||
- MYSQL_CHARACTER_SET_SERVER=utf8mb4
|
||||
- MYSQL_COLLATION_SERVER=utf8mb4_unicode_ci
|
||||
volumes:
|
||||
- mysql-data:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_PASSWORD:-rootpassword}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- polyhermes-network
|
||||
|
||||
volumes:
|
||||
mysql-data:
|
||||
|
||||
networks:
|
||||
polyhermes-network:
|
||||
driver: bridge
|
||||
|
||||
Reference in New Issue
Block a user