item-atlas/deploy/public/README.md

54 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 见物公网预览
`api-atlas.tutudog.com` 为 iOS 提供 HTTPS。完整路径为公网 Nginx → 两条 FRP STCP → 工作 Mac 的 SSD VM → Kubernetes Service。`/api/` 到网关,`/auth/realms/item-atlas/` 与 `/auth/resources/` 到 Keycloak。身份服务用 Keycloak 的生产启动模式和固定 issuer。账号由内部后台创建,开放注册关闭。
## 应用和数据
在 `item-atlas-public` 命名空间部署,另有 PostgreSQL 持久卷和私有图片桶。物品、录入和身份服务各用独立数据库。先准备环境私密文件,再应用底座及应用 chart。
```sh
kubectl get namespace item-atlas-public >/dev/null 2>&1 || kubectl create namespace item-atlas-public
python3 deploy/public/prepare-secrets.py "$ATLAS_SECRET_DIR" \
--owner "$ATLAS_INITIAL_ACCOUNT" --ollama-url "$ATLAS_INTERNAL_OLLAMA_URL"
```
把生成的各 `.env` 按文件名创建同名 Kubernetes Secret。用 `item-atlas-realm.json` 创建 `atlas-public-realm`,文件键用 `item-atlas.json`。在 Garage 建立 `jianwu-public-photos`,导入 `atlas-public-media.env` 里的应用密钥,只授予该桶的读取和写入权限。镜像仓库通过 `item-atlas-registry` 提供拉取权限。生成文件、用户口令和服务密钥保存在 SSD 上的受控目录。
这些文件用于初始化。已有环境的 Keycloak realm、账号和数据库密码由运行中的服务维护。备份与恢复时,以当前数据库、图片桶和现用 Secret 为准。
```sh
theme=deploy/public/keycloak/jianwu/login
kubectl -n item-atlas-public create configmap atlas-public-login-theme \
--from-file="$theme/theme.properties" --from-file="$theme/messages/messages_zh_CN.properties" \
--from-file="$theme/messages/messages_en.properties" --from-file="$theme/resources/css/jianwu.css" \
--from-file=brand.png=apps/ios/ItemAtlas/Assets.xcassets/BrandMark.imageset/BrandMark.png \
--dry-run=client -o yaml | kubectl -n item-atlas-public apply --server-side \
--field-manager=item-atlas-login-theme -f -
kubectl -n item-atlas-public apply -f deploy/public/base.yaml
kubectl -n item-atlas-public rollout status deployment/atlas-keycloak --timeout=5m
helm upgrade --install item-atlas deploy/helm/item-atlas -n item-atlas-public \
-f deploy/public/values.yaml --set-string image.tag="$ATLAS_PUBLISHED_SHA" \
--atomic --wait --timeout 12m --history-max 10
```
`ATLAS_PUBLISHED_SHA` 取已成功发布镜像的 Drone 构建标识。公网预览使用同一 Helm chart。初次建立该环境时,运行上述 Helm 命令并验收,再配置公网域名。切换版本前先记录当前修订和三个镜像摘要。
`jianwu` 主题继承 Keycloak 26.8.2 的 `keycloak.v2` 登录表单。首次导入会给 `atlas-ios` 设置 Login theme。已有 realm 在管理端打开 Clients → atlas-ios → Settings → Login theme,选择 `jianwu`。更新主题文件后重启 Keycloak Deployment 以刷新缓存。单副本重启期间登录入口会短暂中断。先检查主题文件和回调,再验收登录。遇到显示问题可把该客户端的 Login theme 恢复为默认。 [Keycloak 主题](https://www.keycloak.org/ui-customization/themes)
## 转发和验收
在集群里用 FRP 客户端直连 `svc/item-atlas-gateway` 和 `svc/atlas-keycloak`。将 `frpc.toml.template` 渲染为受控文件,其中两条 STCP 各用独立密钥。云端 visitor 使用匹配的名称和密钥,只监听 Nginx 容器可达的私有网桥,由 systemd 管理。
```sh
kubectl -n item-atlas-public create secret generic atlas-public-frpc \
--from-file=frpc.toml="$ATLAS_SECRET_DIR/frpc.toml" --dry-run=client -o yaml |
kubectl -n item-atlas-public apply --server-side -f -
kubectl -n item-atlas-public apply -f deploy/public/frpc.yaml
kubectl -n item-atlas-public rollout status deployment/atlas-public-frpc --timeout=2m
kubectl -n item-atlas-public logs deployment/atlas-public-frpc --tail=20
```
日志应显示两个代理注册成功。渲染 `nginx.conf.template`,将两个 `ATLAS_VISITOR_*` 填为实际私有监听地址和端口。用 `nginx -t` 通过后重载。先用 `curl --resolve` 指定目标 IP,核对 TLS、OIDC discovery 和业务 API,再加入公网 A 记录。用公网 DNS 重新测试 iOS 授权码、PKCE 和回调,带令牌查询 `GET /api/households` 应返回 200。另查未登录的 API 及管理路径,预期分别为 401 和 404。 [iOS 验收步骤](../../docs/deployment/identity-and-media.md#ios-公网连通性验收)
工作 Mac 需要挂载 SSD 并运行 Linux VM,集群会启动 FRP 客户端并重连。通常检查顺序是 DNS、TLS、Nginx、STCP、Service 与应用。检查应用版本用 `helm history item-atlas -n item-atlas-public`,回退前先核对数据库迁移兼容性。需要关闭公网预览时停用该域名的独立 Nginx 站点。数据库和私有桶有独立备份流程。