diff --git a/apps/pc/README.md b/apps/pc/README.md index 4833450..770c56d 100644 --- a/apps/pc/README.md +++ b/apps/pc/README.md @@ -2,6 +2,8 @@ Vue 3、TypeScript、Vue Router 和 Vite。网页使用同源 `/api` 接现有网关,账号、物品和布局与 iOS 共享。 +公网地址为 [pc-atlas.tutudog.com](https://pc-atlas.tutudog.com)。 + ## 本地运行 使用 Node.js 24。在仓库根目录执行: @@ -20,6 +22,6 @@ npm --prefix apps/pc run build docker build -t item-atlas-pc:0.1.0 apps/pc ``` -镜像监听 8080。容器内 `ATLAS_GATEWAY_URL` 指向可达的网关;同一 Kubernetes 命名空间默认用 `http://item-atlas-gateway:8080`。就绪检查用 `/healthz`,Nginx 负责 SPA 路由和同源 API 转发。外部站点通过 HTTPS 接入。Drone 在现有流水线运行 `build-pc` 构建检查。 +镜像监听 8080,就绪检查用 `/healthz`。容器内 `ATLAS_GATEWAY_URL` 默认指向同命名空间的 `http://item-atlas-gateway:8080`。公网云机将页面请求转发到 PC 容器,并将同源 API 请求直接转发到网关通道。Drone 在现有流水线运行 `build-pc` 构建检查。 -[产品交互](../../docs/ui/pc-workbench.md) · [域名与部署](../../docs/deployment/overview.md) +[产品交互](../../docs/ui/pc-workbench.md) · [公网部署](../../deploy/public/README.md#pc-工作台) diff --git a/deploy/helm/item-atlas-pc/Chart.yaml b/deploy/helm/item-atlas-pc/Chart.yaml new file mode 100644 index 0000000..8afe1f4 --- /dev/null +++ b/deploy/helm/item-atlas-pc/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: item-atlas-pc +description: Item Atlas desktop web client +type: application +version: 0.1.0 +appVersion: "0.1.0" diff --git a/deploy/helm/item-atlas-pc/templates/frpc.yaml b/deploy/helm/item-atlas-pc/templates/frpc.yaml new file mode 100644 index 0000000..44e2d54 --- /dev/null +++ b/deploy/helm/item-atlas-pc/templates/frpc.yaml @@ -0,0 +1,36 @@ +{{- if .Values.frp.enabled }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-frpc +spec: + replicas: 1 + strategy: {type: Recreate} + selector: + matchLabels: {app.kubernetes.io/instance: {{ .Release.Name }}, app.kubernetes.io/component: frpc} + template: + metadata: + labels: {app.kubernetes.io/instance: {{ .Release.Name }}, app.kubernetes.io/component: frpc} + spec: + automountServiceAccountToken: false + securityContext: + runAsNonRoot: true + runAsUser: 65532 + seccompProfile: {type: RuntimeDefault} + containers: + - name: frpc + image: ghcr.io/fatedier/frpc:v0.69.1@sha256:5a1b2cbcec588f1def1de6c5bc372e5f6783f78a151aecb4aae99fcebb9b573a + args: [-c, /etc/frp/frpc.toml] + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: {drop: [ALL]} + resources: + requests: {cpu: 10m, memory: 16Mi} + limits: {cpu: 200m, memory: 64Mi} + volumeMounts: + - {name: config, mountPath: /etc/frp, readOnly: true} + volumes: + - name: config + secret: {secretName: {{ .Values.frp.secretName | quote }}} +{{- end }} diff --git a/deploy/helm/item-atlas-pc/templates/web.yaml b/deploy/helm/item-atlas-pc/templates/web.yaml new file mode 100644 index 0000000..e991e87 --- /dev/null +++ b/deploy/helm/item-atlas-pc/templates/web.yaml @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} +spec: + replicas: 1 + strategy: + type: RollingUpdate + rollingUpdate: {maxSurge: 1, maxUnavailable: 0} + selector: + matchLabels: {app.kubernetes.io/instance: {{ .Release.Name }}, app.kubernetes.io/component: web} + template: + metadata: + labels: {app.kubernetes.io/instance: {{ .Release.Name }}, app.kubernetes.io/component: web} + spec: + automountServiceAccountToken: false + securityContext: + seccompProfile: {type: RuntimeDefault} + containers: + - name: nginx + image: {{ required "image is required" .Values.image | quote }} + imagePullPolicy: IfNotPresent + securityContext: {allowPrivilegeEscalation: false} + ports: [{name: http, containerPort: 8080}] + env: + - {name: ATLAS_GATEWAY_URL, value: {{ .Values.gatewayUrl | quote }}} + readinessProbe: + httpGet: {path: /healthz, port: http} + periodSeconds: 5 + livenessProbe: + httpGet: {path: /healthz, port: http} + periodSeconds: 15 + resources: + requests: {cpu: 10m, memory: 16Mi} + limits: {cpu: 200m, memory: 64Mi} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }} +spec: + selector: {app.kubernetes.io/instance: {{ .Release.Name }}, app.kubernetes.io/component: web} + ports: [{name: http, port: 8080, targetPort: http}] diff --git a/deploy/helm/item-atlas-pc/values.yaml b/deploy/helm/item-atlas-pc/values.yaml new file mode 100644 index 0000000..1f4eec9 --- /dev/null +++ b/deploy/helm/item-atlas-pc/values.yaml @@ -0,0 +1,5 @@ +image: item-atlas-pc:0.1.0 +gatewayUrl: http://item-atlas-gateway:8080 +frp: + enabled: false + secretName: atlas-pc-frpc diff --git a/deploy/public/README.md b/deploy/public/README.md index 9416f3d..370efe9 100644 --- a/deploy/public/README.md +++ b/deploy/public/README.md @@ -64,3 +64,30 @@ 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 记录。通过公网跑原生会话冒烟,带令牌查询 `GET /api/households` 应返回 200。另查未登录的 API 及管理路径,预期分别为 401 和 404。仍有旧版 iOS 使用时再验一次 OIDC 授权码回调。 [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 站点。数据库和私有桶有独立备份流程。 + +## PC 工作台 + +`pc-atlas.tutudog.com` 的页面及静态资源经独立的 `jianwu-public-pc` STCP 到 PC 容器。同源 `/api/` 复用网关的 STCP 通道。会话请求使用现有的限流区,管理 API 路径在 PC 入口返回 404。PC 前端和 FRP 客户端使用独立 Deployment,前端更新时可以保留已注册的通道。 + +先按 [PC 构建说明](../../apps/pc/README.md#构建与部署) 生成 ARM64 镜像。用不可变发布标识作为标签,在 kind 环境载入该镜像,或令集群从私有仓库拉取。将 `pc-frpc.toml.template` 渲染到受控文件,再部署独立 Helm release。 + +```sh +kubectl -n item-atlas-public create secret generic atlas-pc-frpc \ + --from-file=frpc.toml="$ATLAS_SECRET_DIR/pc-frpc.toml" +helm upgrade --install item-atlas-pc deploy/helm/item-atlas-pc -n item-atlas-public \ + --set-string image="$ATLAS_PC_IMAGE" --set frp.enabled=true \ + --atomic --wait --timeout 3m +kubectl -n item-atlas-public rollout status deployment/item-atlas-pc --timeout=60s +``` + +云机用同一条 STCP 密钥渲染 `pc-visitor.toml.template`,由 `item-atlas-pc-frpc.service` 监听私有地址的 18792 端口。渲染 `pc-nginx.conf.template` 后先检查 Nginx 配置,再重载。首次接入可以用已有覆盖该域名的证书验证 HTTPS,之后为 PC 域名建立独立的 A 记录。 + +独立证书用 Certbot 的 HTTP-01 webroot。Nginx 将 `/.well-known/acme-challenge/` 指到配置挂载目录下的 `.acme-pc`,其他 HTTP 请求跳转 HTTPS。签发后将 `install-pc-certificate.sh` 安装在云机 `/opt/item-atlas-pc/`,运行一次,并把站点证书目录指到 `/etc/nginx/ssl/pc-atlas.tutudog.com/current`。检查配置并重载后,启用 `item-atlas-pc-cert-renew.timer`。核对外部证书、续期模拟和定时器的下次执行时间。 + +```sh +certbot renew --cert-name pc-atlas.tutudog.com --dry-run +systemctl list-timers item-atlas-pc-cert-renew.timer +curl -fsS https://pc-atlas.tutudog.com/floor-plan +``` + +验收包括深层页面刷新、原生账号登录、物品搜索和平面图读取。PC 版本用 `helm history item-atlas-pc -n item-atlas-public` 查看。后续镜像更新可回退到上一份包含 FRP 的 PC 修订,并复验页面和 API。 diff --git a/deploy/public/install-pc-certificate.sh b/deploy/public/install-pc-certificate.sh new file mode 100644 index 0000000..95138ea --- /dev/null +++ b/deploy/public/install-pc-certificate.sh @@ -0,0 +1,36 @@ +#!/bin/sh +set -eu +umask 077 + +lineage=/etc/letsencrypt/live/pc-atlas.tutudog.com +if [ -n "${RENEWED_LINEAGE:-}" ] && [ "$RENEWED_LINEAGE" != "$lineage" ]; then + exit 0 +fi + +ssl_root=${ATLAS_EDGE_SSL_ROOT:-/home/dongjf/dongjf-ng/ssl} +nginx=${ATLAS_EDGE_NGINX:-dongjf-nginx} +target="$ssl_root/pc-atlas.tutudog.com" +install -d -m 0700 "$target" +cert_key=$(openssl x509 -in "$lineage/fullchain.pem" -pubkey -noout | openssl sha256) +private_key=$(openssl pkey -in "$lineage/privkey.pem" -pubout | openssl sha256) +test "$cert_key" = "$private_key" +openssl x509 -in "$lineage/fullchain.pem" -checkend 86400 -noout + +release=$(mktemp -d "$target/cert.XXXXXX") +install -m 0644 "$lineage/fullchain.pem" "$release/fullchain.pem" +install -m 0600 "$lineage/privkey.pem" "$release/privkey.pem" +previous=$(readlink "$target/current" || true) +ln -s "$(basename "$release")" "$target/.current.$$" +mv -Tf "$target/.current.$$" "$target/current" + +if docker exec "$nginx" nginx -t && docker exec "$nginx" nginx -s reload; then + exit 0 +fi + +if [ -n "$previous" ]; then + ln -s "$previous" "$target/.current.$$" + mv -Tf "$target/.current.$$" "$target/current" +else + mv "$target/current" "$target/failed.$$" +fi +exit 1 diff --git a/deploy/public/item-atlas-pc-cert-renew.service b/deploy/public/item-atlas-pc-cert-renew.service new file mode 100644 index 0000000..f854350 --- /dev/null +++ b/deploy/public/item-atlas-pc-cert-renew.service @@ -0,0 +1,8 @@ +[Unit] +Description=Renew the Item Atlas desktop site certificate +Wants=network-online.target +After=network-online.target docker.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/certbot renew --quiet --cert-name pc-atlas.tutudog.com --deploy-hook /opt/item-atlas-pc/install-certificate.sh diff --git a/deploy/public/item-atlas-pc-cert-renew.timer b/deploy/public/item-atlas-pc-cert-renew.timer new file mode 100644 index 0000000..db08b10 --- /dev/null +++ b/deploy/public/item-atlas-pc-cert-renew.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Check the Item Atlas desktop site certificate twice a day + +[Timer] +OnCalendar=*-*-* 03,15:20:00 +RandomizedDelaySec=20m +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/deploy/public/item-atlas-pc-frpc.service b/deploy/public/item-atlas-pc-frpc.service new file mode 100644 index 0000000..5b45bdc --- /dev/null +++ b/deploy/public/item-atlas-pc-frpc.service @@ -0,0 +1,16 @@ +[Unit] +Description=Item Atlas desktop web FRP visitor +Wants=network-online.target +After=network-online.target docker.service + +[Service] +ExecStart=/opt/localollama-relay/frpc -c /opt/item-atlas-pc/pc-visitor.toml +Restart=on-failure +RestartSec=4s +NoNewPrivileges=true +ProtectSystem=strict +ProtectHome=true +PrivateTmp=true + +[Install] +WantedBy=multi-user.target diff --git a/deploy/public/pc-frpc.toml.template b/deploy/public/pc-frpc.toml.template new file mode 100644 index 0000000..b178b61 --- /dev/null +++ b/deploy/public/pc-frpc.toml.template @@ -0,0 +1,12 @@ +serverAddr = "ATLAS_FRPS_HOST" +serverPort = 7000 +auth.method = "token" +auth.token = "ATLAS_FRPS_TOKEN" +transport.tls.enable = true + +[[proxies]] +name = "jianwu-public-pc" +type = "stcp" +secretKey = "ATLAS_PC_STCP_KEY" +localIP = "item-atlas-pc" +localPort = 8080 diff --git a/deploy/public/pc-nginx.conf.template b/deploy/public/pc-nginx.conf.template new file mode 100644 index 0000000..1803cb3 --- /dev/null +++ b/deploy/public/pc-nginx.conf.template @@ -0,0 +1,45 @@ +server { + listen 80; + server_name pc-atlas.tutudog.com; + location ^~ /.well-known/acme-challenge/ { + root /etc/nginx/conf.d/.acme-pc; + try_files $uri =404; + } + location / { return 308 https://pc-atlas.tutudog.com$request_uri; } +} + +server { + listen 443 ssl; + server_name pc-atlas.tutudog.com; + ssl_certificate ATLAS_PC_CERT_DIR/fullchain.pem; + ssl_certificate_key ATLAS_PC_CERT_DIR/privkey.pem; + client_max_body_size 6m; + + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Forwarded-Port 443; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_connect_timeout 5s; + proxy_read_timeout 90s; + + gzip on; + gzip_types application/javascript text/css; + + location = /api/admin { return 404; } + location ^~ /api/admin/ { return 404; } + location ^~ /api/session/ { + client_max_body_size 4k; + limit_req zone=atlas_native_session burst=10 nodelay; + limit_req_status 429; + proxy_pass http://ATLAS_VISITOR_API; + } + location ^~ /api/ { + proxy_pass http://ATLAS_VISITOR_API; + } + location / { + proxy_pass http://ATLAS_VISITOR_PC; + } +} diff --git a/deploy/public/pc-visitor.toml.template b/deploy/public/pc-visitor.toml.template new file mode 100644 index 0000000..101246c --- /dev/null +++ b/deploy/public/pc-visitor.toml.template @@ -0,0 +1,13 @@ +serverAddr = "ATLAS_FRPS_HOST" +serverPort = 7000 +auth.method = "token" +auth.token = "ATLAS_FRPS_TOKEN" +transport.tls.enable = true + +[[visitors]] +name = "jianwu-public-pc-visitor" +type = "stcp" +serverName = "jianwu-public-pc" +secretKey = "ATLAS_PC_STCP_KEY" +bindAddr = "ATLAS_VISITOR_BIND_ADDR" +bindPort = 18792 diff --git a/docs/deployment/overview.md b/docs/deployment/overview.md index 000fb10..12c5c73 100644 --- a/docs/deployment/overview.md +++ b/docs/deployment/overview.md @@ -44,13 +44,13 @@ Kubernetes 的控制面和应用在同一虚拟机内。Helm 管理应用和可 ## 公网入口和域名 -公网 Nginx 负责证书和 HTTPS,保留 Host 和转发协议。iOS 预览的两个 frp visitor 在云端私有网桥监听,分别通过 STCP 到集群中的 Gateway 和 Keycloak Service。数据库、监控和 Kubernetes 管理端口留在内网。见物的模型调用走家庭私网。 [公网预览部署](../../deploy/public/README.md) · [frp STCP](https://gofrp.org/en/docs/examples/stcp/) +公网 Nginx 负责证书和 HTTPS,保留 Host 和转发协议。三个 frp visitor 在云端私有网桥监听,分别通过 STCP 到集群中的 Gateway、Keycloak 和 PC Service。PC 网页的同源 `/api/` 复用网关通道。数据库、监控和 Kubernetes 管理端口留在内网。见物的模型调用走家庭私网。 [公网部署](../../deploy/public/README.md) · [frp STCP](https://gofrp.org/en/docs/examples/stcp/) -子域名统一采用 `用途-产品名`。移动网页用 `m`,PC 网页用 `pc`。当前已开通 iOS 公网预览的 API 域名,其余三个用于后续 Web 部署。 [公网连通性验收](identity-and-media.md#ios-公网连通性验收) +子域名统一采用 `用途-产品名`。移动网页用 `m`,PC 网页用 `pc`。API 和 PC 网页已开通公网 HTTPS。 [公网连通性验收](identity-and-media.md#ios-公网连通性验收) | 域名 | 指向 | | --- | --- | -| `pc-atlas.tutudog.com` | PC 网页 | +| `pc-atlas.tutudog.com` | PC 网页,独立证书和续期定时器 | | `m-atlas.tutudog.com` | 移动网页(H5) | | `admin-atlas.tutudog.com` | 管理后台,使用管理员身份和访问限制 | | `api-atlas.tutudog.com` | 项目专用 HTTPS 入口,`/api/` 到网关,`/auth/` 到正式身份服务 |