77 - main
88 pull_request :
99
10+ env :
11+ REGISTRY : ghcr.io
12+ IMAGE_NAME : query-doctor/sync
13+
1014jobs :
1115 build :
1216 name : Build container
13- env :
14- REGISTRY : ghcr.io
15- IMAGE_NAME : query-doctor/sync
1617 permissions :
1718 id-token : write
1819 contents : read
@@ -37,15 +38,28 @@ jobs:
3738 uses : docker/metadata-action@v5
3839 with :
3940 images : ${{ env.IMAGE_NAME }}
41+ tags : |
42+ type=ref,event=branch
43+ type=semver,pattern={{version}}
44+ type=semver,pattern={{major}}.{{minor}}
45+
4046 - uses : actions/checkout@v3
4147 - name : Login to ghcr
4248 uses : docker/login-action@v3
4349 with :
4450 registry : ${{ env.REGISTRY }}
45- username : " ${{ github.actor }}"
51+ username : " ${{ github.repository_owner }}"
4652 password : " ${{ secrets.GITHUB_TOKEN }}"
4753 - name : Setup Docker Buildx
54+ id : buildx
4855 uses : docker/setup-buildx-action@v3
56+ - name : Cache Docker layers
57+ uses : actions/cache@v4
58+ with :
59+ path : /tmp/.buildx-cache
60+ key : ${{ runner.os }}-buildx-${{ github.sha }}
61+ restore-keys : |
62+ ${{ runner.os }}-buildx-
4963 - name : Set sync_version from deno.json
5064 run : |
5165 platform=${{ matrix.platform }}
@@ -57,18 +71,90 @@ jobs:
5771 with :
5872 context : .
5973 file : Dockerfile
74+ builder : ${{ steps.buildx.outputs.name }}
75+ push : ${{ github.event_name == 'push' }}
6076 outputs : type=docker
6177 platforms : ${{ matrix.platform }}
62- push : ${{ github.event_name == 'push' }}
63- tags : |
64- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.sync_version }}
65- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
66- - name : Attest
67- uses : actions/attest-build-provenance@v2
78+ tags : ${{ steps.meta.outputs.tags }}
79+ cache-from : type=local,src=/tmp/.buildx-cache
80+ cache-to : type=local,mode=max,dest=/tmp/.buildx-cache-new
81+ # This ugly bit is necessary if you don't want your cache to grow forever
82+ # until it hits GitHub's limit of 5GB.
83+ # Temp fix
84+ # https://github.com/docker/build-push-action/issues/252
85+ # https://github.com/moby/buildkit/issues/1896
86+ - name : Move cache
87+ run : |
88+ rm -rf /tmp/.buildx-cache
89+ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
90+ - name : Export digest
91+ if : ${{ github.event_name == 'push' }}
92+ run : |
93+ mkdir -p ${{ runner.temp }}/digests
94+ digest="${{ steps.build.outputs.digest }}"
95+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
96+ - name : Upload digest
97+ uses : actions/upload-artifact@v4
6898 if : ${{ github.event_name == 'push' }}
6999 with :
70- subject-name : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
71- subject-digest : ${{ steps.build.outputs.digest }}
72- push-to-registry : true
100+ name : digests-${{ env.PLATFORM_PAIR }}
101+ path : ${{ runner.temp }}/digests/*
102+ if-no-files-found : error
103+ retention-days : 1
104+
105+ # TODO: Attest is not working for some reason
106+ # - name: Attest
107+ # uses: actions/attest-build-provenance@v2
108+ # with:
109+ # subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
110+ # subject-digest: ${{ steps.build.outputs.digest }}
111+ # push-to-registry: true
112+
113+ merge :
114+ runs-on : ubuntu-24.04
115+ if : ${{ github.event_name == 'push' }}
116+ permissions :
117+ id-token : write
118+ contents : read
119+ attestations : write
120+ packages : write
121+ needs :
122+ - build
123+ steps :
124+ - name : Download digests
125+ uses : actions/download-artifact@v4
126+ with :
127+ path : ${{ runner.temp }}/digests
128+ pattern : digests-*
129+ merge-multiple : true
73130
74-
131+ - name : Login to ghcr
132+ uses : docker/login-action@v3
133+ with :
134+ registry : ${{ env.REGISTRY }}
135+ username : " ${{ github.actor }}"
136+ password : " ${{ secrets.GITHUB_TOKEN }}"
137+
138+ - name : Set up Docker Buildx
139+ uses : docker/setup-buildx-action@v3
140+
141+ - name : Docker meta
142+ id : meta
143+ uses : docker/metadata-action@v5
144+ with :
145+ images : ${{ env.IMAGE_NAME }}
146+ tags : |
147+ type=ref,event=branch
148+ type=ref,event=pr
149+ type=semver,pattern={{version}}
150+ type=semver,pattern={{major}}.{{minor}}
151+
152+ - name : Create manifest list and push
153+ working-directory : ${{ runner.temp }}/digests
154+ run : |
155+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
156+ $(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)
157+
158+ - name : Inspect image
159+ run : |
160+ docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
0 commit comments