diff --git a/docs/VPS_DEPLOY_RUNBOOK.md b/docs/VPS_DEPLOY_RUNBOOK.md new file mode 100644 index 0000000..14a4ee9 --- /dev/null +++ b/docs/VPS_DEPLOY_RUNBOOK.md @@ -0,0 +1,88 @@ +# VPS Deploy Runbook + +## 1) 拉整合層 + 子模組 +```bash +cd /opt +git clone --recurse-submodules http://127.0.0.1:8888/member/member-platform.git +cd member-platform +git submodule update --init --recursive +``` + +## 2) 後端部署(Docker) +```bash +cd /opt/member-platform/backend +cp .env.production.example .env +``` +編輯 `.env`(DB、Keycloak、Realm Roles、Cache)。 + +首次建表: +```bash +psql "postgresql://:@:/" -f scripts/init_schema.sql +``` + +啟動: +```bash +docker build -t memberapi-backend:latest . +docker rm -f memberapi-backend 2>/dev/null || true +docker run -d \ + --name memberapi-backend \ + --restart unless-stopped \ + -p 127.0.0.1:8000:8000 \ + --env-file .env \ + memberapi-backend:latest +``` + +檢查: +```bash +curl http://127.0.0.1:8000/healthz +docker logs -f memberapi-backend +``` + +## 3) 前端部署(Nginx) +```bash +cd /opt/member-platform/frontend +cp .env.example .env +``` +設定: +```env +VITE_API_BASE_URL=https://memberapi.ose.tw +``` + +Build: +```bash +npm ci +npm run build +``` + +Nginx root 指向 `frontend/dist`,並加 SPA rewrite: +```nginx +location / { + try_files $uri $uri/ /index.html; +} +``` + +## 4) 更新流程 +```bash +cd /opt/member-platform +git pull +git submodule update --init --recursive --remote +``` + +後端更新: +```bash +cd backend +docker build -t memberapi-backend:latest . +docker rm -f memberapi-backend +docker run -d --name memberapi-backend --restart unless-stopped -p 127.0.0.1:8000:8000 --env-file .env memberapi-backend:latest +``` + +前端更新: +```bash +cd ../frontend +npm ci +npm run build +``` + +## 5) 建議網域 +- Frontend: `member.ose.tw` +- API: `memberapi.ose.tw`(反代 `127.0.0.1:8000`) diff --git a/docs/index.md b/docs/index.md index 6025921..2853f85 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,6 +8,7 @@ 5. [docs/FRONTEND_HANDOFF.md](./FRONTEND_HANDOFF.md) 6. [docs/INTERNAL_API_HANDOFF.md](./INTERNAL_API_HANDOFF.md) 7. [docs/LOCAL_DEV_RUNBOOK.md](./LOCAL_DEV_RUNBOOK.md) +8. [docs/VPS_DEPLOY_RUNBOOK.md](./VPS_DEPLOY_RUNBOOK.md) ## 交辦順序(建議) 1. 先看 [ARCHITECTURE.md](./ARCHITECTURE.md) 鎖定資料模型與權限模型。