1
0
Fork 0

👷 ci(docker): enhance multi-tag support in image build workflow

- add multi-tag setup step supporting comma-separated image tags
- automatically add latest tag unless already included
- replace hardcoded tag configuration with metadata-action output
- simplify tag management logic for improved workflow maintainability
This commit is contained in:
pooneyy 2025-11-10 22:56:42 +08:00
parent 57d7a15f66
commit 4351ea0f12
No known key found for this signature in database
1 changed files with 18 additions and 4 deletions

View File

@ -99,6 +99,21 @@ jobs:
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
echo "IMAGE_TAG=${{ github.event.inputs.image_tag }}" >> $GITHUB_ENV
- name: Set multiple tags
id: set-tags
run: |
TAGS_ARRAY=($(echo "${{ env.IMAGE_TAG }}" | tr ',' ' '))
TAGS_MULTILINE=""
for tag in "${TAGS_ARRAY[@]}"; do
TAGS_MULTILINE+="type=raw,value=${tag}\n"
done
if [[ "${{ env.IMAGE_TAG }}" != *"latest"* ]]; then
TAGS_MULTILINE+="type=raw,value=latest\n"
fi
echo "tags<<EOF" >> $GITHUB_OUTPUT
echo -e "$TAGS_MULTILINE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Checkout repository
env:
REPO_URL: ${{ github.event.inputs.repo }}
@ -111,7 +126,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
ruby-version: '3.4.7'
- name: Get license
run: |
gem install licensee
@ -143,6 +158,7 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_FULL_NAME }}
tags: ${{ steps.set-tags.outputs.tags }}
annotations: |
org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }}
org.opencontainers.image.url=${{ github.event.inputs.repo }}
@ -174,9 +190,7 @@ jobs:
target: ${{ github.event.inputs.build_target }}
push: true
file: ${{ github.event.inputs.dockerfile }}
tags: |
${{ env.IMAGE_FULL_NAME }}:${{ env.IMAGE_TAG }}
${{ github.event.inputs.image_tag != 'latest' && format('{0}:latest', env.IMAGE_FULL_NAME) || '' }}
tags: ${{ steps.meta.outputs.tags }}
annotations: ${{ steps.meta.outputs.annotations }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha