Skip to content

Commit

Permalink
chore: enhance image build process
Browse files Browse the repository at this point in the history
  • Loading branch information
davidecavestro committed Dec 24, 2024
1 parent cc4044a commit d5e5a11
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: |
Expand All @@ -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:
Expand Down

0 comments on commit d5e5a11

Please sign in to comment.