Skip to content

Commit e1e966e

Browse files
Copilotbwateratmsft
andcommitted
Add platform arg to run container options
Co-authored-by: bwateratmsft <36966225+bwateratmsft@users.noreply.github.com>
1 parent 98ecdf9 commit e1e966e

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,12 @@ export abstract class DockerClientBase extends ConfigurableClient implements ICo
695695
withDockerAddHostArg(options.addHost),
696696
withDockerMountsArg(options.mounts),
697697
withDockerLabelsArg(options.labels),
698-
withDockerEnvArg(options.environmentVariables),
699-
withNamedArg('--env-file', options.environmentFiles),
700-
withNamedArg('--entrypoint', options.entrypoint),
701-
withDockerExposePortsArg(options.exposePorts),
702-
withVerbatimArg(options.customOptions),
698+
withDockerEnvArg(options.environmentVariables),
699+
withNamedArg('--env-file', options.environmentFiles),
700+
withNamedArg('--entrypoint', options.entrypoint),
701+
withDockerExposePortsArg(options.exposePorts),
702+
withDockerPlatformArg(options.platform),
703+
withVerbatimArg(options.customOptions),
703704
withArg(options.imageRef),
704705
typeof options.command === 'string' ? withVerbatimArg(options.command) : withArg(...(toArray(options.command || []))),
705706
)();

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)