跳到主要内容

AOVIS 部署归档:AWS 生产内容同步到 GCP 冷备测试环境

归档日期:2026-05-04 状态:已同步、已验证、GCP VM 已停机 范围:将 AWS 生产端已经部署的 Git 内容同步到 GCP 冷备/测试环境,避免环境漂移

1. 归档目的

这份记录保存本次跨云同步的执行证据。

本次工作的目标是:

  • 以 AWS 生产端当前 Git commit 作为唯一代码基准
  • 唤醒 GCP 冷备/测试 VM
  • 在 GCP app VM 上从远端 Git 快进到同一 commit
  • 完成安装、Prisma generate、生产构建和 PM2 重启
  • 验证 GCP app 服务可用并与 AWS 生产 commit 一致
  • 验证完成后停机 GCP app/db VM,降低 VM 使用费用

2. 环境身份

  • 仓库:aovis-direct-store
  • 分支:main
  • 远程:origin/main
  • AWS 生产主机:52.87.46.166
  • AWS 生产路径:/opt/aovis/aovis-store-staging
  • AWS PM2 进程:aovis-store-aws
  • GCP 项目:aovis-direct-store-492514
  • GCP zone:us-west1-c
  • GCP app VM:aovis-store-staging-vm
  • GCP db VM:aovis-db-staging-vm
  • GCP app 路径:/opt/aovis/aovis-store-staging
  • GCP PM2 进程:aovis-store-staging

3. 同步身份

  • AWS 生产 commit:b62238082cf3da4c1067dcfe8856c302e45e533e
  • GCP 同步前 commit:7dddb1ccc7319d92d668c0a222bf639842518672
  • GCP 同步后 commit:b62238082cf3da4c1067dcfe8856c302e45e533e
  • 同步方式:GCP VM 内部 git fetch + git pull --ff-only origin main
  • 本地未提交脏文件:未参与同步
  • VM 环境文件:未覆盖 .env.production

4. 同步的 Git 文件范围

GCP 从 7dddb1c 快进到 b622380 时包含以下已提交文件:

  • PROGRESS.md
  • app/account/devices/page.tsx
  • app/account/loading.tsx
  • app/account/orders/[id]/loading.tsx
  • app/account/orders/[id]/page.tsx
  • app/account/orders/loading.tsx
  • app/account/orders/page.tsx
  • app/account/page.tsx
  • app/account/profile/page.tsx
  • app/account/services/page.tsx
  • app/admin/layout.tsx
  • app/globals.css
  • components/account-layout-shell.tsx
  • components/account-order-list.tsx
  • components/account-profile-center.tsx
  • components/account-ui.tsx
  • components/admin-language-switcher.tsx
  • components/admin-nav.tsx
  • components/admin-shell.tsx
  • components/admin-table-row.tsx
  • components/admin-ui.tsx
  • docs/current-store-development-status.md
  • docs/deploy-sop.md
  • lib/auth-config.ts

说明:

  • 这些内容已经先在 AWS 生产端完成部署与验证
  • 本次 GCP 工作只是同步既有生产 commit,不从本地脏工作区发布
  • GCP 工作区同步后无 tracked 脏改
  • GCP 工作区保留未跟踪运行时文件:.env.production.env.production.bak-auth-security-20260428025438

5. 执行步骤

确认 GCP 账号:

gcloud auth list --filter=status:ACTIVE --format='value(account)'

结果:

确认 GCP VM 初始状态:

  • aovis-store-staging-vmTERMINATED
  • aovis-db-staging-vmTERMINATED

启动 GCP VM:

gcloud compute instances start aovis-db-staging-vm aovis-store-staging-vm --zone us-west1-c --project aovis-direct-store-492514

启动结果:

  • app internal IP:10.138.0.4
  • db internal IP:10.138.0.3
  • app 临时 external IP:34.177.118.243

部署命令:

gcloud compute ssh aovis-store-staging-vm --zone us-west1-c --project aovis-direct-store-492514 --command 'set -euo pipefail; cd /opt/aovis/aovis-store-staging; echo BEFORE=$(git rev-parse HEAD); git fetch origin; git pull --ff-only origin main; echo AFTER=$(git rev-parse HEAD); npm install; npx prisma generate; npm run build; pm2 restart aovis-store-staging --update-env; pm2 status aovis-store-staging'

部署结果:

  • git pull --ff-only origin main 成功
  • npm install 成功
  • npx prisma generate 成功
  • npm run build 成功
  • pm2 restart aovis-store-staging --update-env 成功
  • PM2 aovis-store-staging 状态:online

6. 验证结果

AWS 与 GCP commit 对齐:

  • AWS:b62238082cf3da4c1067dcfe8856c302e45e533e
  • GCP:b62238082cf3da4c1067dcfe8856c302e45e533e

GCP app VM 本机服务验证:

  • http://127.0.0.1:3000/ 返回 200
  • http://127.0.0.1:3000/account 返回 307,跳转 /login?callbackUrl=%2Faccount
  • http://127.0.0.1:3000/admin-signin 返回 200

GCP 外部 IP 验证:

  • http://34.177.118.243 返回 301
  • Location: https://aovis.app/

说明:

  • GCP 本机 Next.js 服务已验证可用
  • 外部 IP 的 Caddy 入口仍重定向到生产域名,这是现有冷备入口配置表现
  • 本次同步成功标准以 Git commit 一致性、GCP VM 本机服务响应、构建和 PM2 状态为准

7. 停机结果

验证完成后执行:

gcloud compute instances stop aovis-db-staging-vm aovis-store-staging-vm --zone us-west1-c --project aovis-direct-store-492514

最终状态:

  • aovis-store-staging-vmTERMINATED
  • aovis-store-staging-vm stop time:2026-05-03T23:35:12.231-07:00
  • aovis-db-staging-vmTERMINATED
  • aovis-db-staging-vm stop time:2026-05-03T23:36:36.344-07:00

8. 结论

  • GCP 冷备/测试环境已同步到 AWS 生产同一 Git commit
  • GCP app 构建和 PM2 重启成功
  • GCP 本机 HTTP 验证通过
  • GCP app/db VM 已停机以降低费用
  • 本次没有覆盖 VM 受保护运行时环境文件
  • 本次没有从本地未提交脏文件发布任何内容