110 lines
2.0 KiB
Markdown
110 lines
2.0 KiB
Markdown
# 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 .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
|
||
```
|
||
|
||
### 用 docker compose(建議)
|
||
Compose 檔案:[docker-compose.example.yml](../docker-compose.example.yml)
|
||
|
||
啟動:
|
||
```bash
|
||
cd /opt/member-platform
|
||
cp docker-compose.example.yml docker-compose.yml
|
||
|
||
docker compose up -d --build
|
||
```
|
||
|
||
檢查:
|
||
```bash
|
||
docker compose ps
|
||
docker compose logs -f backend
|
||
```
|
||
|
||
停止:
|
||
```bash
|
||
docker compose down
|
||
```
|
||
|
||
## 3) 前端部署(Nginx)
|
||
```bash
|
||
cd /opt/member-platform/frontend
|
||
```
|
||
production build 會自動讀取 `.env.production`,請先確認設定:
|
||
```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`)
|