Skip to content

Commit b1f92d2

Browse files
committed
Support additional Docker build options (#85)
1 parent f7d4c85 commit b1f92d2

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/spec-configuration/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export type DevContainerFromDockerfileConfig = {
119119
target?: string;
120120
args?: Record<string, string>;
121121
cacheFrom?: string | string[];
122+
options?: string[];
122123
};
123124
}
124125
|
@@ -129,6 +130,7 @@ export type DevContainerFromDockerfileConfig = {
129130
target?: string;
130131
args?: Record<string, string>;
131132
cacheFrom?: string | string[];
133+
options?: string[];
132134
};
133135
}
134136
);

src/spec-node/singleContainer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ async function buildAndExtendImage(buildParams: DockerResolverParameters, config
243243
args.push('--build-arg', `${key}=${buildArgs[key]}`);
244244
}
245245
}
246+
const buildOptions = config.build?.options;
247+
if (buildOptions?.length) {
248+
args.push(...buildOptions);
249+
}
246250
args.push(...additionalBuildArgs);
247251
args.push(await uriToWSLFsPath(getDockerContextPath(cliHost, config), cliHost));
248252
try {

src/test/cli.build.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,5 +315,15 @@ describe('Dev Containers CLI', function () {
315315
const details = JSON.parse((await shellExec(`docker inspect test-subfolder-config`)).stdout)[0] as ImageDetails;
316316
assert.strictEqual(envListToObj(details.Config.Env).SUBFOLDER_CONFIG_IMAGE_ENV, 'true');
317317
});
318+
319+
it('should apply build options', async () => {
320+
const testFolder = `${__dirname}/configs/dockerfile-with-target`;
321+
const res = await shellExec(`${cli} build --workspace-folder ${testFolder}`);
322+
const response = JSON.parse(res.stdout);
323+
assert.equal(response.outcome, 'success');
324+
assert.ok(response.imageName);
325+
const details = JSON.parse((await shellExec(`docker inspect ${response.imageName}`)).stdout)[0] as ImageDetails;
326+
assert.strictEqual(details.Config.Labels?.test_build_options, 'success');
327+
});
318328
});
319329
});

src/test/configs/dockerfile-with-target/.devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"target": "desired-image",
55
"args": {
66
"VARIANT": "16-bullseye"
7-
}
7+
},
8+
"options": [ "--label", "test_build_options=success" ]
89
},
910
"postCreateCommand": "touch /tmp/postCreateCommand.testmarker",
1011
"postStartCommand": "touch /tmp/postStartCommand.testmarker",

0 commit comments

Comments
 (0)