From 5cd24b3aafabd68e9f3e301233e28df134a56717 Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sun, 3 Nov 2024 21:19:29 +0100 Subject: [PATCH 1/7] Expand Docker image tagging --- .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..96c655e56 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]+ + 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=ref,event=branch + type=ref,event=pr + - name: Build Docker image run: ./gradlew bootBuildImage - - name: Docker Tag and Build - 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} + - name: Push image + uses: akhilerm/tag-push-action@v2.1.0 + with: + src: app:latest + dst: | + ${{ steps.meta.outputs.tags }} From 51c883cfde5ae610ec53e30d3d08dfa4158edd3b Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sun, 3 Nov 2024 22:30:26 +0100 Subject: [PATCH 2/7] Fix docker tag push error --- .github/workflows/build-and-publish-image.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-publish-image.yml b/.github/workflows/build-and-publish-image.yml index 96c655e56..6a7fcc4b4 100644 --- a/.github/workflows/build-and-publish-image.yml +++ b/.github/workflows/build-and-publish-image.yml @@ -51,9 +51,8 @@ jobs: - name: Build Docker image run: ./gradlew bootBuildImage - - name: Push image - uses: akhilerm/tag-push-action@v2.1.0 - with: - src: app:latest - dst: | - ${{ steps.meta.outputs.tags }} + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + app:latest From f0f0a586cab1a8df8380c5d19712b35f0b4b2e5d Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Sun, 3 Nov 2024 22:33:03 +0100 Subject: [PATCH 3/7] Remove working dir --- .github/workflows/build-and-publish-image.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-and-publish-image.yml b/.github/workflows/build-and-publish-image.yml index 6a7fcc4b4..cd69f0658 100644 --- a/.github/workflows/build-and-publish-image.yml +++ b/.github/workflows/build-and-publish-image.yml @@ -52,7 +52,6 @@ jobs: run: ./gradlew bootBuildImage - name: Create manifest list and push - working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ app:latest From 03edf8a82e8118229926d2b2aa0e2dbd33c99b0a Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Tue, 5 Nov 2024 18:31:43 +0100 Subject: [PATCH 4/7] Rework push logic --- .github/workflows/build-and-publish-image.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-publish-image.yml b/.github/workflows/build-and-publish-image.yml index cd69f0658..367d5c9bb 100644 --- a/.github/workflows/build-and-publish-image.yml +++ b/.github/workflows/build-and-publish-image.yml @@ -51,7 +51,9 @@ jobs: - name: Build Docker image run: ./gradlew bootBuildImage - - name: Create manifest list and push + - name: Push docker image run: | - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - app:latest + for tag in $(jq -r '.tags | join(" ")' <<< "${{ steps.meta.outputs.metadata }}"); do + docker image tag app:latest $tag + done + docker image push --all-tags ghcr.io/${{ github.repository_owner }}/gamma From f92cc22ce2fa929ee0d11a58a8b1e4d28d15a7b9 Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Tue, 5 Nov 2024 18:45:41 +0100 Subject: [PATCH 5/7] Use JSON --- .github/workflows/build-and-publish-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-image.yml b/.github/workflows/build-and-publish-image.yml index 367d5c9bb..c100a7ffe 100644 --- a/.github/workflows/build-and-publish-image.yml +++ b/.github/workflows/build-and-publish-image.yml @@ -53,7 +53,7 @@ jobs: - name: Push docker image run: | - for tag in $(jq -r '.tags | join(" ")' <<< "${{ steps.meta.outputs.metadata }}"); do + 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 From 8e7c3c4fd82605e908acc5b75a79ece0608c7e83 Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Wed, 6 Nov 2024 16:32:15 +0100 Subject: [PATCH 6/7] Change from main branch tag to edge tag Co-authored-by: Goostaf --- .github/workflows/build-and-publish-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-image.yml b/.github/workflows/build-and-publish-image.yml index c100a7ffe..8877fd957 100644 --- a/.github/workflows/build-and-publish-image.yml +++ b/.github/workflows/build-and-publish-image.yml @@ -45,7 +45,7 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha - type=ref,event=branch + type=edge type=ref,event=pr - name: Build Docker image From 678cf6f7851285c8578a9ae6a6d1ddd750f7f2a0 Mon Sep 17 00:00:00 2001 From: Oscar Eriksson Date: Thu, 7 Nov 2024 13:14:19 +0100 Subject: [PATCH 7/7] Extend allowed tag pattern --- .github/workflows/build-and-publish-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-image.yml b/.github/workflows/build-and-publish-image.yml index 8877fd957..50acb64ef 100644 --- a/.github/workflows/build-and-publish-image.yml +++ b/.github/workflows/build-and-publish-image.yml @@ -4,7 +4,7 @@ on: push: branches: [main] tags: - - v[0-9]+.[0-9]+.[0-9]+ + - v[0-9]+.[0-9]+.[0-9]+* pull_request: branches: [main]