feat(ci): add Docker Hub namespace support and push steps to base image workflow
This commit is contained in:
parent
0754201792
commit
f43c029541
45
.github/workflows/build-base-images.yml
vendored
45
.github/workflows/build-base-images.yml
vendored
@ -18,6 +18,11 @@ on:
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
dockerhub_namespace:
|
||||
description: "Docker Hub namespace (user/org)"
|
||||
type: string
|
||||
default: "manbuzhe2009"
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
registry:
|
||||
@ -32,6 +37,10 @@ on:
|
||||
description: "Push images instead of building locally"
|
||||
type: boolean
|
||||
default: true
|
||||
dockerhub_namespace:
|
||||
description: "Docker Hub namespace (user/org)"
|
||||
type: string
|
||||
default: "manbuzhe2009"
|
||||
|
||||
push:
|
||||
paths:
|
||||
@ -85,6 +94,42 @@ jobs:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# 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
|
||||
|
||||
- uses: anchore/sbom-action@v0
|
||||
with:
|
||||
image: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ matrix.image.name }}@${{ steps.build.outputs.digest }}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user