bake: composable attributes for attestations support
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,16 @@
|
|||||||
"default": {
|
"default": {
|
||||||
"context": ".",
|
"context": ".",
|
||||||
"dockerfile": "Dockerfile",
|
"dockerfile": "Dockerfile",
|
||||||
|
"attest": [
|
||||||
|
{
|
||||||
|
"mode": "max",
|
||||||
|
"type": "provenance"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"disabled": "true",
|
||||||
|
"type": "sbom"
|
||||||
|
}
|
||||||
|
],
|
||||||
"cache-from": [
|
"cache-from": [
|
||||||
{
|
{
|
||||||
"scope": "build",
|
"scope": "build",
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
target "default" {
|
target "default" {
|
||||||
|
attest = [
|
||||||
|
"type=provenance,mode=max",
|
||||||
|
"type=sbom,disabled=true",
|
||||||
|
]
|
||||||
cache-from = [
|
cache-from = [
|
||||||
"type=gha,scope=build",
|
"type=gha,scope=build",
|
||||||
"user/repo:cache",
|
"user/repo:cache",
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {Exec} from '../exec';
|
|||||||
import {Util} from '../util';
|
import {Util} from '../util';
|
||||||
|
|
||||||
import {ExecOptions} from '@actions/exec';
|
import {ExecOptions} from '@actions/exec';
|
||||||
import {BakeDefinition, CacheEntry, ExportEntry, SecretEntry, SSHEntry} from '../types/buildx/bake';
|
import {AttestEntry, BakeDefinition, CacheEntry, ExportEntry, SecretEntry, SSHEntry} from '../types/buildx/bake';
|
||||||
import {BuildMetadata} from '../types/buildx/build';
|
import {BuildMetadata} from '../types/buildx/build';
|
||||||
import {VertexWarning} from '../types/buildkit/client';
|
import {VertexWarning} from '../types/buildkit/client';
|
||||||
|
|
||||||
@@ -183,6 +183,11 @@ export class Bake {
|
|||||||
// convert to composable attributes: https://github.com/docker/buildx/pull/2758
|
// convert to composable attributes: https://github.com/docker/buildx/pull/2758
|
||||||
for (const name in definition.target) {
|
for (const name in definition.target) {
|
||||||
const target = definition.target[name];
|
const target = definition.target[name];
|
||||||
|
if (target['attest'] && Array.isArray(target['attest'])) {
|
||||||
|
target['attest'] = target['attest'].map((item: string | AttestEntry): AttestEntry => {
|
||||||
|
return Bake.parseAttestEntry(item);
|
||||||
|
});
|
||||||
|
}
|
||||||
if (target['cache-from'] && Array.isArray(target['cache-from'])) {
|
if (target['cache-from'] && Array.isArray(target['cache-from'])) {
|
||||||
target['cache-from'] = target['cache-from'].map((item: string | CacheEntry): CacheEntry => {
|
target['cache-from'] = target['cache-from'].map((item: string | CacheEntry): CacheEntry => {
|
||||||
return Bake.parseCacheEntry(item);
|
return Bake.parseCacheEntry(item);
|
||||||
@@ -213,6 +218,34 @@ export class Bake {
|
|||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static parseAttestEntry(item: AttestEntry | string): AttestEntry {
|
||||||
|
if (typeof item !== 'string') {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
const attestEntry: AttestEntry = {type: ''};
|
||||||
|
const fields = parse(item, {
|
||||||
|
relaxColumnCount: true,
|
||||||
|
skipEmptyLines: true
|
||||||
|
})[0];
|
||||||
|
|
||||||
|
for (const field of fields) {
|
||||||
|
const [key, value] = field
|
||||||
|
.toString()
|
||||||
|
.split(/(?<=^[^=]+?)=/)
|
||||||
|
.map((item: string) => item.trim());
|
||||||
|
switch (key) {
|
||||||
|
case 'type':
|
||||||
|
attestEntry.type = value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
attestEntry[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return attestEntry;
|
||||||
|
}
|
||||||
|
|
||||||
private static parseCacheEntry(item: CacheEntry | string): CacheEntry {
|
private static parseCacheEntry(item: CacheEntry | string): CacheEntry {
|
||||||
if (typeof item !== 'string') {
|
if (typeof item !== 'string') {
|
||||||
return item;
|
return item;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export interface Group {
|
|||||||
export interface Target {
|
export interface Target {
|
||||||
description?: string;
|
description?: string;
|
||||||
args?: Record<string, string>;
|
args?: Record<string, string>;
|
||||||
attest?: Array<string>;
|
attest?: Array<AttestEntry> | Array<string>;
|
||||||
'cache-from'?: Array<CacheEntry> | Array<string>;
|
'cache-from'?: Array<CacheEntry> | Array<string>;
|
||||||
'cache-to'?: Array<CacheEntry> | Array<string>;
|
'cache-to'?: Array<CacheEntry> | Array<string>;
|
||||||
call?: string;
|
call?: string;
|
||||||
@@ -50,6 +50,11 @@ export interface Target {
|
|||||||
ulimits?: Array<string>;
|
ulimits?: Array<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AttestEntry {
|
||||||
|
type: string;
|
||||||
|
[key: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface CacheEntry {
|
export interface CacheEntry {
|
||||||
type: string;
|
type: string;
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user