Skip to content
Merged
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
8 changes: 3 additions & 5 deletions src/spec-node/imageMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,9 @@ export function getDevcontainerMetadataLabel(devContainerMetadata: SubstitutedCo
if (!metadata.length) {
return '';
}
const imageMetadataLabelValue = metadata.length !== 1
? `[${metadata
.map(feature => ` \\\n${toLabelString(feature)}`)
.join(',')} \\\n]`
: toLabelString(metadata[0]);
const imageMetadataLabelValue = `[${metadata
.map(feature => ` \\\n${toLabelString(feature)}`)
.join(',')} \\\n]`;
return `LABEL ${imageMetadataLabel}="${imageMetadataLabelValue}"`;
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/imageMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,22 @@ describe('Image Metadata', function () {
assert.strictEqual(label.replace(/ \\\n/g, ''), `LABEL devcontainer.metadata="${JSON.stringify(expected).replace(/"/g, '\\"')}"`);
});

it('should create array label for single metadata entry (docker-compose with Dockerfile, no features)', () => {
// When there is only one metadata entry, the label should still be a JSON array.
// Regression test for https://github.com/devcontainers/cli/issues/1054
const label = getDevcontainerMetadataLabel(configWithRaw([
{
remoteUser: 'testUser',
}
]));
const expected = [
{
remoteUser: 'testUser',
}
];
assert.strictEqual(label.replace(/ \\\n/g, ''), `LABEL devcontainer.metadata="${JSON.stringify(expected).replace(/"/g, '\\"')}"`);
});

it('should merge metadata from devcontainer.json and features', () => {
const merged = mergeConfiguration({
configFilePath: URI.parse('file:///devcontainer.json'),
Expand Down