From 53bdc596a5dc0a4ed1076b3a9a7e34669b4bbe6d Mon Sep 17 00:00:00 2001 From: Henry Rausch <44985923+HRA42@users.noreply.github.com> Date: Thu, 16 Nov 2023 23:37:00 +0100 Subject: [PATCH 1/4] Build container image with support for both Linux/amd64 and Linux/arm64 platforms. --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 762c2eb1..a3aacc2e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,6 +12,7 @@ jobs: uses: actions/checkout@v2 - name: Build container image + platforms: linux/amd64,linux/arm64 run: | docker build \ --tag ghcr.io/cp6/my-idlers:$(echo $GITHUB_SHA | head -c7) \ From 27a0cd494ae5496d5e1807014dc8c08e7820b221 Mon Sep 17 00:00:00 2001 From: Henry Rausch <44985923+HRA42@users.noreply.github.com> Date: Thu, 16 Nov 2023 23:38:46 +0100 Subject: [PATCH 2/4] Update tags in GitHub Actions workflow This commit updates the tags in the GitHub Actions workflow for building Docker images. The previous tags `ghcr.io/cp6/my-idlers` are replaced with `ghcr.io/hra42/my-idlers-arm64`. This change ensures that the correct tags are used for the Docker image. --- .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 a3aacc2e..64947fac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,8 +15,8 @@ jobs: platforms: linux/amd64,linux/arm64 run: | docker build \ - --tag ghcr.io/cp6/my-idlers:$(echo $GITHUB_SHA | head -c7) \ - --tag ghcr.io/cp6/my-idlers:latest \ + --tag ghcr.io/hra42/my-idlers-arm64:$(echo $GITHUB_SHA | head -c7) \ + --tag ghcr.io/hra42/my-idlers-arm64:latest \ . - name: Container registry login run: | From 0c3dd6b7e2567353dda1d5717b866dae1e4bd75c Mon Sep 17 00:00:00 2001 From: Henry Rausch <44985923+HRA42@users.noreply.github.com> Date: Thu, 16 Nov 2023 23:41:33 +0100 Subject: [PATCH 3/4] Update docker image push configuration Changed the repository for pushing the docker image to GHCR from `ghcr.io/cp6/my-idlers` to `ghcr.io/hra42/my-idlers-arm64` in order to align with the updated repository naming convention. --- .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 64947fac..aed5e705 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,5 +25,5 @@ jobs: - name: Push image to GHCR if: github.ref == 'refs/heads/main' run: | - docker push ghcr.io/cp6/my-idlers:$(echo $GITHUB_SHA | head -c7) - docker push ghcr.io/cp6/my-idlers:latest + docker push ghcr.io/hra42/my-idlers-arm64:$(echo $GITHUB_SHA | head -c7) + docker push ghcr.io/hra42/my-idlers-arm64:latest From 32580be6b42e509cd2edf3286527be40125e5c73 Mon Sep 17 00:00:00 2001 From: Henry Rausch <44985923+HRA42@users.noreply.github.com> Date: Thu, 16 Nov 2023 23:46:25 +0100 Subject: [PATCH 4/4] Build and push Docker image with Buildx The commit adds steps to build and push a Docker image using Buildx in the GitHub Actions workflow. It includes checking out the repository, installing the cosign tool, setting up Docker buildx, logging into the Docker registry, extracting metadata for Docker, and finally building and pushing the Docker image with the specified tags and platforms. The commit ensures that the image is only pushed when the event name is not a pull request. --- .github/workflows/main.yml | 92 +++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aed5e705..a7700142 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,29 +1,79 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + on: push: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + jobs: build: - name: Build, push, and deploy + runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@main + with: + cosign-release: 'v1.11.0' + + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + latest + - - name: Checkout - uses: actions/checkout@v2 - - - name: Build container image - platforms: linux/amd64,linux/arm64 - run: | - docker build \ - --tag ghcr.io/hra42/my-idlers-arm64:$(echo $GITHUB_SHA | head -c7) \ - --tag ghcr.io/hra42/my-idlers-arm64:latest \ - . - - name: Container registry login - run: | - echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin - - - name: Push image to GHCR - if: github.ref == 'refs/heads/main' - run: | - docker push ghcr.io/hra42/my-idlers-arm64:$(echo $GITHUB_SHA | head -c7) - docker push ghcr.io/hra42/my-idlers-arm64:latest + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v2 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max