@@ -121,57 +121,65 @@ jobs:
121
121
with :
122
122
sarif_file : snyk.sarif
123
123
124
- # Build the image for production.
125
- #
126
- # TODO: no need to rebuild everything, just copy the testing images we have generated to the production registry
127
- # if we get here and we are building for production.
128
- prodbuild :
124
+ # Use the metadata generated in the `testbuild` step to find all the images
125
+ # that have been built. We copy them one by one to the procuction registry
126
+ # using skopeo. Then we sign the production images too.
127
+ copytoproduction :
128
+ name : Copy images to production
129
129
if : github.event.inputs.environment == 'production' || github.event_name == 'schedule'
130
- name : Build for production
131
130
runs-on : ubuntu-latest
132
131
needs :
132
+ - testbuild
133
133
- security
134
134
permissions :
135
135
contents : read
136
136
packages : write
137
137
security-events : write
138
+ # Required by the cosign step
139
+ id-token : write
138
140
steps :
139
- - name : Checkout Code
140
- uses : actions/checkout@v4
141
-
142
141
- name : Log in to the GitHub Container registry
143
142
uses : docker/login-action@v3
144
143
with :
145
144
registry : ghcr.io
146
145
username : ${{ github.actor }}
147
146
password : ${{ secrets.GITHUB_TOKEN }}
148
147
149
- - name : Set up QEMU
150
- uses : docker/setup-qemu-action@v3
151
- with :
152
- platforms : ' arm64'
153
-
154
- - name : Set up Docker Buildx
155
- uses : docker/setup-buildx-action@v3
156
-
157
- - name : Build and push
158
- uses : docker/bake-action@v6
159
- id : build
160
- env :
161
- environment : production
162
- registry : ghcr.io/${{ github.repository_owner }}
163
- revision : ${{ github.sha }}
164
- with :
165
- push : true
166
-
148
+ - name : Copy images
149
+ run : |
150
+ images=$(echo '${{needs.testbuild.outputs.metadata}}' |
151
+ jq -r '
152
+ .[] as $items |
153
+ (
154
+ $items."image.name" |
155
+ split(",")[] +
156
+ "@" +
157
+ $items."containerimage.digest"
158
+ )
159
+ '
160
+ )
161
+ for image in $images
162
+ do
163
+ testimageshaonly="${image%:*@*}@${image#*@}"
164
+ testimagenosha="${image%@*}"
165
+ prodimage="${testimagenosha/-testing/}"
166
+ echo "Copying ${testimageshaonly} to ${prodimage}"
167
+ docker run --quiet quay.io/skopeo/stable:v1.17.0-immutable copy -q -a \
168
+ --dest-creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
169
+ docker://${testimageshaonly} docker://${prodimage}
170
+ done
167
171
- name : Install cosign
168
172
uses : sigstore/cosign-installer@v3
169
- # See https://github.blog/security/supply-chain-security/safeguard-container-signing-capability-actions/
170
- # and https://github.com/actions/starter-workflows/blob/main/ci/docker-publish.yml for more details on
171
- # how to use cosign.
172
173
- name : Sign images
173
174
run : |
174
- images=$(echo '${{ steps.build.outputs.metadata }}' |
175
- jq '.[] | (."image.name" | sub(",.*";"" )) + "@" + ."containerimage.digest"'
175
+ images=$(echo '${{needs.testbuild.outputs.metadata}}' |
176
+ jq -r '.[] |
177
+ (
178
+ ."image.name" |
179
+ sub(",.*";"") |
180
+ sub("-testing:[^@]+";"")
181
+ ) + "@" + ."containerimage.digest"
182
+ '
176
183
)
177
- cosign sign --yes ${images}
184
+ echo "Signing ${images}"
185
+ cosign sign --yes ${images}
0 commit comments