Skip to content

Commit

Permalink
redundant dockerfile issue with build
Browse files Browse the repository at this point in the history
  • Loading branch information
prathameshzarkar9 committed May 14, 2024
1 parent c1c8b08 commit de4d1bf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/spec-node/containerFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -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,
};
Expand Down
22 changes: 21 additions & 1 deletion src/spec-node/devContainersSpecCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,22 @@ function buildHandler(args: BuildArgs) {
(async () => build(args))().catch(console.error);
}

function removeDuplicateImages(images: string[]): string[] {
const uniqueImageNames = new Set<string>();
const filteredImages: string[] = [];
console.log('images before filtering : ' + images);
for (const image of images) {
const [name] = image.split(':');
if (!uniqueImageNames.has(name)) {
uniqueImageNames.add(name);
filteredImages.push(image);
console.log('image unique tags : ' + filteredImages);
}
}

return filteredImages;
}

async function build(args: BuildArgs) {
const result = await doBuild(args);
const exitCode = result.outcome === 'error' ? 1 : 0;
Expand Down Expand Up @@ -610,7 +626,11 @@ async function doBuild({
await ensureNoDisallowedFeatures(buildParams, config, additionalFeatures, undefined);

// Support multiple use of `--image-name`
const imageNames = (argImageName && (Array.isArray(argImageName) ? argImageName : [argImageName]) as string[]) || undefined;
const duplicateImageNames = (argImageName && (Array.isArray(argImageName) ? argImageName : [argImageName]) as string[]) || undefined;
let imageNames = undefined;
if (duplicateImageNames !== undefined) {
imageNames = removeDuplicateImages(duplicateImageNames);
}

if (isDockerFileConfig(config)) {

Expand Down
10 changes: 10 additions & 0 deletions src/test/cli.build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ 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 --image-name demo:v2 --image-name demo:v3`);
assert.ok(false, 'should not succeed');
} 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`;
Expand Down

0 comments on commit de4d1bf

Please sign in to comment.