From d5e5a119dc19c162ec3ac505749d0b4819ebec72 Mon Sep 17 00:00:00 2001 From: Davide Cavestro Date: Tue, 24 Dec 2024 11:51:23 +0100 Subject: [PATCH] chore: enhance image build process --- .github/workflows/build_and_publish.yml | 33 ++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 414c6ea..a15a172 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -23,6 +23,10 @@ jobs: with: driver-opts: image=moby/buildkit:latest + - name: Install docker-squash + run: | + pip install docker-squash + - name: Log in to Docker Hub uses: docker/login-action@v3 with: @@ -50,14 +54,22 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - - name: Install docker-squash - run: | - pip install docker-squash + - name: Setup jq + uses: dcarbone/install-jq-action@v3 + with: + version: "1.7" + force: true - name: Squash the image run: | docker pull ghcr.io/${{ github.repository }}:${{ github.ref_name }}-huge && \ - docker save ghcr.io/${{ github.repository }}:${{ github.ref_name }}-huge | docker-squash -t ghcr.io/${{ github.repository }}:${{ github.ref_name }} | docker load + docker pull debian:bookworm && \ + FROM_LAYER=$(docker inspect --format='{{json .RootFS.Layers}}' debian:bookworm | jq -r '.[-1]') && \ + echo "FROM_LAYER: $FROM_LAYER" && \ + docker-squash \ + --from $FROM_LAYER \ + --tag ghcr.io/${{ github.repository }}:${{ github.ref_name }} \ + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-huge - name: Push squashed image run: | @@ -73,19 +85,6 @@ jobs: docker push ${{ github.repository }}:latest if: startsWith(github.ref, 'refs/tags/') - - name: Push latest image - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: | - ${{ github.repository }}:latest - ghcr.io/${{ github.repository }}:latest - cache-from: type=gha - cache-to: type=gha,mode=max - if: startsWith(github.ref, 'refs/tags/') - - name: Docker Hub Description uses: peter-evans/dockerhub-description@v4 with: