From 45b6ed595781f778d8169f22102a7f90ec60d777 Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Fri, 13 Oct 2023 11:08:27 -0400 Subject: [PATCH 1/5] Run build action on push Hard-code tag for testing Fix Docker image name Attempt to build multi-arch image Free up runner disk space and disable Docker parallelism Attempt to build arm64 image only Test build on BuildJet arm64 runner Attempt to build images on native runners Remove duplicate 'runs-on' key Fix YAML syntax error Check ghcr.io login first Fix another YAML syntax issue This better work... Run build only on tags --- .github/workflows/build-image.yml | 87 +++++++++++++++++++++++-------- Dockerfile | 2 +- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index e477e2b..a068fa9 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -1,4 +1,4 @@ -name: Create and publish a Docker image +name: Create and publish a multi-architecture Docker image on: push: @@ -6,39 +6,82 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} + IMAGE_NAME: ghcr.io/${{ github.repository }} jobs: - build-and-push-image: - runs-on: ubuntu-latest + build-image: + strategy: + fail-fast: false + matrix: + runner: [ubuntu-latest, buildjet-4vcpu-ubuntu-2204-arm] + runs-on: ${{ matrix.runner }} permissions: contents: read packages: write - steps: - name: Checkout repository - uses: actions/checkout@v2 - - - name: Log in to the Container registry - uses: docker/login-action@v2.1.0 + uses: actions/checkout@v4 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_NAME }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to the Container Registry + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 - - name: Extract metadata (tags, labels) for Docker + merge-image: + runs-on: ubuntu-latest + needs: + - build-image + steps: + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta id: meta - uses: docker/metadata-action@v4.1.1 + uses: docker/metadata-action@v5 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=semver,pattern=v{{version}} - - - name: Build and push Docker image - uses: docker/build-push-action@v3.2.0 + images: ${{ env.IMAGE_NAME }} + - name: Login to the Container Registry + uses: docker/login-action@v3 with: - context: . - push: true - tags: | - ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - 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") \ + $(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *) + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} diff --git a/Dockerfile b/Dockerfile index f3a7f01..bc43dc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ # - Go to Preferences > Resources > Memory # - and give docker more memory (eg: 4gb) -FROM haskell:8 +FROM haskell:8-slim WORKDIR /opt/erd From 0fdcdb8187b15edcf0e6664f9135b71fdbbb3140 Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Wed, 18 Oct 2023 00:21:54 -0400 Subject: [PATCH 2/5] Test Docker image after building --- .github/workflows/build-image.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index a068fa9..021f5e6 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -34,19 +34,28 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push by digest + - name: Build and export the image to Docker + uses: docker/build-push-action@v5 + with: + context: . + load: true + tags: ${{ env.IMAGE_NAME }}:test + - name: Test the image + run: | + docker run --rm ${{ env.IMAGE_NAME }}:test < examples/nfldb.er >| out.pdf + - name: Push the image by digest id: build uses: docker/build-push-action@v5 with: context: . labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true - - name: Export digest + - name: Export the digest run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}" - - name: Upload digest + - name: Upload the digest uses: actions/upload-artifact@v3 with: name: digests From 3916c28ffc5a4e8c2afdbb3c731a3efe1cae134f Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Wed, 18 Oct 2023 17:24:48 -0400 Subject: [PATCH 3/5] Store test diagram as an artifact --- .github/workflows/build-image.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 021f5e6..33b6c81 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -26,6 +26,8 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern=v{{version}} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to the Container Registry @@ -42,12 +44,14 @@ jobs: tags: ${{ env.IMAGE_NAME }}:test - name: Test the image run: | - docker run --rm ${{ env.IMAGE_NAME }}:test < examples/nfldb.er >| out.pdf + docker run --rm ${{ env.IMAGE_NAME }}:test < examples/nfldb.er >| nfldb.png - name: Push the image by digest id: build uses: docker/build-push-action@v5 with: context: . + tags: | + ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true - name: Export the digest @@ -62,6 +66,11 @@ jobs: path: /tmp/digests/* if-no-files-found: error retention-days: 1 + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: example-diagram-nfldb + path: nfldb.png merge-image: runs-on: ubuntu-latest From 121446df5fb3479bc053f293e1e79d0d8afb4a0a Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Wed, 18 Oct 2023 17:51:03 -0400 Subject: [PATCH 4/5] Don't push digest with tags --- .github/workflows/build-image.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 33b6c81..a9bf80f 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -26,8 +26,6 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.IMAGE_NAME }} - tags: | - type=semver,pattern=v{{version}} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to the Container Registry @@ -50,8 +48,6 @@ jobs: uses: docker/build-push-action@v5 with: context: . - tags: | - ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true - name: Export the digest From daca9fbf406f1cb02bace2389cbb65798438578b Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Wed, 18 Oct 2023 22:00:19 -0400 Subject: [PATCH 5/5] Test Docker image in interactive mode --- .github/workflows/build-image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index a9bf80f..1144152 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -42,7 +42,7 @@ jobs: tags: ${{ env.IMAGE_NAME }}:test - name: Test the image run: | - docker run --rm ${{ env.IMAGE_NAME }}:test < examples/nfldb.er >| nfldb.png + docker run --rm -i ${{ env.IMAGE_NAME }}:test < examples/nfldb.er >| nfldb.pdf - name: Push the image by digest id: build uses: docker/build-push-action@v5 @@ -66,7 +66,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: example-diagram-nfldb - path: nfldb.png + path: nfldb.pdf merge-image: runs-on: ubuntu-latest