66
77env :
88 GHCR_REPO : ghcr.io/${{ github.repository }}
9+ DOCKER_PUSH : true
10+ LOCAL_KIND : false
911
1012jobs :
11- build :
12- name : Build and Push
13- strategy :
14- fail-fast : false
15- matrix :
16- runner : [buildjet-2vcpu-ubuntu-2204-arm, buildjet-2vcpu-ubuntu-2204]
17- include :
18- - runner : buildjet-2vcpu-ubuntu-2204-arm
19- platform : linux/arm64
20- - runner : buildjet-2vcpu-ubuntu-2204
21- platform : linux/amd64
22- runs-on : ${{ matrix.runner }}
23-
13+ build-and-push :
14+ runs-on : ubuntu-latest
15+
2416 permissions :
2517 contents : read
2618 packages : write
2719
2820 steps :
29- - name : Prepare
30- run : |
31- platform=${{ matrix.platform }}
32- echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
21+ - name : Checkout
22+ uses : actions/checkout@v4
3323
3424 - name : Docker meta
3525 id : meta
@@ -38,78 +28,33 @@ jobs:
3828 images : ${{ env.GHCR_REPO }}
3929
4030 - name : Login to GHCR
31+ if : env.DOCKER_PUSH == 'true'
4132 uses : docker/login-action@v3
4233 with :
4334 registry : ghcr.io
4435 username : ${{ github.repository_owner }}
4536 password : ${{ secrets.GITHUB_TOKEN }}
4637
38+ - name : Set up QEMU
39+ uses : docker/setup-qemu-action@v3
40+
4741 - name : Set up Docker Buildx
4842 uses : docker/setup-buildx-action@v3
4943
50- - name : Build and push by digest
51- id : build
44+ - name : Build and push
5245 uses : docker/build-push-action@v5
5346 with :
54- platforms : ${{ matrix.platform }}
55- push : true
47+ push : ${{ env.DOCKER_PUSH == 'true' }}
48+ load : ${{ env.LOCAL_KIND == 'true' }}
49+ no-cache : ${{ env.LOCAL_KIND == 'true' }}
50+ platforms : ${{ env.LOCAL_KIND == 'true' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
51+ tags : ${{ steps.meta.outputs.tags }}
5652 labels : ${{ steps.meta.outputs.labels }}
57- outputs : type=image,"name=${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=true
58-
59- - name : Export digest
60- run : |
61- mkdir -p /tmp/digests
62- digest="${{ steps.build.outputs.digest }}"
63- touch "/tmp/digests/${digest#sha256:}"
64-
65- - name : Upload digest
66- uses : actions/upload-artifact@v4
67- with :
68- name : digests-${{ env.PLATFORM_PAIR }}
69- path : /tmp/digests/*
70- if-no-files-found : error
71- retention-days : 1
72-
73- merge :
74- runs-on : ubuntu-latest
75- needs :
76- - build
77- permissions :
78- contents : read
79- packages : write
80- steps :
81- - name : Download digests
82- uses : actions/download-artifact@v4
83- with :
84- path : /tmp/digests
85- pattern : digests-*
86- merge-multiple : true
87-
88- - name : Login to GHCR
89- uses : docker/login-action@v3
90- with :
91- registry : ghcr.io
92- username : ${{ github.repository_owner }}
93- password : ${{ secrets.GITHUB_TOKEN }}
94-
95- - name : Set up Docker Buildx
96- uses : docker/setup-buildx-action@v3
97-
98- - name : Docker meta
99- id : meta
100- uses : docker/metadata-action@v5
101- with :
102- images : ${{ env.GHCR_REPO }}
103-
104- - name : Create manifest list and push
105- working-directory : /tmp/digests
106- run : |
107- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
108- $(printf '${{ env.GHCR_REPO }}@sha256:%s ' *)
109-
110- - name : Inspect image
111- run : |
112- docker buildx imagetools inspect ${{ env.GHCR_REPO }}:${{ steps.meta.outputs.version }}
53+ build-args : |
54+ CACHEBUST=${{ github.sha }}
55+ COMMIT_HASH=${{ github.sha }}
56+ cache-from : ${{ env.LOCAL_KIND == 'true' && '' || 'type=gha' }}
57+ cache-to : ${{ env.LOCAL_KIND == 'true' && '' || 'type=gha,mode=max' }}
11358
11459 test :
11560 runs-on : ubuntu-latest
0 commit comments