feat(ci): add Docker Hub namespace support and push workflow
This commit is contained in:
parent
c176f3bbcf
commit
e6d5a8d5e3
45
.github/workflows/build-service-images.yml
vendored
45
.github/workflows/build-service-images.yml
vendored
@ -8,6 +8,10 @@ on:
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
dockerhub_namespace:
|
||||
description: "Docker Hub namespace (user/org)"
|
||||
type: string
|
||||
|
||||
# Base image references (full image URL)
|
||||
node_builder_image:
|
||||
type: string
|
||||
@ -27,6 +31,11 @@ on:
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
dockerhub_namespace:
|
||||
description: "Docker Hub namespace (user/org)"
|
||||
type: string
|
||||
default: "manbuzhe2009"
|
||||
|
||||
node_builder_image:
|
||||
type: string
|
||||
default: "node:22-bookworm"
|
||||
@ -125,6 +134,42 @@ jobs:
|
||||
NODE_BUILDER_IMAGE=${{ env.NODE_BUILDER_IMAGE }}
|
||||
NODE_RUNTIME_IMAGE=${{ env.NODE_RUNTIME_IMAGE }}
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Push to Docker Hub (optional)
|
||||
# -------------------------------------------------------------
|
||||
- name: Login to Docker Hub
|
||||
if: env.PUSH_IMAGES == 'true'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: docker.io
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Re-tag & Push image to Docker Hub
|
||||
if: env.PUSH_IMAGES == 'true'
|
||||
env:
|
||||
TARGET_NS: ${{ env.DOCKERHUB_NAMESPACE }}
|
||||
run: |
|
||||
ORIGIN_IMG="${{ env.REGISTRY }}/${{ env.ORG }}/${{ matrix.service.name }}@${{ steps.build.outputs.digest }}"
|
||||
TARGET_REPO="docker.io/${TARGET_NS}/${{ matrix.service.name }}"
|
||||
TAGS="${{ steps.meta.outputs.tags }}"
|
||||
|
||||
echo "Origin: $ORIGIN_IMG"
|
||||
echo "Target Namespace: $TARGET_NS"
|
||||
echo "Target Repo: $TARGET_REPO"
|
||||
|
||||
docker pull "$ORIGIN_IMG"
|
||||
|
||||
# 为所有 tag 逐个推送
|
||||
for TAG in $TAGS; do
|
||||
SHORT_TAG=$(echo "$TAG" | sed -E 's|.*/||') # 提取 tag 名称
|
||||
echo "Tagging -> $TARGET_REPO:$SHORT_TAG"
|
||||
docker tag "$ORIGIN_IMG" "$TARGET_REPO:$SHORT_TAG"
|
||||
echo "Pushing -> $TARGET_REPO:$SHORT_TAG"
|
||||
docker push "$TARGET_REPO:$SHORT_TAG"
|
||||
echo "✓ Pushed: $TARGET_REPO:$SHORT_TAG"
|
||||
done
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# SBOM Generation
|
||||
# -------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user