Files
dukang/deploy/bootstrap-staging.sh
T
jacy 6a23e79f4c chore(deploy): add same-host staging stack next to production
dev deploys to /opt/dukang-staging (819x, *-test domains); main deploys to production. Staging uses full Mock with shared WeChat app ids.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-31 11:37:18 +08:00

47 lines
1.9 KiB
Bash
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.
#!/usr/bin/env bash
# 在生产机上初始化 Staging 目录(同机双栈,一次性)
# 用法(SSH 到服务器后):
# APP_ROOT=/opt/dukang bash /opt/dukang/deploy/bootstrap-staging.sh
# 或本机:
# ssh root@host 'bash -s' < deploy/bootstrap-staging.sh
set -euo pipefail
PROD_ROOT="${PROD_ROOT:-/opt/dukang}"
STAGING_ROOT="${STAGING_ROOT:-/opt/dukang-staging}"
GIT_REMOTE_URL="${GIT_REMOTE_URL:-}"
GIT_BRANCH="${GIT_BRANCH:-dev}"
if [[ -d "$STAGING_ROOT/.git" ]]; then
echo "==> 已存在 $STAGING_ROOT,跳过 clone"
else
if [[ -z "$GIT_REMOTE_URL" ]]; then
if [[ -d "$PROD_ROOT/.git" ]]; then
GIT_REMOTE_URL="$(git -C "$PROD_ROOT" remote get-url origin)"
else
echo "错误: 请设置 GIT_REMOTE_URL,或确保 $PROD_ROOT 为 git 仓库" >&2
exit 1
fi
fi
echo "==> clone $GIT_REMOTE_URL$STAGING_ROOT (branch $GIT_BRANCH)"
git clone --branch "$GIT_BRANCH" "$GIT_REMOTE_URL" "$STAGING_ROOT"
fi
mkdir -p "$STAGING_ROOT/server/dukang-api"
if [[ ! -f "$STAGING_ROOT/server/dukang-api/.env.staging" ]]; then
if [[ -f "$STAGING_ROOT/server/dukang-api/.env.staging.example" ]]; then
cp "$STAGING_ROOT/server/dukang-api/.env.staging.example" \
"$STAGING_ROOT/server/dukang-api/.env.staging"
echo "==> 已生成 .env.staging(请编辑 DATABASE_URL / Redis / 微信后 sync 或本机改)"
else
echo "WARN: 无 .env.staging.example,请手动创建 .env.staging"
fi
fi
echo "==> 下一步:"
echo " 1. 创建 RDS 库 dukang_staging,填好 $STAGING_ROOT/server/dukang-api/.env.staging"
echo " 2. DNS: api-test/user-test/shop-test/partner-test/admin-test.dukanghaoke.com → 本机"
echo " 3. 启用 nginx: ln -sf $STAGING_ROOT/deploy/nginx-dukang-staging.conf /etc/nginx/sites-enabled/"
echo " nginx -t && systemctl reload nginx(证书需含 *-test SAN"
echo " 4. 本机发版: bash deploy/deploy-staging.sh -- --seed --accept-data-loss"
echo "==> bootstrap 完成"