2026-07-06 06:13:14 +00:00
|
|
|
|
# Haixun Docker Deploy
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
Production uses two compose stacks:
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
- `infra/`: Mongo + Redis + persistent volumes.
|
|
|
|
|
|
- `deploy/`: nginx static frontend, API gateway, independent workers, and one-shot init.
|
|
|
|
|
|
|
|
|
|
|
|
## Build Images
|
|
|
|
|
|
|
|
|
|
|
|
Build and push images outside the runtime host, then deploy by changing tags in `deploy/.env.prod`.
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
docker build -f backend/Dockerfile -t ghcr.io/kupi-cat/haixun-backend:v0.0.1 .
|
|
|
|
|
|
docker build -f backend/web/Dockerfile -t ghcr.io/kupi-cat/haixun-web:v0.0.1 .
|
|
|
|
|
|
docker build -f backend/worker/Dockerfile -t ghcr.io/kupi-cat/haixun-node-worker:v0.0.1 .
|
|
|
|
|
|
|
|
|
|
|
|
docker push ghcr.io/kupi-cat/haixun-backend:v0.0.1
|
|
|
|
|
|
docker push ghcr.io/kupi-cat/haixun-web:v0.0.1
|
|
|
|
|
|
docker push ghcr.io/kupi-cat/haixun-node-worker:v0.0.1
|
2026-06-28 10:08:43 +00:00
|
|
|
|
```
|
2026-07-06 06:13:14 +00:00
|
|
|
|
|
|
|
|
|
|
## Env files (single source of truth)
|
|
|
|
|
|
|
|
|
|
|
|
| File | 用途 | 誰讀 |
|
|
|
|
|
|
|------|------|------|
|
|
|
|
|
|
| `deploy/.env.dev` | 本機 dev 全部 env | `make dev-all`、`make dev-infra`、`make run`、`infra/start-*.sh` |
|
|
|
|
|
|
| `deploy/.env.prod` | 正式環境全部 env | `make prod-*` 的 infra / app compose |
|
|
|
|
|
|
|
|
|
|
|
|
兩份都從對應 `.example` 複製而來,實值不進 repo。
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
cp deploy/.env.dev.example deploy/.env.dev # dev
|
|
|
|
|
|
cp deploy/.env.prod.example deploy/.env.prod # prod
|
2026-06-28 10:08:43 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
infra compose 的 Mongo / Redis 容器密碼(`MONGO_ROOT_PASSWORD` / `REDIS_PASSWORD`)必須與 app 用的 `HAIXUN_MONGO_URI`(URL-encoded)/ `HAIXUN_REDIS_PASSWORD` 一致,不能各自獨立。
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
## Start Infra + App(one-shot)
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-07-06 06:13:14 +00:00
|
|
|
|
make prod-install
|
|
|
|
|
|
# = 啟動 infra compose(讀 deploy/.env.prod)
|
|
|
|
|
|
# + pull app image + up -d
|
|
|
|
|
|
# + 跑 init(索引 / permission / role / job template / 第一個 admin)
|
2026-06-28 10:08:43 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
## Init Database(單獨跑)
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
idempotent,部署新版本若有 schema/template 變更可重跑:
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-07-06 06:13:14 +00:00
|
|
|
|
make prod-rebuild # 或單獨 init:
|
|
|
|
|
|
docker compose --env-file deploy/.env.prod -f deploy/docker-compose.yml --profile init run --rm init
|
2026-06-28 10:08:43 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
## Start / Upgrade
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-07-06 06:13:14 +00:00
|
|
|
|
make prod-install # 首次
|
|
|
|
|
|
make prod-rebuild # 改 tag 後升版
|
2026-06-28 10:08:43 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
Upgrade by changing `BACKEND_TAG`, `WEB_TAG`, and `NODE_WORKER_TAG` in `deploy/.env.prod`, then run `make prod-rebuild`.
|
|
|
|
|
|
|
|
|
|
|
|
## Rollback
|
|
|
|
|
|
|
|
|
|
|
|
Change the tags back to the previous version in `deploy/.env.prod` and run `make prod-rebuild`.
|
|
|
|
|
|
|
|
|
|
|
|
## Stop
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-07-06 06:13:14 +00:00
|
|
|
|
make prod-stop # 關 app stack,保留 infra 與資料
|
|
|
|
|
|
make prod-stop-all # 關 app + infra,保留資料 volume
|
2026-06-28 10:08:43 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
## Public Entry
|
2026-06-28 10:08:43 +00:00
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
|
Only `web` publishes port `80`. nginx serves static files and proxies `/api/` to `gateway:8890` with SSE buffering disabled.
|