1
+ # Based on https://docs.docker.com/build/ci/github-actions/multi-platform/
1
2
name : Docker
2
3
3
4
on :
12
13
13
14
env :
14
15
REGISTRY : ghcr.io
15
- IMAGE_NAME : ${{ github.repository }}
16
+ ORGANIZATION : singlestore-labs
17
+
18
+ permissions :
19
+ contents : read
20
+ packages : write
21
+ attestations : write
22
+ id-token : write
16
23
17
24
jobs :
18
25
build :
@@ -24,15 +31,27 @@ jobs:
24
31
- linux/amd64
25
32
- linux/arm64
26
33
27
- permissions :
28
- contents : read
29
- packages : write
30
- attestations : write
31
- id-token : write
32
-
33
34
steps :
34
- - name : Checkout repository
35
- uses : actions/checkout@v4
35
+ - name : Prepare
36
+ run : |
37
+ platform=${{ matrix.platform }}
38
+ # Store image name in lowercase and platform pair for Docker push
39
+ echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV
40
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
41
+
42
+ - name : Docker meta
43
+ id : meta
44
+ uses : docker/metadata-action@v5
45
+ with :
46
+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
47
+ tags : |
48
+ type=raw,value=latest,enable={{is_default_branch}}
49
+ type=ref,event=branch
50
+ type=ref,event=tag
51
+ type=ref,event=pr
52
+ type=semver,pattern={{version}}
53
+ type=semver,pattern={{major}}.{{minor}}
54
+ type=sha,format=long
36
55
37
56
- name : Set up QEMU
38
57
uses : docker/setup-qemu-action@v3
@@ -47,70 +66,78 @@ jobs:
47
66
username : ${{ github.actor }}
48
67
password : ${{ secrets.GITHUB_TOKEN }}
49
68
50
- - name : Build and cache Docker image
51
- id : push
69
+ - name : Build and push by digest
70
+ id : build
52
71
uses : docker/build-push-action@v6
53
72
with :
54
- context : .
55
73
platforms : ${{ matrix.platform }}
56
- cache-from : type=gha
57
- cache-to : type=gha,mode=max
58
- push : false
74
+ cache-from : type=gha,scope=${{ matrix.platform }}
75
+ cache-to : type=gha,scope=${{ matrix.platform }},mode=max
76
+ labels : ${{ steps.meta.outputs.labels }}
77
+ outputs : type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.ref == 'refs/heads/main' || github.repository_owner != env.ORGANIZATION }}
78
+
79
+ - name : Export digest
80
+ if : github.ref == 'refs/heads/main' || github.repository_owner != env.ORGANIZATION
81
+ run : |
82
+ mkdir -p /tmp/digests
83
+ digest="${{ steps.build.outputs.digest }}"
84
+ touch "/tmp/digests/${digest#sha256:}"
85
+
86
+ - name : Upload digest
87
+ if : github.ref == 'refs/heads/main' || github.repository_owner != env.ORGANIZATION
88
+ uses : actions/upload-artifact@v4
89
+ with :
90
+ name : digests-${{ env.PLATFORM_PAIR }}
91
+ path : /tmp/digests/*
92
+ if-no-files-found : error
93
+ retention-days : 1
59
94
60
- push :
61
- needs : build
95
+ merge :
62
96
runs-on : ubuntu-latest
63
-
64
- permissions :
65
- contents : read
66
- packages : write
67
- attestations : write
68
- id-token : write
69
-
97
+ if : github.ref == 'refs/heads/main' || github.repository_owner != 'singlestore-labs'
98
+ needs :
99
+ - build
70
100
steps :
71
- - name : Checkout repository
72
- uses : actions/checkout@v4
101
+ - name : Prepare
102
+ run : |
103
+ echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV
73
104
74
- - name : Set up QEMU
75
- uses : docker/setup-qemu-action@v3
105
+ - name : Download digests
106
+ uses : actions/download-artifact@v4
107
+ with :
108
+ path : /tmp/digests
109
+ pattern : digests-*
110
+ merge-multiple : true
76
111
77
112
- name : Set up Docker Buildx
78
113
uses : docker/setup-buildx-action@v3
79
114
80
- - name : Log in to the Container registry
81
- uses : docker/login-action@v3
82
- with :
83
- registry : ${{ env.REGISTRY }}
84
- username : ${{ github.actor }}
85
- password : ${{ secrets.GITHUB_TOKEN }}
86
-
87
- - name : Extract metadata (tags, labels) for Docker
115
+ - name : Docker meta
88
116
id : meta
89
117
uses : docker/metadata-action@v5
90
118
with :
91
119
images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
92
120
tags : |
121
+ type=raw,value=latest,enable={{is_default_branch}}
93
122
type=ref,event=branch
94
- type=ref,event=pr
123
+ type=ref,event=tag
95
124
type=semver,pattern={{version}}
96
125
type=semver,pattern={{major}}.{{minor}}
97
126
type=sha,format=long
98
127
99
- - name : Build and push Docker image
100
- id : push
101
- uses : docker/build-push-action@v6
128
+ - name : Log in to the Container registry
129
+ uses : docker/login-action@v3
102
130
with :
103
- context : .
104
- platforms : linux/amd64,linux/arm64
105
- cache-from : type=gha
106
- cache-to : type=gha,mode=max
107
- push : true
108
- tags : ${{ steps.meta.outputs.tags }}
109
- labels : ${{ steps.meta.outputs.labels }}
131
+ registry : ${{ env.REGISTRY }}
132
+ username : ${{ github.actor }}
133
+ password : ${{ secrets.GITHUB_TOKEN }}
110
134
111
- - name : Generate artifact attestation
112
- uses : actions/attest-build-provenance@v1
113
- with :
114
- subject-name : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
115
- subject-digest : ${{ steps.push.outputs.digest }}
116
- push-to-registry : true
135
+ - name : Create manifest list and push
136
+ working-directory : /tmp/digests
137
+ run : |
138
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
139
+ $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
140
+
141
+ - name : Inspect image
142
+ run : |
143
+ docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
0 commit comments