From a88c2dc403a6ba4eedda755b65a1f75bd066e801 Mon Sep 17 00:00:00 2001 From: Guillaume Berche Date: Thu, 17 Oct 2024 11:18:02 +0200 Subject: [PATCH] Refine github workflow to publish tagged image on tag --- ...h.yml => docker-publish-latest-commit.yml} | 7 --- .github/workflows/docker-publish-tags.yml | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) rename .github/workflows/{docker-publish.yml => docker-publish-latest-commit.yml} (82%) create mode 100644 .github/workflows/docker-publish-tags.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish-latest-commit.yml similarity index 82% rename from .github/workflows/docker-publish.yml rename to .github/workflows/docker-publish-latest-commit.yml index 5957e2f..b208012 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish-latest-commit.yml @@ -31,13 +31,6 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and export to ghcr - uses: docker/build-push-action@v3 - with: - context: . - load: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest - - name: Build and push image to github container registry uses: docker/build-push-action@v3 with: diff --git a/.github/workflows/docker-publish-tags.yml b/.github/workflows/docker-publish-tags.yml new file mode 100644 index 0000000..6342bb4 --- /dev/null +++ b/.github/workflows/docker-publish-tags.yml @@ -0,0 +1,45 @@ +name: Build on tags + +on: + push: + tags: [ '*'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + + #--- Set permissions to ephemeral GITHUB_TOKEN for job actions + permissions: + contents: read + packages: write + + steps: + - name: Checkout and download repository to workflow runner + uses: actions/checkout@v3 + + - name: Set up docker buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to github container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + #See https://stackoverflow.com/a/70468025/1484823 about fetching and formatting tags in current commit + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push image to github container registry + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.labels }}