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
2 changes: 1 addition & 1 deletion src/spec-node/dockerCompose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ while sleep 1 & wait $$!; do :; done", "-"${userEntrypoint.map(a => `, ${JSON.st
init: true` : ''}${user ? `
user: ${user}` : ''}${Object.keys(env).length ? `
environment:${Object.keys(env).map(key => `
- ${key}=${env[key]}`).join('')}` : ''}${mergedConfig.privileged ? `
- '${key}=${env[key].replace(/\n/g, '\\n').replace(/\$/g, '$$$$').replace(/'/g, '\'\'')}'`).join('')}` : ''}${mergedConfig.privileged ? `
privileged: true` : ''}${capAdd.length ? `
cap_add:${capAdd.map(cap => `
- ${cap}`).join('')}` : ''}${securityOpts.length ? `
Expand Down
34 changes: 34 additions & 0 deletions src/test/cli.up.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,40 @@ describe('Dev Containers CLI', function () {
await shellExec(`docker rm -f ${containerId}`);
});

it('should follow the correct merge logic for containerEnv using docker compose', async () => {
const res = await shellExec(`${cli} up --workspace-folder ${__dirname}/configs/image-containerEnv-issue`);
const response = JSON.parse(res.stdout);
assert.equal(response.outcome, 'success');
const containerId: string = response.containerId;
assert.ok(containerId, 'Container id not found.');

const somePath = await shellExec(`docker exec ${containerId} bash -c 'echo -n $SOME_PATH'`);
assert.equal('/tmp/path/doc-ver/loc', somePath.stdout);

const envWithSpaces = await shellExec(`docker exec ${containerId} bash -c 'echo -n $VAR_WITH_SPACES'`);
assert.equal('value with spaces', envWithSpaces.stdout);

const evalEnvWithCommand = await shellExec(`docker exec ${containerId} bash -c 'eval $ENV_WITH_COMMAND'`);
assert.equal('Hello, World!', evalEnvWithCommand.stdout);

const envWithTestMessage = await shellExec(`docker exec ${containerId} bash -c 'echo -n $Test_Message'`);
assert.equal('H"\\n\\ne"\'\'\'llo M:;a/t?h&^iKa%#@!``ni,sk_a-', envWithTestMessage.stdout);

const envWithFormat = await shellExec(`docker exec ${containerId} bash -c 'echo -n $ROSCONSOLE_FORMAT'`);
assert.equal('[$${severity}] [$${walltime:%Y-%m-%d %H:%M:%S}] [$${node}]: $${message}', envWithFormat.stdout);

const envWithDoubleQuote = await shellExec(`docker exec ${containerId} bash -c 'echo -n $VAR_WITH_QUOTES_WE_WANT_TO_KEEP'`);
assert.equal('value with \"quotes\" we want to keep', envWithDoubleQuote.stdout);

const envWithDollar = await shellExec(`docker exec ${containerId} bash -c 'echo -n $VAR_WITH_DOLLAR_SIGN'`);
assert.equal('value with $dollar sign', envWithDollar.stdout);

const envWithBackSlash = await shellExec(`docker exec ${containerId} bash -c 'echo -n $VAR_WITH_BACK_SLASH'`);
assert.equal('value with \\back slash', envWithBackSlash.stdout);

await shellExec(`docker rm -f ${containerId}`);
});

it('should run with config in subfolder', async () => {
const upRes = await shellExec(`${cli} up --workspace-folder ${__dirname}/configs/dockerfile-without-features --config ${__dirname}/configs/dockerfile-without-features/.devcontainer/subfolder/devcontainer.json`);
const response = JSON.parse(upRes.stdout);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"dockerComposeFile": "docker-compose.yml",
"service": "devcontainerissues",
"workspaceFolder": "/workspaces/cli",
"containerEnv": {
"SOME_PATH": "/tmp/path/doc-ver/loc",
"Test_Message": "H\"\n\ne\"'''llo M:;a/t?h&^iKa%#@!``ni,sk_a-",
"ROSCONSOLE_FORMAT": "[$${severity}] [$${walltime:%Y-%m-%d %H:%M:%S}] [$${node}]: $${message}",
"VAR_WITH_SPACES": "value with spaces",
"VAR_WITH_QUOTES_WE_WANT_TO_KEEP": "value with \"quotes\" we want to keep",
"VAR_WITH_DOLLAR_SIGN": "value with $dollar sign",
"VAR_WITH_BACK_SLASH": "value with \\back slash",
"ENV_WITH_COMMAND": "bash -c 'echo -n \"Hello, World!\"'"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
devcontainerissues:
# set this to the premade image generated by running the 'original_container' vsc-original-container-c521b00ea40fee92e585b105d9e4f1699ad8216f18220c1b914451f2eafef3b4
image: mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm
volumes:
- ../..:/workspaces:cached
environment:
FOO: b"\n\ta"r
Test_Message: "Hello Max"
ROSCONSOLE_FORMAT: "Ros from compose"
command: sleep infinity

Loading