Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nx-container): initial support for provenance and sbom #1020

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/nx-container/src/executors/build/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorContext, names } from '@nx/devkit';
import * as core from '@nx-tools/core';
import { ExecutorContext, names } from '@nx/devkit';
import { parse } from 'csv-parse/sync';
import * as fs from 'node:fs';
import * as os from 'node:os';
Expand Down Expand Up @@ -29,8 +29,10 @@ export interface Inputs {
noCacheFilters: string[];
outputs: string[];
platforms: string[];
provenance: string;
pull: boolean;
push: boolean;
sbom: string;
secretFiles: string[];
secrets: string[];
shmSize: string;
Expand Down Expand Up @@ -85,6 +87,8 @@ export async function getInputs(
noCacheFilters: await getInputList('no-cache-filters', prefix, options['no-cache-filters']),
outputs: await getInputList('outputs', prefix, options.outputs, true),
platforms: await getInputList('platforms', prefix, options.platforms),
provenance: core.getInput('provenance'),
sbom: core.getInput('sbom'),
pull: core.getBooleanInput('pull', { fallback: `${options.pull || false}` }),
push: core.getBooleanInput('push', { fallback: `${options.push || false}` }),
secretFiles: await getInputList('secret-files', prefix, options['secret-files'], true),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorContext, names } from '@nx/devkit';
import { asyncForEach, exec, getBooleanInput, getExecOutput, logger } from '@nx-tools/core';
import { ExecutorContext, names } from '@nx/devkit';
import * as handlebars from 'handlebars';
import { randomBytes } from 'node:crypto';
import { Inputs } from '../../context';
Expand Down Expand Up @@ -161,6 +161,12 @@ export class Docker extends EngineAdapter {
if (inputs.platforms.length > 0) {
args.push('--platform', inputs.platforms.join(','));
}
if (inputs.provenance) {
args.push('--provenance', inputs.provenance);
}
if (inputs.sbom) {
args.push('--sbom', inputs.sbom);
}
await asyncForEach(inputs.secrets, async (secret) => {
try {
args.push('--secret', await buildx.getSecretString(secret));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('Build Executor', () => {
});

afterEach(() => {
jest.restoreAllMocks();
restore();
});

Expand Down
8 changes: 8 additions & 0 deletions packages/nx-container/src/executors/build/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export interface DockerBuildSchema {
* List of target platforms for build
*/
platforms?: string[];
/**
* Change or disable provenance attestations for the build result
*/
provenance?: string;
/**
* Always attempt to pull a newer version of the image (default false)
*/
Expand All @@ -76,6 +80,10 @@ export interface DockerBuildSchema {
* Push is a shorthand for --output=type=registry (default false)
*/
push?: boolean;
/**
* Generate SBOM attestation for the build (shorthand for --attest=type=sbom)
*/
sbom?: string;
/**
* List of secrets to expose to the build (eg. key=string, GIT_AUTH_TOKEN=mytoken)
*/
Expand Down
9 changes: 9 additions & 0 deletions packages/nx-container/src/executors/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
},
"description": "List of target platforms for build"
},
"provenance": {
"type": "string",
"description": "Change or disable provenance attestations for the build result"
},

"pull": {
"type": "boolean",
"description": "Always attempt to pull a newer version of the image (default false)",
Expand All @@ -126,6 +131,10 @@
"description": "Push is a shorthand for --output=type=registry (default false)",
"default": false
},
"sbom": {
"type": "string",
"description": "Generate SBOM attestation for the build (shorthand for --attest=type=sbom)"
},
"secrets": {
"type": "array",
"items": {
Expand Down
Loading