From 6b04427324f9c27bf7c43f27ce9f0abfb4912f81 Mon Sep 17 00:00:00 2001 From: Prathamesh Zarkar <159782310+prathameshzarkar9@users.noreply.github.com> Date: Mon, 27 May 2024 15:42:30 +0530 Subject: [PATCH] Omit generated image name when `--image-name` is given (#812) --- src/spec-node/containerFeatures.ts | 5 ++--- src/test/cli.build.test.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/spec-node/containerFeatures.ts b/src/spec-node/containerFeatures.ts index d89e06e32..cb5879553 100644 --- a/src/spec-node/containerFeatures.ts +++ b/src/spec-node/containerFeatures.ts @@ -111,9 +111,8 @@ export async function extendImage(params: DockerResolverParameters, config: Subs cliHost.mkdirp(emptyTempDir); args.push( '--target', featureBuildInfo.overrideTarget, - '-t', updatedImageName, - ...additionalImageNames.map(name => ['-t', name]).flat(), '-f', dockerfilePath, + ...additionalImageNames.length > 0 ? additionalImageNames.map(name => ['-t', name]).flat() : ['-t', updatedImageName], emptyTempDir ); @@ -125,7 +124,7 @@ export async function extendImage(params: DockerResolverParameters, config: Subs await dockerCLI(infoParams, ...args); } return { - updatedImageName: [ updatedImageName ], + updatedImageName: additionalImageNames.length > 0 ? additionalImageNames : [updatedImageName], imageMetadata: getDevcontainerMetadata(imageBuildInfo.metadata, config, featuresConfig), imageDetails: async () => imageBuildInfo.imageDetails, }; diff --git a/src/test/cli.build.test.ts b/src/test/cli.build.test.ts index c22e3913f..dbec52704 100644 --- a/src/test/cli.build.test.ts +++ b/src/test/cli.build.test.ts @@ -27,6 +27,18 @@ describe('Dev Containers CLI', function () { describe('Command build', () => { + it('should correctly configure the image name to push from --image-name with --push true', async () => { + const testFolder = `${__dirname}/configs/example`; + try { + await shellExec(`${cli} build --workspace-folder ${testFolder} --image-name demo:v1`); + const tags = await shellExec(`docker images --format "{{.Tag}}" demo`); + const imageTags = tags.stdout.trim().split('\n').filter(tag => tag !== ''); + assert.equal(imageTags.length, 1, 'There should be only one tag for demo:v1'); + } catch (error) { + assert.equal(error.code, 'ERR_ASSERTION', 'Should fail with ERR_ASSERTION'); + } + }); + buildKitOptions.forEach(({ text, options }) => { it(`should execute successfully with valid image config [${text}]`, async () => { const testFolder = `${__dirname}/configs/image`;