From 3f5c2bb137a22d2f64151fc118fa1017d78f3b73 Mon Sep 17 00:00:00 2001 From: dongjf <1+dongjf@noreply.git.tutudog.com> Date: Wed, 25 Nov 2026 10:18:59 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=8E=A5=E9=80=9A=20ARM64=20=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=8F=91=E5=B8=83=E5=92=8C=E9=A2=84=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 50 +++++++++++++++++++++++------- backend/tests/smoke.py | 13 ++++++-- docs/deployment/backend-release.md | 8 ++--- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6284669..ac77acc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -23,9 +23,32 @@ steps: - apk add --no-cache openjdk21-jdk maven postgresql-client - mvn -B -ntp -f backend/pom.xml verify - sh deploy/local/ci-smoke.sh +trigger: + event: [push, pull_request, tag] + +--- +kind: pipeline +type: docker +name: backend-publish + +platform: + os: linux + arch: arm64 + +node: + atlas-release: "true" + +depends_on: + - backend-ci + +steps: + - name: package + image: maven:3.9.11-eclipse-temurin-21-alpine + commands: + - mvn -B -ntp -f backend/pom.xml -DskipTests package - name: publish-gateway image: plugins/docker:21.3.8 - depends_on: [verify] + depends_on: [package] settings: registry: git.tutudog.com repo: git.tutudog.com/dongjf/item-atlas-gateway @@ -37,9 +60,6 @@ steps: context: backend/gateway platform: linux/arm64 tags: ["${DRONE_COMMIT_SHA}"] - when: - event: [tag] - ref: [refs/tags/v*] - name: publish-inventory-service image: plugins/docker:21.3.8 depends_on: [publish-gateway] @@ -54,9 +74,6 @@ steps: context: backend/inventory-service platform: linux/arm64 tags: ["${DRONE_COMMIT_SHA}"] - when: - event: [tag] - ref: [refs/tags/v*] - name: publish-intake-service image: plugins/docker:21.3.8 depends_on: [publish-inventory-service] @@ -71,17 +88,19 @@ steps: context: backend/intake-service platform: linux/arm64 tags: ["${DRONE_COMMIT_SHA}"] - when: - event: [tag] - ref: [refs/tags/v*] trigger: - event: [push, pull_request, tag] + event: [tag] + ref: [refs/tags/v*] --- kind: pipeline type: docker name: deploy-staging +platform: + os: linux + arch: arm64 + node: atlas-deploy: "true" @@ -89,6 +108,7 @@ steps: - name: helm-upgrade image: alpine/helm:3.20.0 environment: + HELM_DRIVER: configmap ATLAS_KUBECONFIG_B64: from_secret: atlas_staging_kubeconfig_b64 commands: @@ -97,12 +117,17 @@ steps: trigger: event: [promote] target: [staging] + ref: [refs/tags/v*] --- kind: pipeline type: docker name: deploy-production +platform: + os: linux + arch: arm64 + node: atlas-deploy: "true" @@ -118,3 +143,6 @@ steps: trigger: event: [promote] target: [production] + ref: + include: [refs/tags/v*] + exclude: [refs/tags/v*-*] diff --git a/backend/tests/smoke.py b/backend/tests/smoke.py index f50e0fd..3c6ba01 100644 --- a/backend/tests/smoke.py +++ b/backend/tests/smoke.py @@ -10,7 +10,11 @@ from urllib.parse import urlencode from urllib.request import Request, urlopen BASE = os.environ.get("ATLAS_BASE_URL", "http://127.0.0.1:8080").rstrip("/") -PASSWORD = os.environ["ATLAS_LOCAL_PASSWORD"] +PASSWORD = os.environ.get("ATLAS_LOCAL_PASSWORD") +TOKENS = {name: os.environ.get("ATLAS_SMOKE_TOKEN_" + name.upper()) + for name in ("owner", "viewer", "other")} +if not (all(TOKENS.values()) or PASSWORD and not any(TOKENS.values())): + raise ValueError("Supply ATLAS_LOCAL_PASSWORD or the three staging access tokens") HOUSE = "/api/households/00000000-0000-0000-0000-000000000001" OTHER_HOUSE = "/api/households/00000000-0000-0000-0000-000000000002" RUN = uuid.uuid4().hex[:8] @@ -22,8 +26,11 @@ def call(method, path, payload=None, *, user="owner", status=200): if data is not None: request.add_header("Content-Type", "application/json") if user: - token = base64.b64encode(f"{user}:{PASSWORD}".encode()).decode() - request.add_header("Authorization", f"Basic {token}") + if TOKENS[user]: + request.add_header("Authorization", f"Bearer {TOKENS[user]}") + else: + token = base64.b64encode(f"{user}:{PASSWORD}".encode()).decode() + request.add_header("Authorization", f"Basic {token}") try: response = urlopen(request, timeout=78) except HTTPError as error: diff --git a/docs/deployment/backend-release.md b/docs/deployment/backend-release.md index c4ba2c9..453b1d1 100644 --- a/docs/deployment/backend-release.md +++ b/docs/deployment/backend-release.md @@ -2,11 +2,11 @@ ## 从提交到部署 -1. Gitea 保存代码。Drone `backend-ci` 在常规提交和发布标签上运行 Java 21、Maven 和 API 冒烟。CI 使用 runner 已缓存的 PostgreSQL 15 镜像做兼容验证,本地和目标部署使用 PostgreSQL 17。发布标签采用 `v*`。标签验证通过后构建并推送三个 ARM64 镜像,镜像标签使用完整提交 SHA。 +1. Gitea 保存代码。Drone `backend-ci` 在常规提交和发布标签上运行 Java 21、Maven 和 API 冒烟。CI 用 PostgreSQL 15 做兼容验证,本地和部署环境用 PostgreSQL 17。对 `v*` 标签,CI 通过后 ARM64 runner 构建并推送三个镜像。镜像标签使用完整提交 SHA。 2. 在 Drone 提升同一个成功构建到 `staging`。部署步骤使用 Helm 3 的 `upgrade --install --atomic --wait`。就绪探针检查应用和数据库,Helm hook 逐个访问 Kubernetes Service。 -3. 在预发布验证业务请求,再将同一个构建提升到 `production`。正式端口由既有入口配置转发到网关。数据库、Ollama 与 Actuator 保持内部访问。 +3. 在预发布验证业务请求。正式发布使用同一稳定版本构建与 `production` 提升,带连字符的候选标签只走预发布。正式端口由入口配置转发到网关。数据库、Ollama 与 Actuator 保持内部访问。 -标记 `atlas-deploy=true` 的 Drone runner 须能通过内网访问对应 Kubernetes API。分环境创建 Kubernetes namespace 和作用域受限的发布身份。用 Drone Secrets 提供仓库令牌和对应 namespace 的 kubeconfig。集群内的镜像拉取使用 `item-atlas-registry`。 [Drone Promotion](https://docs.drone.io/user-guide/pipeline/promotion/) · [Helm 升级](https://helm.sh/docs/v3/helm/helm_upgrade/) +标记 `atlas-release=true` 的 ARM64 runner 构建镜像。标记 `atlas-deploy=true` 的 runner 须能访问对应 Kubernetes API。分环境创建 namespace 和作用域受限的发布身份。预发布用 ConfigMap 存 Helm 修订,部署账号可维护应用资源。Drone Secrets 保存仓库令牌与分环境的 kubeconfig。集群用 `item-atlas-registry` 拉取镜像。 [Drone Promotion](https://docs.drone.io/user-guide/pipeline/promotion/) · [Helm 升级](https://helm.sh/docs/v3/helm/helm_upgrade/) | 位置 | 配置 | | --- | --- | @@ -16,7 +16,7 @@ | PostgreSQL | 为两个服务各建一个数据库和登录角色。数据卷在 SSD。首次启动由 Flyway 建表。 | | Ollama | 录入服务设置 `ATLAS_OLLAMA_ENABLED=true` 和内网 `ATLAS_OLLAMA_URL`,模型默认 `gemma4:12b`。 | -正式数据库使用 `release` 配置,家庭成员按 OIDC `sub` 建立记录。演示数据用单独数据库。首期需要开通家庭时,由管理员在数据库维护窗口建立 `household` 和 `household_member` 对应行。 +预发布和正式数据库使用 `release` 配置,家庭成员按 OIDC `sub` 建立记录。演示数据用单独数据库。首次开通家庭时,由管理员建立 `household` 和 `household_member` 对应行。预发布冒烟可注入 `ATLAS_SMOKE_TOKEN_OWNER`、`ATLAS_SMOKE_TOKEN_VIEWER`、`ATLAS_SMOKE_TOKEN_OTHER` 三个临时 OIDC 凭据,验证家庭隔离和确认后的后台服务调用。 ## 灰度