From dd3caa170302d61a73bba432f26a3f8bb9cc18a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otakar=20Hir=C5=A1?= Date: Thu, 12 Sep 2024 21:02:20 +0200 Subject: [PATCH] feat(CD): add latest tag --- .github/workflows/backend_publish.yml | 29 ++++++++++----------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/backend_publish.yml b/.github/workflows/backend_publish.yml index d2dd45c..b8622e4 100644 --- a/.github/workflows/backend_publish.yml +++ b/.github/workflows/backend_publish.yml @@ -23,16 +23,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Get the Git commit hash - id: vars - run: | - # Get commit hash - echo "GIT_COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - # Get the tag if exists - TAG=$(git describe --tags --exact-match 2>/dev/null || echo "") - echo "GIT_TAG=$TAG" >> $GITHUB_ENV - - name: Log in to GitHub Container Registry uses: docker/login-action@v2 with: @@ -40,15 +30,18 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Determine Image Tag + id: tag + run: | + # Try to find a Git tag, otherwise use the short commit hash + TAG=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD) + echo "Tag or Commit: $TAG" + echo "::set-output name=image_tag::$TAG" + - name: Build and Publish Docker Image - working-directory: backend - run: ./gradlew bootBuildImage - env: - GITHUB_REPOSITORY: ${{ github.repository }} - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GIT_TAG: ${{ env.GIT_TAG }} # Pass the tag to Gradle - GIT_COMMIT_HASH: ${{ env.GIT_COMMIT_HASH }} # Pass the commit hash to Gradle + run: | + ./backend/gradlew bootBuildImage --imageName=ghcr.io/${{ github.repository }}:${{ steps.tag.outputs.image_tag }} + ./backend/gradlew bootBuildImage --imageName=ghcr.io/${{ github.repository }}:latest - name: Verify image run: docker images