Skip to content

Commit 302e0f6

Browse files
committed
ci: support multiple tags in docker workflow
1 parent 85737a2 commit 302e0f6

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

.github/workflows/docker_publish.yaml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: Publish Docker Image
33
on:
44
workflow_dispatch:
55
inputs:
6-
tag:
7-
description: "Docker image tag (e.g., latest, v0.1.0)"
6+
tags:
7+
description: "Docker image tags, comma-separated (e.g., latest,v0.1.0)"
88
required: false
99
default: "latest"
1010

@@ -42,6 +42,17 @@ jobs:
4242
username: ${{ github.actor }}
4343
password: ${{ secrets.GITHUB_TOKEN }}
4444

45+
- name: Prepare tags
46+
id: prep
47+
run: |
48+
TAGS=""
49+
IFS=',' read -ra TAG_ARRAY <<< "${{ inputs.tags }}"
50+
for t in "${TAG_ARRAY[@]}"; do
51+
TAGS="${TAGS}${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${t}-${{ matrix.arch }},"
52+
done
53+
TAGS="${TAGS%,}" # Remove trailing comma
54+
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
55+
4556
- name: Build and push Docker image
4657
uses: docker/build-push-action@v6
4758
with:
@@ -51,7 +62,7 @@ jobs:
5162
GIT_COMMIT=${{ github.sha }}
5263
GIT_BRANCH=${{ github.ref_name }}
5364
push: true
54-
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }}-${{ matrix.arch }}
65+
tags: ${{ steps.prep.outputs.tags }}
5566
platforms: linux/${{ matrix.arch }}
5667
cache-from: type=gha,scope=${{ matrix.arch }}
5768
cache-to: type=gha,scope=${{ matrix.arch }},mode=max
@@ -69,12 +80,24 @@ jobs:
6980
username: ${{ github.actor }}
7081
password: ${{ secrets.GITHUB_TOKEN }}
7182

72-
- name: Create multi-arch manifest
83+
- name: Create multi-arch manifests
7384
env:
7485
SHORT_SHA: ${{ github.sha }}
7586
run: |
87+
IFS=',' read -ra TAG_ARRAY <<< "${{ inputs.tags }}"
88+
FIRST_TAG="${TAG_ARRAY[0]}"
89+
90+
# Create manifest for first tag with SHA tag
7691
docker buildx imagetools create \
77-
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }} \
92+
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${FIRST_TAG} \
7893
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${SHORT_SHA::7} \
79-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }}-amd64 \
80-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }}-arm64
94+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${FIRST_TAG}-amd64 \
95+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${FIRST_TAG}-arm64
96+
97+
# Create manifests for remaining tags
98+
for t in "${TAG_ARRAY[@]:1}"; do
99+
docker buildx imagetools create \
100+
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${t} \
101+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${t}-amd64 \
102+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${t}-arm64
103+
done

0 commit comments

Comments
 (0)