From 0d1734d0fec4115b01a80b3f8a9b989e0d018eab Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sun, 10 Nov 2024 18:50:57 +0100 Subject: [PATCH] Expand Docker image tagging (#919) Co-authored-by: Goostaf --- .github/workflows/build-and-publish-image.yml | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-publish-image.yml b/.github/workflows/build-and-publish-image.yml index 3eb6b4503..50acb64ef 100644 --- a/.github/workflows/build-and-publish-image.yml +++ b/.github/workflows/build-and-publish-image.yml @@ -1,8 +1,12 @@ name: Build Docker Image + on: push: + branches: [main] tags: - - v[0-9]+.[0-9]+.[0-9]+ + - v[0-9]+.[0-9]+.[0-9]+* + pull_request: + branches: [main] jobs: build: @@ -31,11 +35,25 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/gamma + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + type=edge + type=ref,event=pr + - name: Build Docker image run: ./gradlew bootBuildImage - - name: Docker Tag and Build + - name: Push docker image run: | - version=${GITHUB_REF#refs/tags/} - docker tag app:latest ghcr.io/${{ github.repository_owner }}/gamma:${version} - docker push ghcr.io/${{ github.repository_owner }}/gamma:${version} + for tag in $(jq -r '.tags | join(" ")' <<< $DOCKER_METADATA_OUTPUT_JSON ); do + docker image tag app:latest $tag + done + docker image push --all-tags ghcr.io/${{ github.repository_owner }}/gamma