From 336afdcb0cf59f43f0ce01ac5e28aec8707eb824 Mon Sep 17 00:00:00 2001 From: chenhang Date: Thu, 9 Jul 2026 10:44:05 +0800 Subject: [PATCH] ci(docker): resolve registry package identity --- .gitea/workflows/docker-image.yml | 2 ++ docs/docker-image-ci.md | 2 ++ docs/gitea-actions-ssh-deploy.md | 1 + scripts/ci/prune-gitea-container-images.sh | 22 ++++++++++++++++++---- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/docker-image.yml b/.gitea/workflows/docker-image.yml index 74ab4e54..c6c449fa 100644 --- a/.gitea/workflows/docker-image.yml +++ b/.gitea/workflows/docker-image.yml @@ -135,6 +135,8 @@ jobs: env: REGISTRY_API_BASE_URL: ${{ secrets.REGISTRY_API_BASE_URL }} REGISTRY_PACKAGE_TOKEN: ${{ secrets.REGISTRY_PACKAGE_TOKEN }} + REGISTRY_PACKAGE_OWNER: ${{ secrets.REGISTRY_PACKAGE_OWNER }} + REGISTRY_PACKAGE_NAME: ${{ secrets.REGISTRY_PACKAGE_NAME }} run: | set -eu diff --git a/docs/docker-image-ci.md b/docs/docker-image-ci.md index 131f1609..6ec16a12 100644 --- a/docs/docker-image-ci.md +++ b/docs/docker-image-ci.md @@ -25,6 +25,8 @@ | `REGISTRY_PASSWORD` | `***` | 镜像仓库密码或访问令牌 | | `REGISTRY_API_BASE_URL` | `https://gitea.banlv-ai.com/api/v1` | Gitea API 地址,用于清理旧镜像版本 | | `REGISTRY_PACKAGE_TOKEN` | `***` | 具备 package 删除权限的 Gitea token | +| `REGISTRY_PACKAGE_OWNER` | `banlv` | 可选;Registry 镜像名不含 owner 时用于指定 package owner | +| `REGISTRY_PACKAGE_NAME` | `cozsweet-web` | 可选;Registry 镜像名不含 owner 或包名不一致时用于指定 package name | | `TEST_ENV_FILE` | `.env.local` 的完整内容 | 测试环境构建期环境变量 | | `PRODUCTION_ENV_FILE` | `.env.production` 的完整内容 | 生产环境构建期环境变量 | diff --git a/docs/gitea-actions-ssh-deploy.md b/docs/gitea-actions-ssh-deploy.md index 127d47cf..48f3d1e3 100644 --- a/docs/gitea-actions-ssh-deploy.md +++ b/docs/gitea-actions-ssh-deploy.md @@ -31,6 +31,7 @@ push test/main | `REGISTRY_PASSWORD` | registry 密码或 token | | `REGISTRY_API_BASE_URL` | Gitea API 地址,例如 `https://gitea.banlv-ai.com/api/v1` | | `REGISTRY_PACKAGE_TOKEN` | 具备 package 删除权限的 Gitea token,用于清理旧镜像 tag | +| `REGISTRY_PACKAGE_OWNER` / `REGISTRY_PACKAGE_NAME` | 可选;当 `REGISTRY_IMAGE` 不包含 owner/package 两段路径时,显式指定 Gitea package owner 和 name | | `TEST_ENV_FILE` | 测试环境 `.env.local` 内容 | | `PRODUCTION_ENV_FILE` | 生产环境 `.env.production` 内容 | diff --git a/scripts/ci/prune-gitea-container-images.sh b/scripts/ci/prune-gitea-container-images.sh index f60fb446..fe70eb0a 100755 --- a/scripts/ci/prune-gitea-container-images.sh +++ b/scripts/ci/prune-gitea-container-images.sh @@ -5,6 +5,8 @@ KEEP_COUNT="${REGISTRY_PACKAGE_KEEP_COUNT:-3}" API_BASE_URL="${REGISTRY_API_BASE_URL:-https://gitea.banlv-ai.com/api/v1}" TOKEN="${REGISTRY_PACKAGE_TOKEN:-}" REGISTRY_IMAGE="${REGISTRY_IMAGE:-${IMAGE:-}}" +REGISTRY_PACKAGE_OWNER="${REGISTRY_PACKAGE_OWNER:-}" +REGISTRY_PACKAGE_NAME="${REGISTRY_PACKAGE_NAME:-}" DEPLOY_ENV="${DEPLOY_ENV:-}" CURRENT_IMAGE_TAG="${IMAGE_VERSION_TAG:-}" @@ -38,11 +40,23 @@ fi image_without_tag="${REGISTRY_IMAGE%%:*}" path_without_registry="${image_without_tag#*/}" -owner="${path_without_registry%%/*}" -package="${path_without_registry#*/}" +parsed_owner="" +parsed_package="$path_without_registry" +if [ "$path_without_registry" != "$image_without_tag" ] && [ "$path_without_registry" != "${path_without_registry#*/}" ]; then + parsed_owner="${path_without_registry%%/*}" + parsed_package="${path_without_registry#*/}" +fi -if [ "$owner" = "$path_without_registry" ] || [ -z "$owner" ] || [ -z "$package" ]; then - echo "Could not parse owner/package from REGISTRY_IMAGE: $REGISTRY_IMAGE" >&2 +repository_owner="${GITHUB_REPOSITORY_OWNER:-}" +if [ -z "$repository_owner" ] && [ -n "${GITHUB_REPOSITORY:-}" ]; then + repository_owner="${GITHUB_REPOSITORY%%/*}" +fi + +owner="${REGISTRY_PACKAGE_OWNER:-${parsed_owner:-$repository_owner}}" +package="${REGISTRY_PACKAGE_NAME:-$parsed_package}" + +if [ -z "$owner" ] || [ -z "$package" ]; then + echo "Could not resolve registry package owner/name. Set REGISTRY_PACKAGE_OWNER and REGISTRY_PACKAGE_NAME." >&2 exit 1 fi