From 2b520cdc1795a4f03ea25718dec2847512178d90 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 17:19:55 +0100 Subject: [PATCH 01/10] Remove the temp line for manual runs --- .github/workflows/publish.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8d533e2..0b0289a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,8 +6,6 @@ on: - main tags: - '*' - - pull_request: # temp while iterating workflow_dispatch: From b3d5a22b5dfbd877b55963386edb70dd72e0ee93 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 17:20:08 +0100 Subject: [PATCH 02/10] Add support for armv7 in the docker build --- .github/workflows/publish.yml | 6 ++++++ Dockerfile | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0b0289a..c692283 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,6 +31,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: arm32v7/armhf, arm64v8/aarch64 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - name: Log in to the Container registry uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 @@ -59,6 +64,7 @@ jobs: uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: context: . + platforms: linux/arm/v7,linux/arm64,linux/amd64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 556e2d2..5780769 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12-slim +FROM --platform=$TARGETPLATFORM python:3.9-slim:3.12-slim LABEL org.opencontainers.image.source=https://github.com/mdiluz/matchy LABEL org.opencontainers.image.description="Matchy matches matchees" LABEL org.opencontainers.image.licenses=Unlicense From 2d1b0560f4334869f14d1bef4891a82daf5d5f5e Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 17:27:44 +0100 Subject: [PATCH 03/10] Cement both trigger types --- .github/workflows/publish.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c692283..3bd7534 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,8 +6,7 @@ on: - main tags: - '*' - - # temp while iterating + pull_request: workflow_dispatch: # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. From 442fc906d886fdcab60e6423dd225b99a800c704 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 17:30:02 +0100 Subject: [PATCH 04/10] Use docker-container driver for multi-plat builds --- .github/workflows/publish.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3bd7534..0f2140a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -42,7 +42,12 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver: docker-container # Use docker-container driver for multi-platform builds + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. - name: Extract metadata (tags, labels) for Docker id: meta From f568d96239bf287fb31eddc8a1ff3f6fbb1426c6 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 17:32:19 +0100 Subject: [PATCH 05/10] Correct the docker base image tag --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5780769..09e4085 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$TARGETPLATFORM python:3.9-slim:3.12-slim +FROM --platform=$TARGETPLATFORM python:3.12-slim LABEL org.opencontainers.image.source=https://github.com/mdiluz/matchy LABEL org.opencontainers.image.description="Matchy matches matchees" LABEL org.opencontainers.image.licenses=Unlicense From e130f0c7a64d69c7d7c0a85e3af0ded8b39dd1cd Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 17:36:28 +0100 Subject: [PATCH 06/10] Skip arm64 as it's not currently needed --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0f2140a..60640b7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,7 +33,7 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: - platforms: arm32v7/armhf, arm64v8/aarch64 + platforms: arm32v7/armhf # arm64v8/aarch64 - no current need for arm64 # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - name: Log in to the Container registry @@ -68,7 +68,7 @@ jobs: uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: context: . - platforms: linux/arm/v7,linux/arm64,linux/amd64 + platforms: linux/arm/v7,linux/amd64 # linux/arm64 no current need for arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From 5cab5fdaaf2f47b2b811d1dfa2504141a86db1e1 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 17:42:39 +0100 Subject: [PATCH 07/10] Move back to python 3.11 Apparently has less issues with gcc https://github.com/docker-library/python/issues/869 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 09e4085..15d6c2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$TARGETPLATFORM python:3.12-slim +FROM --platform=$TARGETPLATFORM python:3.11-slim LABEL org.opencontainers.image.source=https://github.com/mdiluz/matchy LABEL org.opencontainers.image.description="Matchy matches matchees" LABEL org.opencontainers.image.licenses=Unlicense From 0b0494baed6d6a3e8c86a205ebfbe06e31896dba Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 17:50:07 +0100 Subject: [PATCH 08/10] Split out the docker build and final image Try and work around an issue aith gcc in the python armv7 images https://github.com/docker-library/python/issues/869#issuecomment-1744826183 --- Dockerfile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 15d6c2b..1640791 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,19 @@ -FROM --platform=$TARGETPLATFORM python:3.11-slim +# Split out the wheel build into the non-slim image +# See https://github.com/docker-library/python/issues/869 +FROM python:3.12 AS build +COPY requirements.txt ./ +RUN --mount=type=cache,target=/var/cache/buildkit/pip \ + pip wheel --wheel-dir /wheels -r requirements.txt + +FROM python:3.12-slim LABEL org.opencontainers.image.source=https://github.com/mdiluz/matchy LABEL org.opencontainers.image.description="Matchy matches matchees" LABEL org.opencontainers.image.licenses=Unlicense -WORKDIR /usr/src/app COPY requirements.txt ./ -RUN pip install --no-cache-dir -r requirements.txt +COPY --from=build /wheels /wheels +RUN --mount=type=cache,target=/var/cache/buildkit/pip \ + pip install --find-links /wheels --no-index -r requirements.txt + COPY . . CMD ["python", "py/matchy.py"] \ No newline at end of file From 31a1e1560fa381e18e03772effd083ae248083a8 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 18:26:22 +0100 Subject: [PATCH 09/10] Put back the image workdir --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 1640791..b3c9015 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ LABEL org.opencontainers.image.source=https://github.com/mdiluz/matchy LABEL org.opencontainers.image.description="Matchy matches matchees" LABEL org.opencontainers.image.licenses=Unlicense +WORKDIR /usr/src/app COPY requirements.txt ./ COPY --from=build /wheels /wheels RUN --mount=type=cache,target=/var/cache/buildkit/pip \ From 8e1ccb8e14be0a62ed5c514d530c56d1bf6f5d71 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 14 Aug 2024 18:34:48 +0100 Subject: [PATCH 10/10] Cache the docker builds to hopefully save a lot of time --- .github/workflows/publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 60640b7..7d0d549 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -72,6 +72,8 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." - name: Generate artifact attestation