Fix image tagging in CI/CD flow
All checks were successful
Docker Build and Push (Multi-architecture) / build-and-push (push) Successful in 22s
All checks were successful
Docker Build and Push (Multi-architecture) / build-and-push (push) Successful in 22s
This commit is contained in:
@@ -38,38 +38,45 @@ jobs:
|
|||||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Determine Docker tags
|
- name: Generate Docker tags
|
||||||
id: tags
|
id: tags
|
||||||
run: |
|
run: |
|
||||||
# Default tag from workflow_dispatch input
|
# Base image name
|
||||||
|
IMAGE_NAME="${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}"
|
||||||
|
|
||||||
|
# Determine primary tag
|
||||||
if [ -n "${{ github.event.inputs.image_tag }}" ]; then
|
if [ -n "${{ github.event.inputs.image_tag }}" ]; then
|
||||||
PRIMARY_TAG="${{ github.event.inputs.image_tag }}"
|
PRIMARY_TAG="${{ github.event.inputs.image_tag }}"
|
||||||
# Tag for release (semantic version tag)
|
|
||||||
elif [[ ${{ github.ref }} == refs/tags/v* ]]; then
|
elif [[ ${{ github.ref }} == refs/tags/v* ]]; then
|
||||||
PRIMARY_TAG="${GITHUB_REF#refs/tags/}"
|
PRIMARY_TAG="${GITHUB_REF#refs/tags/}"
|
||||||
# Also create a major.minor tag (e.g., v1.2 for v1.2.3)
|
|
||||||
MAJOR_MINOR_TAG=$(echo "$PRIMARY_TAG" | sed -E 's/^v([0-9]+\.[0-9]+)\.[0-9]+.*$/v\1/')
|
|
||||||
if [[ "$MAJOR_MINOR_TAG" != "$PRIMARY_TAG" ]]; then
|
|
||||||
echo "major_minor_tag=$MAJOR_MINOR_TAG" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
# Also create a major tag (e.g., v1 for v1.2.3)
|
|
||||||
MAJOR_TAG=$(echo "$PRIMARY_TAG" | sed -E 's/^v([0-9]+)\.[0-9]+\.[0-9]+.*$/v\1/')
|
|
||||||
if [[ "$MAJOR_TAG" != "$PRIMARY_TAG" ]]; then
|
|
||||||
echo "major_tag=$MAJOR_TAG" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
# Tag for main branch
|
|
||||||
elif [[ ${{ github.ref }} == refs/heads/main ]]; then
|
elif [[ ${{ github.ref }} == refs/heads/main ]]; then
|
||||||
PRIMARY_TAG="latest"
|
PRIMARY_TAG="latest"
|
||||||
# Tag for experimental branch
|
|
||||||
elif [[ ${{ github.ref }} == refs/heads/experimental ]]; then
|
elif [[ ${{ github.ref }} == refs/heads/experimental ]]; then
|
||||||
PRIMARY_TAG="experimental"
|
PRIMARY_TAG="experimental"
|
||||||
|
else
|
||||||
|
PRIMARY_TAG="latest"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "primary_tag=$PRIMARY_TAG" >> $GITHUB_OUTPUT
|
# Start with primary tag and SHA tag
|
||||||
echo "Using primary tag: $PRIMARY_TAG"
|
TAGS="$IMAGE_NAME:$PRIMARY_TAG,$IMAGE_NAME:${{ github.sha }}"
|
||||||
|
|
||||||
# Always include SHA tag for traceability
|
# Add version tags for releases
|
||||||
echo "sha_tag=${{ github.sha }}" >> $GITHUB_OUTPUT
|
if [[ ${{ github.ref }} == refs/tags/v* ]]; then
|
||||||
|
# Add major.minor tag (e.g., v1.2 for v1.2.3)
|
||||||
|
MAJOR_MINOR_TAG=$(echo "$PRIMARY_TAG" | sed -E 's/^v([0-9]+\.[0-9]+)\.[0-9]+.*$/v\1/')
|
||||||
|
if [[ "$MAJOR_MINOR_TAG" != "$PRIMARY_TAG" ]]; then
|
||||||
|
TAGS="$TAGS,$IMAGE_NAME:$MAJOR_MINOR_TAG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add major tag (e.g., v1 for v1.2.3)
|
||||||
|
MAJOR_TAG=$(echo "$PRIMARY_TAG" | sed -E 's/^v([0-9]+)\.[0-9]+\.[0-9]+.*$/v\1/')
|
||||||
|
if [[ "$MAJOR_TAG" != "$PRIMARY_TAG" ]]; then
|
||||||
|
TAGS="$TAGS,$IMAGE_NAME:$MAJOR_TAG"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "tags=$TAGS" >> $GITHUB_OUTPUT
|
||||||
|
echo "Generated tags: $TAGS"
|
||||||
|
|
||||||
- name: Build and push multi-arch image
|
- name: Build and push multi-arch image
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
@@ -79,8 +86,4 @@ jobs:
|
|||||||
push: true
|
push: true
|
||||||
cache-from: type=registry,ref=${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:cache
|
cache-from: type=registry,ref=${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:cache
|
||||||
cache-to: type=registry,ref=${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:cache,mode=max
|
cache-to: type=registry,ref=${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:cache,mode=max
|
||||||
tags: |
|
tags: ${{ steps.tags.outputs.tags }}
|
||||||
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ steps.tags.outputs.primary_tag }}
|
|
||||||
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ steps.tags.outputs.sha_tag }}
|
|
||||||
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ steps.tags.outputs.major_minor_tag }}
|
|
||||||
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ steps.tags.outputs.major_tag }}
|
|
||||||
Reference in New Issue
Block a user