From 7535bec72f1cdd004562e798ec4762e3a7016f49 Mon Sep 17 00:00:00 2001 From: julialawrence <98329494+julialawrence@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:52:49 +0100 Subject: [PATCH 1/3] Going back to on-tag. --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8fd1078..e148f4b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,8 +2,8 @@ name: Build and Push Docker Image on: push: - branches: - - main + tags: + - '*' jobs: build-and-push: From c5da8926c75b0172def20ed86d1cdf0c13ed602b Mon Sep 17 00:00:00 2001 From: julialawrence <98329494+julialawrence@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:56:55 +0100 Subject: [PATCH 2/3] Fixing latest tag. --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e148f4b..020e042 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,10 +21,11 @@ jobs: - name: Build and Push Docker Image run: | + LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) docker buildx create --use docker buildx build \ --platform linux/amd64,linux/arm64 \ - -t ghcr.io/${{ github.repository }}:${{ github.ref }} \ + -t ghcr.io/${{ github.repository }}:$LATEST_TAG \ -t ghcr.io/${{ github.repository }}:latest \ -f Dockerfile . docker buildx stop ${GITHUB_RUN_ID} From 5f05956e12a36f86b8d5ff58fd525a28b935f652 Mon Sep 17 00:00:00 2001 From: julialawrence <98329494+julialawrence@users.noreply.github.com> Date: Thu, 19 Oct 2023 08:05:56 +0100 Subject: [PATCH 3/3] Rewriting the workflow --- .github/workflows/main.yml | 50 ++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 020e042..50711f2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,12 @@ on: push: tags: - '*' - + release: + types: [published] + +permissions: + packages: write + contents: read jobs: build-and-push: runs-on: ubuntu-latest @@ -13,25 +18,24 @@ jobs: - name: Checkout Repository uses: actions/checkout@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to GitHub Container Registry - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Build and Push Docker Image - run: | - LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) - docker buildx create --use - docker buildx build \ - --platform linux/amd64,linux/arm64 \ - -t ghcr.io/${{ github.repository }}:$LATEST_TAG \ - -t ghcr.io/${{ github.repository }}:latest \ - -f Dockerfile . - docker buildx stop ${GITHUB_RUN_ID} - env: - DOCKER_CLI_AGGREGATE: 1 - - - name: Clean up - run: | - docker buildx rm --all + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: | + ghcr.io/${{ github.repository }} + + - name: Build and push Docker images + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}