Skip to content

Commit bc1443b

Browse files
committed
Add labels from params in compose
1 parent fc10eb3 commit bc1443b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/spec-node/dockerCompose.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ export async function buildAndExtendDockerCompose(configWithRaw: SubstitutedConf
220220
buildOverrideContent += ` target: ${featureBuildInfo.overrideTarget}\n`;
221221
}
222222

223+
// Add labels from params
224+
if (params.additionalLabels && params.additionalLabels.length > 0) {
225+
buildOverrideContent += ` labels:\n`;
226+
params.additionalLabels.forEach(label => {
227+
buildOverrideContent += ` - ${label}\n`;
228+
});
229+
}
230+
223231
if (!serviceInfo.build?.context) {
224232
// need to supply a context as we don't have one inherited
225233
const emptyDir = getEmptyContextFolder(common);

src/test/cli.build.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ describe('Dev Containers CLI', function () {
4949
assert.equal(labels.type, 'multiple-labels');
5050
});
5151

52+
it('should build successfully with valid image metadata --label property (compose)', async () => {
53+
const testFolder = `${__dirname}/configs/compose-without-name`;
54+
const image1 = 'image-1';
55+
await shellExec(`docker rmi -f ${image1}`);
56+
const res = await shellExec(`${cli} build --workspace-folder ${testFolder} --image-name ${image1} --label 'name=label-test' --label 'type=multiple-labels'`);
57+
const response = JSON.parse(res.stdout);
58+
assert.equal(response.outcome, 'success');
59+
assert.equal(response.imageName[0], image1);
60+
const labelsResponse = await shellExec(`docker inspect --format '{{json .Config.Labels}}' ${response.imageName[0]}`);
61+
const labels = JSON.parse(labelsResponse.stdout);
62+
assert.equal(labels.name, 'label-test');
63+
assert.equal(labels.type, 'multiple-labels');
64+
});
65+
5266
it('should fail to build with correct error message for local feature', async () => {
5367
const testFolder = `${__dirname}/configs/image-with-local-feature`;
5468
try {

0 commit comments

Comments
 (0)