devops: production.env 同步通道修复——render-env 切 ali + 发版漂移告警

2026-07-04 二维码 IP 事故复盘:env 不随发版同步(by design,密钥走
render-env 手动通道),但 render-env 还停在 EC2 时代且割接后没跑过,
线上 env 的 STORAGE_*/CORS 一直是割接临时 IP。三处修复:

- deploy/render-env.sh:目标改 ssh 别名 ali(可 JIU_DEPLOY_SSH 覆盖)、
  SECRET_KEYS 补 PAY_SECRET(旧模板缺此行,直接 deploy 会删掉线上支付
  密钥)、健康检查改 :8081、覆盖前先备份线上 env
- deploy/production.env.template:SERVER_PORT 8080→8081(对齐 ali nginx
  反代口径)、补 PAY_SECRET 占位
- scripts/ci/deploy-server.sh(ali 分支):部署后比对模板与线上 env 的
  非密钥项,漂移只告警不覆盖——手改线上配置不再长期无人发现

线上 env 已手工修正(STORAGE_BASE_URL/STORAGE_PUBLIC_URL/SERVER_CORS_ORIGIN
→ https://jiu.51yanmei.com,退役 LICENSE_* 三行清除,改前有备份)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-04 19:20:53 +08:00
parent cd477ce81a
commit 145bf06ff8
3 changed files with 45 additions and 12 deletions
+30
View File
@@ -89,6 +89,36 @@ nginx -t && systemctl reload nginx
echo "Ali server deploy complete!"
ENDSSH
# --- 配置漂移检查(只告警不覆盖)---
# production.env 不随发版同步(密钥走 deploy/render-env.sh 手动通道);
# 这里比对模板与线上 env 的非密钥项,漂移时在 CI 日志醒目提示,防止
# 「割接手改 env 后长期无人发现」(2026-07-04 二维码 IP 事故复盘)。
TEMPLATE=/tmp/jiu-configs/deploy/production.env.template
if [ -f "$TEMPLATE" ]; then
${SSH} "${TARGET_USER}@${TARGET_HOST}" \
"grep -v '^#' /opt/jiu/config/production.env | grep -v '^$'" \
> /tmp/jiu-env-remote.txt 2>/dev/null || true
DRIFT=0
while IFS= read -r line; do
case "$line" in ''|\#*) continue;; esac
key="${line%%=*}"
case " DATABASE_DSN JWT_SECRET DB_PASSWORD PAY_SECRET " in
*" $key "*) continue;; # 密钥行不比值
esac
remote_line="$(grep "^${key}=" /tmp/jiu-env-remote.txt || true)"
if [ -n "$remote_line" ] && [ "$remote_line" != "$line" ]; then
echo "⚠️ env 漂移: 线上 [$remote_line] ≠ 模板 [$line]"
DRIFT=1
fi
done < "$TEMPLATE"
rm -f /tmp/jiu-env-remote.txt
if [ "$DRIFT" = "1" ]; then
echo "⚠️ production.env 与模板存在非密钥项漂移——确认线上口径后同步模板,或跑 deploy/render-env.sh --deploy 覆盖线上"
else
echo "==> env drift check: 非密钥项与模板一致 ✓"
fi
fi
else
# --- EC2 (live primary) ---
${SSH} "${TARGET_USER}@${TARGET_HOST}" << 'ENDSSH'