Skip to content

Commit fdc638d

Browse files
test added to check the --label applied successfully
1 parent eb89b94 commit fdc638d

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

.vscode/launch.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,12 @@
3030
"-r",
3131
"ts-node/register",
3232
"--exit",
33-
"src/test/cli.build.test.ts"
33+
"src/test/*.test.ts"
3434
],
3535
"env": {
3636
"TS_NODE_PROJECT": "src/test/tsconfig.json"
3737
},
3838
"console": "integratedTerminal",
39-
},
40-
{
41-
"type": "node",
42-
"request": "launch",
43-
"name": "Launch Help",
44-
"program": "${workspaceFolder}/src/spec-node/devContainersSpecCLI.ts",
45-
"cwd": "${workspaceFolder}",
46-
"args": [
47-
"build",
48-
"--help"
49-
],
50-
"console": "integratedTerminal",
5139
}
5240
]
5341
}

src/spec-node/containerFeatures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export async function extendImage(params: DockerResolverParameters, config: Subs
113113
'--target', featureBuildInfo.overrideTarget,
114114
'-f', dockerfilePath,
115115
...additionalImageNames.length > 0 ? additionalImageNames.map(name => ['-t', name]).flat() : ['-t', updatedImageName],
116-
...imageLabels.length > 0 ? imageLabels.map(name => ['-t', name]).flat() : ['-t', imageLabels],
116+
...imageLabels.length > 0 ? imageLabels.map(label => ['--label', label]).flat() : ['--label', imageLabels.toString()],
117117
emptyTempDir
118118
);
119119

src/spec-node/singleContainer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,13 @@ function getDefaultName(config: DevContainerFromDockerfileConfig | DevContainerF
122122
export async function buildNamedImageAndExtend(params: DockerResolverParameters, configWithRaw: SubstitutedConfig<DevContainerFromDockerfileConfig | DevContainerFromImageConfig>, additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>, canAddLabelsToContainer: boolean, argImageNames?: string[], imageLabels?: string[]): Promise<{ updatedImageName: string[]; imageMetadata: SubstitutedConfig<ImageMetadataEntry[]>; imageDetails: () => Promise<ImageDetails>; labels?: Record<string, string> }> {
123123
const { config } = configWithRaw;
124124
const imageNames = argImageNames ?? [getDefaultName(config, params)];
125+
const imagelabel = imageLabels ?? [getDefaultName(config, params)];
125126
params.common.progress(ResolverProgress.BuildingImage);
126127
if (isDockerFileConfig(config)) {
127128
return await buildAndExtendImage(params, configWithRaw as SubstitutedConfig<DevContainerFromDockerfileConfig>, imageNames, params.buildNoCache ?? false, additionalFeatures);
128129
}
129130
// image-based dev container - extend
130-
return await extendImage(params, configWithRaw, imageNames[0], argImageNames || [], imageLabels || [], additionalFeatures, canAddLabelsToContainer);
131+
return await extendImage(params, configWithRaw, imageNames[0], argImageNames || [], imagelabel || [], additionalFeatures, canAddLabelsToContainer);
131132
}
132133

133134
async function buildAndExtendImage(buildParams: DockerResolverParameters, configWithRaw: SubstitutedConfig<DevContainerFromDockerfileConfig>, baseImageNames: string[], noCache: boolean, additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>) {

src/test/cli.build.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ describe('Dev Containers CLI', function () {
2727

2828
describe('Command build', () => {
2929

30+
it('should build successfully with valid image metadata --label property', async () => {
31+
const testFolder = `${__dirname}/configs/example`;
32+
const response = await shellExec(`${cli} build --workspace-folder ${testFolder} --label 'name=label-test' --label 'type=multiple-labels'`);
33+
const res = JSON.parse(response.stdout);
34+
assert.equal(res.outcome, 'success');
35+
const labels = await shellExec(`docker inspect --format '{{json .Config.Labels}}' ${res.imageName} | jq`);
36+
assert.match(labels.stdout.toString(), /\"name\": \"label-test\"/);
37+
});
38+
3039
it('should fail to build with correct error message for local feature', async () => {
3140
const testFolder = `${__dirname}/configs/image-with-local-feature`;
3241
try {

0 commit comments

Comments
 (0)