From cd8cb3ead07fbc2a170186cf48b6b128e111baaa Mon Sep 17 00:00:00 2001 From: Arham Jain Date: Fri, 25 Oct 2024 15:55:54 +0530 Subject: [PATCH] ci(workflow): fixed use of docker tag --- .github/workflows/docker.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 98c46b3..c40bc9a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,8 +7,7 @@ on: inputs: tag: description: 'Tag for the Docker image' - required: false - default: 'latest' # Default tag if none is provided + required: true env: REGISTRY: ghcr.io @@ -48,6 +47,14 @@ jobs: else echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV # Actual branch name for push events fi + - name: Set Docker image tag + id: set-docker-tag + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + echo "DOCKER_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + else + echo "DOCKER_TAG=${{ env.BRANCH_NAME }}-${{ env.SHORT_COMMIT_HASH }}" >> $GITHUB_ENV + fi - name: Build and push Docker image id: push uses: docker/build-push-action@v6 @@ -55,7 +62,7 @@ jobs: context: . file: Dockerfile push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}-${{ env.SHORT_COMMIT_HASH }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}::${{ env.DOCKER_TAG }} labels: | version=${{ env.SHORT_COMMIT_HASH }} branch=${{ env.BRANCH_NAME }}