build-image workflow 加 OCI 标签实现包仓库自动关联

加两个 OCI 标签到镜像 manifest:

- org.opencontainers.image.source=<repo url>
  Gitea 收包时检测此标签若指向自家 repo URL,自动把包链接到 repo
  的 Packages tab,不再需要手动去 "包设置 → 链接仓库"

- org.opencontainers.image.revision=<full SHA>
  把构建时的源码 commit SHA 烙进 manifest,docker inspect 可反推回
  代码版本,配合 image_tag(commit short hash)形成两层冗余

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-02 17:08:34 +08:00
parent 2dd8f0994a
commit 76043e587b
+10 -1
View File
@@ -37,7 +37,7 @@ jobs:
username: ${{ gitea.actor }} username: ${{ gitea.actor }}
password: ${{ secrets.PACKAGES_TOKEN }} password: ${{ secrets.PACKAGES_TOKEN }}
- name: Determine image tag - name: Determine image tag and revision
id: meta id: meta
run: | run: |
if [ -n "${{ inputs.tag }}" ]; then if [ -n "${{ inputs.tag }}" ]; then
@@ -46,6 +46,7 @@ jobs:
IMAGE_TAG="$(git rev-parse --short HEAD)" IMAGE_TAG="$(git rev-parse --short HEAD)"
fi fi
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "full_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "==> Image tag: $IMAGE_TAG" echo "==> Image tag: $IMAGE_TAG"
- name: Build and push - name: Build and push
@@ -59,6 +60,14 @@ jobs:
# CHECK_3RD_API 留空 → 三方 API 测试不跑;想跑设 "1" # CHECK_3RD_API 留空 → 三方 API 测试不跑;想跑设 "1"
build-args: | build-args: |
BUILD_PIPELINE=1 BUILD_PIPELINE=1
# OCI 标签:
# - source 让 Gitea 收包时自动把镜像关联到对应 repo(不再需要手动去
# "包设置 → 链接到仓库")
# - revision 把构建时的 commit full SHA 烙进镜像 manifest
# docker inspect 能反推回源码版本
labels: |
org.opencontainers.image.source=https://git.zhengchentao.win/dev/ezbookkeeping
org.opencontainers.image.revision=${{ steps.meta.outputs.full_sha }}
tags: | tags: |
git.zhengchentao.win/dev/ezbookkeeping:${{ steps.meta.outputs.image_tag }} git.zhengchentao.win/dev/ezbookkeeping:${{ steps.meta.outputs.image_tag }}
git.zhengchentao.win/dev/ezbookkeeping:latest git.zhengchentao.win/dev/ezbookkeeping:latest