Add VPS deployment runbook

This commit is contained in:
Chris
2026-04-03 03:40:10 +08:00
parent c394e9153e
commit a45aa5a6c7
2 changed files with 89 additions and 0 deletions

View File

@@ -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://<user>:<pass>@<host>:<port>/<db>" -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`

View File

@@ -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) 鎖定資料模型與權限模型。