From 630b180101c327a1cd82e01be6deeef7a32f1b39 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:06:34 +0200 Subject: [PATCH] buildx(build): resolveWarnings from metadata Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/buildx/build.test.ts | 10 ++ __tests__/fixtures/metadata.json | 183 +++++++++++++++++++++++++++++++ src/buildx/build.ts | 14 +++ 3 files changed, 207 insertions(+) diff --git a/__tests__/buildx/build.test.ts b/__tests__/buildx/build.test.ts index c348a42..fcad419 100644 --- a/__tests__/buildx/build.test.ts +++ b/__tests__/buildx/build.test.ts @@ -84,6 +84,16 @@ describe('resolveProvenance', () => { }); }); +describe('resolveWarnings', () => { + it('matches', async () => { + const build = new Build(); + fs.writeFileSync(build.getMetadataFilePath(), JSON.stringify(metadata)); + const warnings = build.resolveWarnings(); + expect(warnings).toBeDefined(); + expect(warnings?.length).toEqual(3); + }); +}); + describe('resolveDigest', () => { it('matches', async () => { const build = new Build(); diff --git a/__tests__/fixtures/metadata.json b/__tests__/fixtures/metadata.json index 1de626a..0c5f5d3 100644 --- a/__tests__/fixtures/metadata.json +++ b/__tests__/fixtures/metadata.json @@ -40,6 +40,189 @@ } }, "buildx.build.ref": "default/default/n6ibcp9b2pw108rrz7ywdznvo", + "buildx.build.warnings": [ + { + "vertex": "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0", + "level": 1, + "short": "Q29uc2lzdGVudEluc3RydWN0aW9uQ2FzaW5nOiBDb21tYW5kICdmck9NJyBzaG91bGQgYmUgY29uc2lzdGVudGx5IGNhc2VkIChsaW5lIDIp", + "detail": [ + "SW5zdHJ1Y3Rpb25zIHNob3VsZCBiZSBpbiBjb25zaXN0ZW50IGNhc2luZyAoYWxsIGxvd2VyIG9yIGFsbCB1cHBlcik=" + ], + "url": "https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/", + "sourceInfo": { + "filename": "Dockerfile", + "data": "IyBzeW50YXg9ZG9ja2VyL2RvY2tlcmZpbGUtdXBzdHJlYW06bWFzdGVyCmZyT00gYnVzeWJveCBhcyBiYXNlCmNPcHkgRG9ja2VyZmlsZSAuCgpmcm9tIHNjcmF0Y2gKQ09QeSAtLWZyb209YmFzZSBcCiAgL0RvY2tlcmZpbGUgXAogIC8K", + "definition": { + "def": [ + "GsUBChJsb2NhbDovL2RvY2tlcmZpbGUSFAoMbG9jYWwuZGlmZmVyEgRub25lEkoKEWxvY2FsLmZvbGxvd3BhdGhzEjVbIkRvY2tlcmZpbGUiLCJEb2NrZXJmaWxlLmRvY2tlcmlnbm9yZSIsImRvY2tlcmZpbGUiXRIqCg1sb2NhbC5zZXNzaW9uEhkwN3A3MzJ6aGR4NXV1NnVsZDNzOGpteWo2EiEKE2xvY2FsLnNoYXJlZGtleWhpbnQSCmRvY2tlcmZpbGVaAA==", + "CkkKR3NoYTI1Njo3YjQ3N2FjNWRkM2E0YzRkMjUyM2Y3ZjdmMjA0MDZiNjI2Mzk1ZGUwODJmNDRmZDVmZjk5NjMyM2VjODI1N2Qw" + ], + "metadata": { + "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0": { + "description": { + "llb.customname": "[internal] load build definition from Dockerfile" + }, + "caps": { + "source.local": true, + "source.local.followpaths": true, + "source.local.sessionid": true, + "source.local.sharedkeyhint": true + } + }, + "sha256:a06279dbe062a3b181c9b918abfaf37ca8106f1f9745b9d42356b3195b205cd1": { + "caps": { + "constraints": true, + "meta.description": true, + "platform": true + } + } + }, + "Source": { + "locations": { + "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0": {} + } + } + }, + "language": "Dockerfile" + }, + "range": [ + { + "start": { + "line": 2 + }, + "end": { + "line": 2 + } + } + ] + }, + { + "vertex": "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0", + "level": 1, + "short": "Q29uc2lzdGVudEluc3RydWN0aW9uQ2FzaW5nOiBDb21tYW5kICdjT3B5JyBzaG91bGQgYmUgY29uc2lzdGVudGx5IGNhc2VkIChsaW5lIDMp", + "detail": [ + "SW5zdHJ1Y3Rpb25zIHNob3VsZCBiZSBpbiBjb25zaXN0ZW50IGNhc2luZyAoYWxsIGxvd2VyIG9yIGFsbCB1cHBlcik=" + ], + "url": "https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/", + "sourceInfo": { + "filename": "Dockerfile", + "data": "IyBzeW50YXg9ZG9ja2VyL2RvY2tlcmZpbGUtdXBzdHJlYW06bWFzdGVyCmZyT00gYnVzeWJveCBhcyBiYXNlCmNPcHkgRG9ja2VyZmlsZSAuCgpmcm9tIHNjcmF0Y2gKQ09QeSAtLWZyb209YmFzZSBcCiAgL0RvY2tlcmZpbGUgXAogIC8K", + "definition": { + "def": [ + "GsUBChJsb2NhbDovL2RvY2tlcmZpbGUSFAoMbG9jYWwuZGlmZmVyEgRub25lEkoKEWxvY2FsLmZvbGxvd3BhdGhzEjVbIkRvY2tlcmZpbGUiLCJEb2NrZXJmaWxlLmRvY2tlcmlnbm9yZSIsImRvY2tlcmZpbGUiXRIqCg1sb2NhbC5zZXNzaW9uEhkwN3A3MzJ6aGR4NXV1NnVsZDNzOGpteWo2EiEKE2xvY2FsLnNoYXJlZGtleWhpbnQSCmRvY2tlcmZpbGVaAA==", + "CkkKR3NoYTI1Njo3YjQ3N2FjNWRkM2E0YzRkMjUyM2Y3ZjdmMjA0MDZiNjI2Mzk1ZGUwODJmNDRmZDVmZjk5NjMyM2VjODI1N2Qw" + ], + "metadata": { + "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0": { + "description": { + "llb.customname": "[internal] load build definition from Dockerfile" + }, + "caps": { + "source.local": true, + "source.local.followpaths": true, + "source.local.sessionid": true, + "source.local.sharedkeyhint": true + } + }, + "sha256:a06279dbe062a3b181c9b918abfaf37ca8106f1f9745b9d42356b3195b205cd1": { + "caps": { + "constraints": true, + "meta.description": true, + "platform": true + } + } + }, + "Source": { + "locations": { + "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0": {} + } + } + }, + "language": "Dockerfile" + }, + "range": [ + { + "start": { + "line": 3 + }, + "end": { + "line": 3 + } + } + ] + }, + { + "vertex": "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0", + "level": 1, + "short": "Q29uc2lzdGVudEluc3RydWN0aW9uQ2FzaW5nOiBDb21tYW5kICdDT1B5JyBzaG91bGQgYmUgY29uc2lzdGVudGx5IGNhc2VkIChsaW5lIDYp", + "detail": [ + "SW5zdHJ1Y3Rpb25zIHNob3VsZCBiZSBpbiBjb25zaXN0ZW50IGNhc2luZyAoYWxsIGxvd2VyIG9yIGFsbCB1cHBlcik=" + ], + "url": "https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/", + "sourceInfo": { + "filename": "Dockerfile", + "data": "IyBzeW50YXg9ZG9ja2VyL2RvY2tlcmZpbGUtdXBzdHJlYW06bWFzdGVyCmZyT00gYnVzeWJveCBhcyBiYXNlCmNPcHkgRG9ja2VyZmlsZSAuCgpmcm9tIHNjcmF0Y2gKQ09QeSAtLWZyb209YmFzZSBcCiAgL0RvY2tlcmZpbGUgXAogIC8K", + "definition": { + "def": [ + "GsUBChJsb2NhbDovL2RvY2tlcmZpbGUSFAoMbG9jYWwuZGlmZmVyEgRub25lEkoKEWxvY2FsLmZvbGxvd3BhdGhzEjVbIkRvY2tlcmZpbGUiLCJEb2NrZXJmaWxlLmRvY2tlcmlnbm9yZSIsImRvY2tlcmZpbGUiXRIqCg1sb2NhbC5zZXNzaW9uEhkwN3A3MzJ6aGR4NXV1NnVsZDNzOGpteWo2EiEKE2xvY2FsLnNoYXJlZGtleWhpbnQSCmRvY2tlcmZpbGVaAA==", + "CkkKR3NoYTI1Njo3YjQ3N2FjNWRkM2E0YzRkMjUyM2Y3ZjdmMjA0MDZiNjI2Mzk1ZGUwODJmNDRmZDVmZjk5NjMyM2VjODI1N2Qw" + ], + "metadata": { + "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0": { + "description": { + "llb.customname": "[internal] load build definition from Dockerfile" + }, + "caps": { + "source.local": true, + "source.local.followpaths": true, + "source.local.sessionid": true, + "source.local.sharedkeyhint": true + } + }, + "sha256:a06279dbe062a3b181c9b918abfaf37ca8106f1f9745b9d42356b3195b205cd1": { + "caps": { + "constraints": true, + "meta.description": true, + "platform": true + } + } + }, + "Source": { + "locations": { + "sha256:7b477ac5dd3a4c4d2523f7f7f20406b626395de082f44fd5ff996323ec8257d0": {} + } + } + }, + "language": "Dockerfile" + }, + "range": [ + { + "start": { + "line": 6 + }, + "end": { + "line": 6 + } + }, + { + "start": { + "line": 7 + }, + "end": { + "line": 7 + } + }, + { + "start": { + "line": 8 + }, + "end": { + "line": 8 + } + } + ] + } + ], "containerimage.config.digest": "sha256:059b68a595b22564a1cbc167f369349fdc2ecc1f7bc092c2235cbf601a795fd", "containerimage.digest": "sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c" } diff --git a/src/buildx/build.ts b/src/buildx/build.ts index 796e36e..e81b7d5 100644 --- a/src/buildx/build.ts +++ b/src/buildx/build.ts @@ -25,6 +25,7 @@ import {GitHub} from '../github'; import {Util} from '../util'; import {BuildMetadata} from '../types/buildx/build'; +import {VertexWarning} from '../types/buildkit/client'; import {ProvenancePredicate} from '../types/intoto/slsa_provenance/v0.2/provenance'; export interface BuildOpts { @@ -96,6 +97,19 @@ export class Build { return undefined; } + public resolveWarnings(metadata?: BuildMetadata): Array | undefined { + if (!metadata) { + metadata = this.resolveMetadata(); + if (!metadata) { + return undefined; + } + } + if ('buildx.build.warnings' in metadata) { + return metadata['buildx.build.warnings'] as Array; + } + return undefined; + } + public resolveDigest(metadata?: BuildMetadata): string | undefined { if (!metadata) { metadata = this.resolveMetadata();