@@ -64,29 +64,18 @@ jobs:
64
64
- name : Checkout repository
65
65
uses : actions/checkout@v4
66
66
67
- # Install the cosign tool except on PR
68
- - name : Install cosign
69
- if : github.event_name != 'pull_request'
70
- uses : sigstore/cosign-installer@v3
71
-
72
- # Add support for more platforms with QEMU (optional)
73
- # https://github.com/docker/setup-qemu-action
74
- - name :
75
- uses : docker/setup-qemu-action@v3
67
+ - name : Prepare variables
68
+ id : vars
69
+ run : |
70
+ SURFIX=$(echo ${{ matrix.platform }} | cut -d'/' -f2)
71
+ echo "SURFIX=$SURFIX" >> $GITHUB_OUTPUT
72
+ # Generate a unique local tag for the image
73
+ echo "LOCAL_TAG=local-${{ github.sha }}-$SURFIX" >> $GITHUB_OUTPUT
76
74
77
75
# Set up BuildKit Docker container builder
78
76
- name : Set up Docker Buildx
79
77
uses : docker/setup-buildx-action@v3
80
78
81
- # Login against a Docker registry except on PR
82
- - name : Log into registry ${{ env.REGISTRY }}
83
- if : github.event_name != 'pull_request'
84
- uses : docker/login-action@v3
85
- with :
86
- registry : ${{ env.REGISTRY }}
87
- username : ${{ github.actor }}
88
- password : ${{ secrets.GITHUB_TOKEN }}
89
-
90
79
# Extract metadata (tags, labels) for Docker
91
80
- name : Extract Docker metadata
92
81
id : meta
@@ -101,30 +90,32 @@ jobs:
101
90
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
102
91
images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
103
92
104
- # Build and push Docker image with platform-specific tag
105
- - name : Build and push Docker image
106
- id : build-and-push
93
+ # Build and export Docker image for each platform (without pushing)
94
+ - name : Build Docker image
95
+ id : build
107
96
uses : docker/build-push-action@v6
108
97
with :
109
98
context : .
110
99
pull : true
111
- push : ${{ github.event_name != 'pull_request' }}
112
- tags : ${{ steps.meta.outputs.tags }}-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
100
+ push : false
101
+ load : true # Export to local Docker instead of pushing
102
+ tags : ${{ steps.vars.outputs.LOCAL_TAG }}
113
103
labels : ${{ steps.meta.outputs.labels }}
114
104
platforms : ${{ matrix.platform }}
115
105
cache-from : type=gha,scope=${{ matrix.platform }}
116
106
cache-to : type=gha,mode=max,scope=${{ matrix.platform }}
117
107
build-args : GITHUB_BUILD=true,VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
108
+ outputs : type=docker,dest=/tmp/image-${{ steps.vars.outputs.SURFIX }}.tar
118
109
119
- # Sign the platform specific image
120
- - name : Sign the published Docker image
121
- if : ${{ github.event_name != 'pull_request' }}
122
- env :
123
- TAGS : ${{ steps.meta .outputs.tags }}
124
- DIGEST : ${{ steps.build-and-push .outputs.digest }}
125
- run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
110
+ # Upload the tarball as an artifact
111
+ - name : Upload image artifact
112
+ uses : actions/upload-artifact@v4
113
+ with :
114
+ name : docker-image- ${{ steps.vars .outputs.SURFIX }}
115
+ path : /tmp/image- ${{ steps.vars .outputs.SURFIX }}.tar
116
+ retention-days : 1
126
117
127
- merge :
118
+ merge-and-push :
128
119
needs : build
129
120
runs-on : ubuntu-latest
130
121
if : github.event_name != 'pull_request'
@@ -137,13 +128,23 @@ jobs:
137
128
- name : Checkout repository
138
129
uses : actions/checkout@v4
139
130
131
+ # Install the cosign tool
132
+ - name : Install cosign
133
+ uses : sigstore/cosign-installer@v3
134
+
135
+ # Set up Docker Buildx
136
+ - name : Set up Docker Buildx
137
+ uses : docker/setup-buildx-action@v3
138
+
139
+ # Log into registry
140
140
- name : Log into registry ${{ env.REGISTRY }}
141
141
uses : docker/login-action@v3
142
142
with :
143
143
registry : ${{ env.REGISTRY }}
144
144
username : ${{ github.actor }}
145
145
password : ${{ secrets.GITHUB_TOKEN }}
146
146
147
+ # Extract Docker metadata for tagging
147
148
- name : Extract Docker metadata
148
149
id : meta
149
150
uses : docker/metadata-action@v5
@@ -157,26 +158,46 @@ jobs:
157
158
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
158
159
images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
159
160
160
- - name : Install cosign
161
- uses : sigstore/cosign-installer@v3
161
+ # Download all image artifacts
162
+ - name : Download AMD64 image
163
+ uses : actions/download-artifact@v4
164
+ with :
165
+ name : docker-image-amd64
166
+ path : /tmp
162
167
163
- - name : Set up Docker Buildx
164
- uses : docker/setup-buildx-action@v3
168
+ - name : Download ARM64 image
169
+ uses : actions/download-artifact@v4
170
+ with :
171
+ name : docker-image-arm64
172
+ path : /tmp
173
+
174
+ # Load images into Docker
175
+ - name : Load images
176
+ run : |
177
+ docker load --input /tmp/image-amd64.tar
178
+ docker load --input /tmp/image-arm64.tar
165
179
166
- - name : Create and push manifest
180
+ # Create manifest lists and push
181
+ - name : Create and push manifest lists
167
182
run : |
168
183
TAGS="${{ steps.meta.outputs.tags }}"
169
184
for TAG in $TAGS; do
185
+ # Tag the local images with their registry counterparts
186
+ docker tag local-${{ github.sha }}-amd64 $TAG-amd64
187
+ docker tag local-${{ github.sha }}-arm64 $TAG-arm64
188
+
189
+ # Push individual platform images
190
+ # docker push $TAG-amd64
191
+ # docker push $TAG-arm64
192
+
170
193
# Create manifest list and push it
171
194
docker buildx imagetools create -t $TAG \
172
195
$TAG-amd64 \
173
196
$TAG-arm64
174
197
done
175
198
176
- - name : Install cosign
177
- uses : sigstore/cosign-installer@v3
178
-
179
- - name : Sign the manifest
199
+ # Sign the manifest
200
+ - name : Sign the manifests
180
201
env :
181
202
TAGS : ${{ steps.meta.outputs.tags }}
182
203
run : |
0 commit comments