Skip to content

Commit

Permalink
feat(CD): add latest tag
Browse files Browse the repository at this point in the history
  • Loading branch information
otahirs authored Sep 12, 2024
1 parent d963dbd commit dd3caa1
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions .github/workflows/backend_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,25 @@ 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:
registry: ghcr.io
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

0 comments on commit dd3caa1

Please sign in to comment.