@@ -24,19 +24,16 @@ jobs:
2424 exit 1
2525 fi
2626
27- act :
27+ act-build-arch :
2828 needs : arrange
2929 uses : ./.github/workflows/docker-build-images.yml
3030 secrets :
3131 oci-registry-password : ${{ secrets.GITHUB_TOKEN }}
32- build-secrets : |
33- SECRET_REPOSITORY_OWNER=${{ github.repository_owner }}
34- SECRET_REPOSITORY=${{ github.repository }}
3532 build-secret-github-app-key : ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}
3633 with :
3734 # First image is multi arch
3835 # Second image is mono arch
39- # Third image tests build args, secrets
36+ # Default caching
4037 images : |
4138 [
4239 {
@@ -55,31 +52,11 @@ jobs:
5552 "target": "prod",
5653 "platforms": ["linux/amd64"],
5754 "tag": "0.1.0"
58- },
59- {
60- "name": "test-build-args-secrets",
61- "context": ".",
62- "target": "test",
63- "dockerfile": "./tests/application/Dockerfile",
64- "platforms": ["linux/amd64"],
65- "build-args": {
66- "BUILD_RUN_ID": "${{ github.run_id }}",
67- "BUILD_REPOSITORY_OWNER": "${{ github.repository_owner }}",
68- "BUILD_REPOSITORY": "${{ github.repository }}"
69- },
70- "secret-envs": {
71- "SECRET_ENV_REPOSITORY_OWNER": "GITHUB_REPOSITORY_OWNER",
72- "SECRET_ENV_REPOSITORY": "GITHUB_REPOSITORY"
73- }
7455 }
7556 ]
76- build-secret-github-app-id : ${{ vars.CI_BOT_APP_ID }}
77- build-secret-github-app-token-env : |
78- SECRET_ENV_GITHUB_APP_TOKEN_1
79- SECRET_ENV_GITHUB_APP_TOKEN_2
8057
81- assert :
82- needs : act
58+ assert-build-arch :
59+ needs : act-build-arch
8360 runs-on : " ubuntu-latest"
8461 steps :
8562 - name : Check built images ouput
8865 script : |
8966 const assert = require("assert");
9067
91- const builtImagesOutput = `${{ needs.act.outputs.built-images }}`;
68+ const builtImagesOutput = `${{ needs.act-build-arch .outputs.built-images }}`;
9269 assert(builtImagesOutput.length, `"built-images" output is empty`);
9370
9471 // Check if is valid Json
10178
10279 const expectedCreatedImages = [
10380 "test-multi-arch",
104- "test-mono-arch",
105- "test-build-args-secrets"
81+ "test-mono-arch"
10682 ];
10783 assert(typeof builtImages === "object" && !Array.isArray(builtImages), `"built-images" output is not an object`);
10884 assert.equal(Object.keys(builtImages).length, expectedCreatedImages.length, `"built-images" output does not contain ${expectedCreatedImages.length} images`);
@@ -162,7 +138,7 @@ jobs:
162138 script : |
163139 const assert = require("assert");
164140
165- const image = `${{ fromJson(needs.act.outputs.built-images).test-multi-arch.images[0] }}`;
141+ const image = `${{ fromJson(needs.act-build-arch .outputs.built-images).test-multi-arch.images[0] }}`;
166142
167143 await exec.exec('docker', ['pull', image]);
168144
@@ -224,7 +200,7 @@ jobs:
224200 script : |
225201 const assert = require("assert");
226202
227- const image = `${{ fromJson(needs.act.outputs.built-images).test-mono-arch.images[0] }}`;
203+ const image = `${{ fromJson(needs.act-build-arch .outputs.built-images).test-mono-arch.images[0] }}`;
228204
229205 await exec.exec('docker', ['pull', image]);
230206
@@ -263,4 +239,120 @@ jobs:
263239 );
264240 });
265241
242+ act-build-args-secrets-and-registry-caching :
243+ needs : arrange
244+ uses : ./.github/workflows/docker-build-images.yml
245+ secrets :
246+ oci-registry-password : ${{ secrets.GITHUB_TOKEN }}
247+ build-secrets : |
248+ SECRET_REPOSITORY_OWNER=${{ github.repository_owner }}
249+ SECRET_REPOSITORY=${{ github.repository }}
250+ build-secret-github-app-key : ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}
251+ with :
252+ cache-type : registry
253+ images : |
254+ [
255+ {
256+ "name": "test-build-args-secrets",
257+ "context": ".",
258+ "target": "test",
259+ "dockerfile": "./tests/application/Dockerfile",
260+ "platforms": ["linux/amd64","linux/arm64"],
261+ "build-args": {
262+ "BUILD_RUN_ID": "${{ github.run_id }}",
263+ "BUILD_REPOSITORY_OWNER": "${{ github.repository_owner }}",
264+ "BUILD_REPOSITORY": "${{ github.repository }}"
265+ },
266+ "secret-envs": {
267+ "SECRET_ENV_REPOSITORY_OWNER": "GITHUB_REPOSITORY_OWNER",
268+ "SECRET_ENV_REPOSITORY": "GITHUB_REPOSITORY"
269+ }
270+ }
271+ ]
272+ build-secret-github-app-id : ${{ vars.CI_BOT_APP_ID }}
273+ build-secret-github-app-token-env : |
274+ SECRET_ENV_GITHUB_APP_TOKEN_1
275+ SECRET_ENV_GITHUB_APP_TOKEN_2
276+
277+ assert-build-args-secrets-and-registry-caching :
278+ needs : act-build-args-secrets-and-registry-caching
279+ runs-on : " ubuntu-latest"
280+ steps :
281+ - name : Check built images ouput
282+ uses : actions/github-script@v7.0.1
283+ with :
284+ script : |
285+ const assert = require("assert");
286+
287+ const builtImagesOutput = `${{ needs.act-build-args-secrets-and-registry-caching.outputs.built-images }}`;
288+ assert(builtImagesOutput.length, `"built-images" output is empty`);
289+
290+ // Check if is valid Json
291+ let builtImages = null;
292+ try {
293+ builtImages = JSON.parse(builtImagesOutput);
294+ } catch (error) {
295+ throw new Error(`"built-images" output is not a valid JSON: ${error}`);
296+ }
297+
298+ const expectedCreatedImages = [
299+ "test-build-args-secrets"
300+ ];
301+
302+ assert(typeof builtImages === "object" && !Array.isArray(builtImages), `"built-images" output is not an object`);
303+ assert.equal(Object.keys(builtImages).length, expectedCreatedImages.length, `"built-images" output does not contain ${expectedCreatedImages.length} images`);
304+
305+ for (const image of expectedCreatedImages) {
306+ assert(builtImages[image], `"built-images" output does not contain "${image}" image`);
307+ }
308+ - uses : docker/login-action@v3
309+ with :
310+ registry : ghcr.io
311+ username : ${{ github.repository_owner }}
312+ password : ${{ github.token }}
313+
314+ - name : Check docker image and cache
315+ uses : actions/github-script@v7.0.1
316+ with :
317+ script : |
318+ const assert = require("assert");
319+
320+ let expectedTag;
321+
322+ const isPullRequest = `${{ github.event_name }}` === "pull_request";
323+ if (isPullRequest) {
324+ const shortSha = `${{ github.sha }}`.substring(0, 7);
325+ expectedTag = `pr-${{ github.event.pull_request.number }}-${shortSha}`;
326+ } else {
327+ expectedTag = `${{ github.ref_name }}`;
328+ }
329+
330+ const expectedImage = `ghcr.io/hoverkraft-tech/ci-github-container/test-build-args-secrets`;
331+ const expectedImageTag = `${expectedImage}:${expectedTag}`;
332+
333+ const image = `${{ fromJson(needs.act-build-args-secrets-and-registry-caching.outputs.built-images).test-build-args-secrets.images[0] }}`;
334+
335+ assert.equal(image, expectedImageTag, `"built-images" output is not valid. Expected "${expectedImage}", got "${image}"`);
336+
337+ await exec.exec('docker', ['pull', image]);
338+
339+ let expectedCacheTag;
340+
341+ if (isPullRequest) {
342+ expectedCacheTag = `pr-${{ github.event.pull_request.number }}`;
343+ } else {
344+ expectedCacheTag = `${{ github.ref_name }}`;
345+ }
346+
347+ const cacheImage = `${expectedImage}/cache:${expectedCacheTag}`;
348+
349+ const cacheImages = [
350+ `${cacheImage}-linux-arm64`,
351+ `${cacheImage}-linux-amd64`
352+ ];
353+
354+ for (const cacheImage of cacheImages) {
355+ await exec.exec('docker', ['manifest', 'inspect', cacheImage]);
356+ }
357+
266358# jscpd:ignore-end
0 commit comments