Skip to content

Commit c11aee1

Browse files
hoverkraft-bot[bot]neilime
authored andcommitted
feat(docker-build-images): optimize caching and signing
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 7384bd5 commit c11aee1

6 files changed

Lines changed: 202 additions & 109 deletions

File tree

.github/workflows/__test-workflow-docker-build-images.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ jobs:
105105
)
106106
);
107107
108+
assert.equal(applicationMultiArchImage.platforms.length, 3);
109+
assert(applicationMultiArchImage.platforms.includes("linux/amd64"));
110+
assert(applicationMultiArchImage.platforms.includes("linux/arm64"));
111+
assert(applicationMultiArchImage.platforms.includes("linux/arm/v7"));
112+
108113
const applicationMonoArchImage = builtImages["test-mono-arch"];
109114
110115
assert.equal(applicationMonoArchImage.name, "test-mono-arch");
@@ -121,6 +126,8 @@ jobs:
121126
applicationMonoArchImage.images[0],
122127
`ghcr.io/hoverkraft-tech/ci-github-container/test-mono-arch:0.1.0@${applicationMonoArchImage.digest}`
123128
);
129+
assert.equal(applicationMonoArchImage.platforms.length, 1);
130+
assert(applicationMonoArchImage.platforms.includes("linux/amd64"));
124131
125132
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
126133
with:
@@ -194,6 +201,8 @@ jobs:
194201

195202
- name: Assert - signed multi-arch docker image
196203
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
204+
env:
205+
COSIGN_EXPERIMENTAL: "1"
197206
with:
198207
script: |
199208
const images = ${{ toJson(fromJson(needs.act-build-images.outputs.built-images).test-multi-arch.images) }};
@@ -202,7 +211,9 @@ jobs:
202211
await exec.exec(
203212
'cosign',
204213
[
205-
'verify', image,
214+
'verify',
215+
'--registry-referrers-mode', 'oci-1-1',
216+
image,
206217
'--certificate-oidc-issuer', 'https://token.actions.githubusercontent.com',
207218
'--certificate-identity-regexp', 'https://github.com/hoverkraft-tech/ci-github-container',
208219
]
@@ -256,6 +267,8 @@ jobs:
256267
257268
- name: Assert - signed mono-arch docker image
258269
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
270+
env:
271+
COSIGN_EXPERIMENTAL: "1"
259272
with:
260273
script: |
261274
const images = ${{ toJson(fromJson(needs.act-build-images.outputs.built-images).test-mono-arch.images) }};
@@ -264,7 +277,9 @@ jobs:
264277
await exec.exec(
265278
'cosign',
266279
[
267-
'verify', image,
280+
'verify',
281+
'--registry-referrers-mode', 'oci-1-1',
282+
image,
268283
'--certificate-oidc-issuer', 'https://token.actions.githubusercontent.com',
269284
'--certificate-identity-regexp', 'https://github.com/hoverkraft-tech/ci-github-container',
270285
]
@@ -278,8 +293,8 @@ jobs:
278293
secrets:
279294
oci-registry-password: ${{ secrets.GITHUB_TOKEN }}
280295
build-secrets: |
281-
SECRET_REPOSITORY_OWNER=${{ github.repository_owner }}
282-
SECRET_REPOSITORY=${{ github.repository }}
296+
SECRET_TEST=test-secret
297+
SECRET_ANOTHER_TEST=another-test-secret
283298
build-secret-github-app-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}
284299
with:
285300
cache-type: registry
@@ -293,12 +308,12 @@ jobs:
293308
"platforms": ["linux/amd64","linux/arm64"],
294309
"build-args": {
295310
"BUILD_RUN_ID": "${{ github.run_id }}",
296-
"BUILD_REPOSITORY_OWNER": "${{ github.repository_owner }}",
297-
"BUILD_REPOSITORY": "${{ github.repository }}"
311+
"BUILD_ARG_TEST": "test-arg",
312+
"BUILD_ARG_ANOTHER_TEST": "another-test-arg"
298313
},
299314
"secret-envs": {
300-
"SECRET_ENV_REPOSITORY_OWNER": "GITHUB_REPOSITORY_OWNER",
301-
"SECRET_ENV_REPOSITORY": "GITHUB_REPOSITORY"
315+
"SECRET_ENV_TEST": "GITHUB_ACTION",
316+
"SECRET_ENV_ANOTHER_TEST": "GITHUB_JOB"
302317
}
303318
}
304319
]

.github/workflows/docker-build-images.yml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,6 @@ name: Docker build images
66

77
on: # yamllint disable-line rule:truthy
88
workflow_call:
9-
outputs:
10-
built-images:
11-
description: |
12-
Built images data.
13-
Example:
14-
```json
15-
{
16-
"application": {
17-
"name": "application",
18-
"registry": "ghcr.io",
19-
"repository": "my-org/my-repo/application",
20-
"tags": ["pr-63-5222075","pr-63"],
21-
"images": [
22-
"ghcr.io/my-org/my-repo/application:pr-63-5222075@sha256:d31aa93410434ac9dcfc9179cac2cb1fd4d7c27f11527addc40299c7c675f49d",
23-
"ghcr.io/my-org/my-repo/application:pr-63@sha256:d31aa93410434ac9dcfc9179cac2cb1fd4d7c27f11527addc40299c7c675f49d"
24-
],
25-
"digest": "sha256:d31aa93410434ac9dcfc9179cac2cb1fd4d7c27f11527addc40299c7c675f49d",
26-
"annotations": {
27-
"org.opencontainers.image.created": "2021-09-30T14:00:00Z",
28-
"org.opencontainers.image.description": "Application image"
29-
}
30-
}
31-
}
32-
```
33-
value: ${{ jobs.publish-manifests.outputs.built-images }}
349
inputs:
3510
runs-on:
3611
description: |
@@ -141,6 +116,32 @@ on: # yamllint disable-line rule:truthy
141116
GitHub App private key to generate GitHub token to be passed as build secret env.
142117
See https://github.com/actions/create-github-app-token.
143118
required: false
119+
outputs:
120+
built-images:
121+
description: |
122+
Built images data.
123+
Example:
124+
```json
125+
{
126+
"application": {
127+
"name": "application",
128+
"registry": "ghcr.io",
129+
"repository": "my-org/my-repo/application",
130+
"tags": ["pr-63-5222075","pr-63"],
131+
"images": [
132+
"ghcr.io/my-org/my-repo/application:pr-63-5222075@sha256:d31aa93410434ac9dcfc9179cac2cb1fd4d7c27f11527addc40299c7c675f49d",
133+
"ghcr.io/my-org/my-repo/application:pr-63@sha256:d31aa93410434ac9dcfc9179cac2cb1fd4d7c27f11527addc40299c7c675f49d"
134+
],
135+
"digest": "sha256:d31aa93410434ac9dcfc9179cac2cb1fd4d7c27f11527addc40299c7c675f49d",
136+
"annotations": {
137+
"org.opencontainers.image.created": "2021-09-30T14:00:00Z",
138+
"org.opencontainers.image.description": "Application image"
139+
},
140+
"platforms": ["linux/amd64", "linux/arm64"]
141+
}
142+
}
143+
```
144+
value: ${{ jobs.publish-manifests.outputs.built-images }}
144145

145146
permissions:
146147
contents: read
@@ -474,15 +475,17 @@ jobs:
474475
// Group by image name
475476
const images = {};
476477
builtImages.forEach(builtImage => {
477-
const { name, image, ...rest } = builtImage;
478+
const { name, image, platform, ...rest } = builtImage;
478479
if (!images[name]) {
479480
images[name] = {
480481
name,
481482
images: [image],
483+
platforms: [platform],
482484
...rest,
483485
};
484486
} else {
485487
images[name].images = [...new Set([...images[name].images, image])];
488+
images[name].platforms = [...new Set([...images[name].platforms, platform])];
486489
}
487490
});
488491
@@ -512,6 +515,7 @@ jobs:
512515
built-images: ${{ steps.built-images.outputs.built-images }}
513516

514517
- id: get-images-to-sign
518+
if: inputs.sign
515519
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
516520
with:
517521
script: |
@@ -527,7 +531,7 @@ jobs:
527531
const imagesToSign = Object.values(builtImages).map(image => image.images).flat();
528532
core.setOutput('images-to-sign', JSON.stringify(imagesToSign));
529533
- uses: ./self-workflow/actions/docker/sign-images
530-
if: inputs.sign
534+
if: steps.get-images-to-sign.outputs.images-to-sign
531535
with:
532536
images: ${{ steps.get-images-to-sign.outputs.images-to-sign }}
533537
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)