feat(0.2.1): M4-a 部署栈 —— compose(PG逻辑复制+powersync+app:13001), sync streams(任务域6表+User), initdb, DISABLE_CRON 开关, 健康检查端口跟随 PORT

This commit is contained in:
jif2.zhang
2026-10-25 23:57:51 +08:00
parent a4ab22588c
commit 034c87f955
10 changed files with 233 additions and 6 deletions
+58
View File
@@ -0,0 +1,58 @@
# 0.2.1 独立验证部署 (baihu /app/iboard-0.2.1)
与现网 `/app/iboard`(3001/宿主 MySQL) 完全隔离:本栈使用独立 PG 容器、端口 13001/13002,不写原库。
## 栈
| 服务 | 说明 |
| --- | --- |
| `pg` | postgres:16-alpine,`wal_level=logical`(供 PowerSync 逻辑复制),数据在 `./data/pg`,**不对外暴露端口** |
| `app` | 本仓库 Dockerfile 构建,13001 对外;启动时先 `prisma migrate deploy`;`DISABLE_CRON=1` 关闭定时任务 |
| `powersync` | journeyapps/powersync-service,13002 对外;源库=pg,bucket storage=同实例 PG 的 powersync schema |
## 首次部署
```bash
# 服务器上 (源码已上传到 /app/iboard-0.2.1)
cd /app/iboard-0.2.1/deploy/0.2.1
# 1. 生成 .env (参照 .env.example; POWERSYNC_JWT_KEY_B64 由 secret 派生)
umask 077
PG_PASSWORD=$(openssl rand -hex 16)
PS_STORAGE_PASSWORD=$(openssl rand -hex 16)
JWT_SECRET_021=$(openssl rand -hex 32)
POWERSYNC_JWT_SECRET=$(openssl rand -hex 32)
POWERSYNC_JWT_KEY_B64=$(printf %s "$POWERSYNC_JWT_SECRET" | openssl base64 -A | tr '+/' '-_' | tr -d '=')
cat > .env <<EOF
PG_PASSWORD=$PG_PASSWORD
PS_STORAGE_PASSWORD=$PS_STORAGE_PASSWORD
JWT_SECRET_021=$JWT_SECRET_021
POWERSYNC_JWT_SECRET=$POWERSYNC_JWT_SECRET
POWERSYNC_JWT_KEY_B64=$POWERSYNC_JWT_KEY_B64
POWERSYNC_URL=http://bh.vps.honor3.com:13002
OTA_PUBLIC_BASE=http://bh.vps.honor3.com:13001
EOF
# 2. 构建并启动
docker compose build app
docker compose up -d
# 3. 验证
docker compose ps
curl -s http://127.0.0.1:13001/api/health
docker compose logs powersync --tail 50 # 应看到连接源库/建 publication/sync config 部署成功
```
## 日常更新
```bash
cd /app/iboard-0.2.1
git archive 方式重新上传源码 tar 后解包覆盖 (data/.env 不受影响)
cd deploy/0.2.1 && docker compose build app && docker compose up -d app
```
## 注意
- `./data/pg` 为 0.2.1 独立数据卷;`./.env` 为密钥,两者均已 gitignore,更新源码时不会覆盖 `.env`(tar 解包不产生它)。
- PowerSync 的 publication / replication slot 由 service 自动管理(账号 iboard021 为容器内 superuser)。
- 同步规则改动:编辑 `powersync/sync-config.yaml` 后 `docker compose restart powersync`。