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

[Feature] Add support for passing --metadata-file from cli arg to buildx build #464 #467

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Notable changes.

## March 2023

### [0.36.0]

- Add `--metadata-file` argument to `devcontainer build` command, to enable exporting build info. (https://github.com/devcontainers/cli/issues/464)

### [0.35.0]

- Transform maven, gradle and jupyterlab usages to their features v2 counterparts. (https://github.com/devcontainers/cli/issues/461)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@devcontainers/cli",
"description": "Dev Containers CLI",
"version": "0.35.0",
"version": "0.36.0",
"bin": {
"devcontainer": "devcontainer.js"
},
Expand Down
1 change: 1 addition & 0 deletions src/spec-common/injectHeadless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface ResolverParameters {
buildxPlatform: string | undefined;
buildxPush: boolean;
buildxOutput: string | undefined;
buildxMetadataFile: string | undefined;
skipFeatureAutoMapping: boolean;
skipPostAttach: boolean;
containerSessionDataFolder?: string;
Expand Down
3 changes: 3 additions & 0 deletions src/spec-node/devContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ProvisionOptions {
buildxPlatform: string | undefined;
buildxPush: boolean;
buildxOutput: string | undefined;
buildxMetadataFile: string | undefined;
additionalFeatures?: Record<string, string | boolean | Record<string, string | boolean>>;
skipFeatureAutoMapping: boolean;
skipPostAttach: boolean;
Expand Down Expand Up @@ -134,6 +135,7 @@ export async function createDockerParams(options: ProvisionOptions, disposables:
buildxPlatform: options.buildxPlatform,
buildxPush: options.buildxPush,
buildxOutput: options.buildxOutput,
buildxMetadataFile: options.buildxMetadataFile,
skipFeatureAutoMapping: options.skipFeatureAutoMapping,
skipPostAttach: options.skipPostAttach,
containerSessionDataFolder: options.containerSessionDataFolder,
Expand Down Expand Up @@ -182,6 +184,7 @@ export async function createDockerParams(options: ProvisionOptions, disposables:
buildxPlatform: common.buildxPlatform,
buildxPush: common.buildxPush,
buildxOutput: common.buildxOutput,
buildxMetadataFile: common.buildxMetadataFile
};
}

Expand Down
7 changes: 7 additions & 0 deletions src/spec-node/devContainersSpecCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ async function provision({
buildxPlatform: undefined,
buildxPush: false,
buildxOutput: undefined,
buildxMetadataFile: undefined,
additionalFeatures,
skipFeatureAutoMapping,
skipPostAttach,
Expand Down Expand Up @@ -389,6 +390,7 @@ async function doSetUp({
buildxPlatform: undefined,
buildxPush: false,
buildxOutput: undefined,
buildxMetadataFile: undefined,
skipFeatureAutoMapping: false,
skipPostAttach: false,
skipPersistingCustomizationsFromFeatures: false,
Expand Down Expand Up @@ -461,6 +463,7 @@ function buildOptions(y: Argv) {
'platform': { type: 'string', description: 'Set target platforms.' },
'push': { type: 'boolean', default: false, description: 'Push to a container registry.' },
'output': { type: 'string', description: 'Overrides the default behavior to load built images into the local docker registry. Valid options are the same ones provided to the --output option of docker buildx build.' },
'metadata-file': { type: 'string', description: 'Write build result metadata to the file. Valid options are the same ones provided to the --metadata-file option of docker buildx build. ' },
'additional-features': { type: 'string', description: 'Additional features to apply to the dev container (JSON as per "features" section in devcontainer.json)' },
'skip-feature-auto-mapping': { type: 'boolean', default: false, hidden: true, description: 'Temporary option for testing.' },
'skip-persisting-customizations-from-features': { type: 'boolean', default: false, hidden: true, description: 'Do not save customizations from referenced Features as image metadata' },
Expand Down Expand Up @@ -495,6 +498,7 @@ async function doBuild({
'platform': buildxPlatform,
'push': buildxPush,
'output': buildxOutput,
'metadata-file': buildxMetadataFile,
'additional-features': additionalFeaturesJson,
'skip-feature-auto-mapping': skipFeatureAutoMapping,
'skip-persisting-customizations-from-features': skipPersistingCustomizationsFromFeatures,
Expand Down Expand Up @@ -538,6 +542,7 @@ async function doBuild({
buildxPlatform,
buildxPush,
buildxOutput,
buildxMetadataFile,
skipFeatureAutoMapping,
skipPostAttach: true,
skipPersistingCustomizationsFromFeatures: skipPersistingCustomizationsFromFeatures,
Expand Down Expand Up @@ -786,6 +791,7 @@ async function doRunUserCommands({
buildxPlatform: undefined,
buildxPush: false,
buildxOutput: undefined,
buildxMetadataFile: undefined,
skipFeatureAutoMapping,
skipPostAttach,
skipPersistingCustomizationsFromFeatures: false,
Expand Down Expand Up @@ -1138,6 +1144,7 @@ export async function doExec({
buildxPush: false,
skipFeatureAutoMapping,
buildxOutput: undefined,
buildxMetadataFile: undefined,
skipPostAttach: false,
skipPersistingCustomizationsFromFeatures: false,
dotfiles: {}
Expand Down
4 changes: 4 additions & 0 deletions src/spec-node/singleContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ async function buildAndExtendImage(buildParams: DockerResolverParameters, config
if (target) {
args.push('--target', target);
}
if(buildParams.buildxMetadataFile) {
output.write('Setting Metadata file: ' + buildParams.buildxMetadataFile, LogLevel.Trace);
args.push('--metadata-file', buildParams.buildxMetadataFile);
}
if (noCache) {
args.push('--no-cache');
// `docker build --pull` pulls local image: https://github.com/devcontainers/cli/issues/60
Expand Down
1 change: 1 addition & 0 deletions src/spec-node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface DockerResolverParameters {
buildxPlatform: string | undefined;
buildxPush: boolean;
buildxOutput: string | undefined;
buildxMetadataFile: string | undefined;
}

export interface ResolverResult {
Expand Down