Skip to content

Commit f373286

Browse files
committed
fix docker do not tag manual as latest
1 parent 9bb68fd commit f373286

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

.github/workflows/docker-image.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ jobs:
4949
echo "VERSION=${BRANCH_NAME}" >> $GITHUB_ENV
5050
fi
5151
52+
- name: Generate Docker tags
53+
run: |
54+
BASE_TAG="${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:${{ env.VERSION }}"
55+
56+
if [ "${{ github.event_name }}" == "release" ]; then
57+
# For releases: add both version tag and latest
58+
TAGS="${BASE_TAG},${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:latest"
59+
echo "DOCKER_TAGS=${TAGS}" >> $GITHUB_ENV
60+
echo "TAGGING_MODE=release (with latest)" >> $GITHUB_ENV
61+
else
62+
# For manual dispatch: only version tag (branch name)
63+
TAGS="${BASE_TAG}"
64+
echo "DOCKER_TAGS=${TAGS}" >> $GITHUB_ENV
65+
echo "TAGGING_MODE=manual dispatch (no latest)" >> $GITHUB_ENV
66+
fi
67+
5268
- name: Extract metadata (tags, labels) for Docker
5369
id: meta
5470
uses: docker/metadata-action@v5
@@ -57,29 +73,31 @@ jobs:
5773
tags: |
5874
type=ref,event=branch
5975
type=ref,event=tag
60-
type=raw,value=latest,enable={{is_default_branch}}
76+
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
6177
6278
- name: Build and push Docker image
6379
uses: docker/build-push-action@v5
6480
with:
6581
context: .
6682
platforms: linux/amd64,linux/arm64
6783
push: true
68-
tags: |
69-
${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:${{ env.VERSION }}
70-
${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:latest
84+
tags: ${{ env.DOCKER_TAGS }}
7185
labels: ${{ steps.meta.outputs.labels }}
7286
cache-from: type=gha
7387
cache-to: type=gha,mode=max
7488

7589
- name: Output build information
7690
run: |
7791
echo "✅ Docker images built and pushed successfully!"
78-
echo "🐋 Images:"
79-
echo " - ${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:${{ env.VERSION }}"
80-
echo " - ${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:latest"
92+
echo "🐋 Images built:"
8193
if [ "${{ github.event_name }}" == "release" ]; then
94+
echo " - ${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:${{ env.VERSION }}"
95+
echo " - ${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:latest"
8296
echo "📝 Triggered by release: ${{ github.event.release.tag_name }}"
97+
echo "🏷️ Tagged as 'latest' because this is a published release"
8398
else
99+
echo " - ${{ env.REGISTRY }}/${{ env.LOWER_CASE_REPO_NAME }}:${{ env.VERSION }}"
84100
echo "📝 Triggered by manual workflow dispatch on branch: ${{ github.ref_name }}"
101+
echo "🏷️ No 'latest' tag for manual builds"
85102
fi
103+
echo "🔧 Tagging mode: ${{ env.TAGGING_MODE }}"

0 commit comments

Comments
 (0)