fix(deploy): 修复生产 CMS 解密失败与媒体库 500

- deploy.sh 构建时从 .env.production 显式注入 NEXT_PUBLIC_ENCRYPTION_SECRET,
  避免 .env.local 开发密钥覆盖生产密钥,导致前端 chunk 与后端 ENCRYPTION_SECRET
  不匹配,CMS 所有列表/仪表盘解密失败(The operation failed for an
  operation-specific reason)
- Dockerfile.prod 新增 sharp-deps 阶段,为 Alpine 容器补充 @img/sharp-linuxmusl-x64
  平台依赖,修复媒体库接口缺失 musl 二进制导致的 500
This commit is contained in:
2026-08-20 12:06:34 +08:00
parent 417463ee9a
commit d4caa7bef3
2 changed files with 31 additions and 0 deletions
+18
View File
@@ -130,6 +130,24 @@ cmd_build() {
log "📋 构建静态站点"
log "=========================================="
cd "$PROJECT_ROOT"
# 生产构建必须注入 .env.production 中的前后端加密密钥。
# Next.js 加载 env 的优先级为 .env.local > .env.production
# 若不显式注入,构建时会使用 .env.local 中的开发密钥,
# 导致前端 chunk 密钥与后端 ENCRYPTION_SECRET 不匹配,
# CMS 所有列表/仪表盘解密失败(The operation failed for an operation-specific reason)。
if [[ -f "$PROJECT_ROOT/.env.production" ]]; then
PROD_ENC_SECRET=$(grep '^NEXT_PUBLIC_ENCRYPTION_SECRET=' "$PROJECT_ROOT/.env.production" | head -1 | cut -d= -f2- | tr -d '"')
if [[ -n "$PROD_ENC_SECRET" ]]; then
export NEXT_PUBLIC_ENCRYPTION_SECRET="$PROD_ENC_SECRET"
log "✅ 已注入生产加密密钥到构建环境"
else
log "⚠️ .env.production 中未找到 NEXT_PUBLIC_ENCRYPTION_SECRET,请检查配置"
fi
else
log "⚠️ 未找到 .env.production,无法注入生产加密密钥"
fi
if [[ "$CLEAN_BUILD" == "1" ]]; then
npm run build:clean
else