Skip to content

Commit 037c03f

Browse files
Add platform arg to run container options (#259)
* Initial plan for issue * Add platform arg to run container options Co-authored-by: bwateratmsft <36966225+bwateratmsft@users.noreply.github.com> * Fix whitespace/line ending issues in DockerClientBase.ts Co-authored-by: bwateratmsft <36966225+bwateratmsft@users.noreply.github.com> * Remove unnecessary devDependencies from root package.json Co-authored-by: bwateratmsft <36966225+bwateratmsft@users.noreply.github.com> * Restore package-lock.json to original state Co-authored-by: bwateratmsft <36966225+bwateratmsft@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bwateratmsft <36966225+bwateratmsft@users.noreply.github.com>
1 parent 93a21af commit 037c03f

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

packages/vscode-container-client/src/clients/DockerClientBase/DockerClientBase.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ export abstract class DockerClientBase extends ConfigurableClient implements ICo
699699
withNamedArg('--env-file', options.environmentFiles),
700700
withNamedArg('--entrypoint', options.entrypoint),
701701
withDockerExposePortsArg(options.exposePorts),
702+
withDockerPlatformArg(options.platform),
702703
withVerbatimArg(options.customOptions),
703704
withArg(options.imageRef),
704705
typeof options.command === 'string' ? withVerbatimArg(options.command) : withArg(...(toArray(options.command || []))),

packages/vscode-container-client/src/contracts/ContainerClient.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ export type RunContainerCommandOptions = CommonCommandOptions & {
745745
* Optional expose ports for the container
746746
*/
747747
exposePorts?: Array<number>;
748+
/**
749+
* Target platform for the container
750+
*/
751+
platform?: ContainerPlatform;
748752
/**
749753
* Additional custom options to pass
750754
*/

packages/vscode-container-client/src/test/DockerClient.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,33 @@ describe('DockerClient (unit)', () => {
197197
expect(pwshQuoted).to.deep.equal(['container', 'run', 'someimage', 'sh', '-c', 'echo` hello` world']);
198198
expect(bashQuoted).to.deep.equal(['container', 'run', 'someimage', 'sh', '-c', 'echo\\ hello\\ world']);
199199
});
200+
201+
it('Should include platform flag when platform is specified', async () => {
202+
const options: RunContainerCommandOptions = {
203+
imageRef: 'someimage',
204+
platform: {
205+
os: 'linux',
206+
architecture: 'arm64'
207+
},
208+
};
209+
210+
const commandResponse = await client.runContainer(options);
211+
const args = commandResponse.args;
212+
213+
// Find the position of --platform flag
214+
const platformFlagIndex = args.findIndex(arg =>
215+
typeof arg === 'string' ? arg === '--platform' : arg.value === '--platform'
216+
);
217+
218+
// Verify that --platform flag is present
219+
expect(platformFlagIndex).to.be.greaterThan(-1);
220+
221+
// Verify that the value after --platform matches our expected platform
222+
const platformValue = args[platformFlagIndex + 1];
223+
const platformValueStr = typeof platformValue === 'string'
224+
? platformValue
225+
: platformValue.value;
226+
227+
expect(platformValueStr).to.equal('linux/arm64');
228+
});
200229
});

0 commit comments

Comments
 (0)