Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignored platform property on bundling an asset with docker #30240

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions packages/aws-cdk-lib/core/lib/private/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class AssetBundlingBindMount extends AssetBundlingBase {
public run() {
this.options.image.run({
command: this.options.command,
platform: this.options.platform,
user: this.determineUser(),
environment: this.options.environment,
entrypoint: this.options.entrypoint,
Expand Down Expand Up @@ -178,6 +179,7 @@ export class AssetBundlingVolumeCopy extends AssetBundlingBase {

this.options.image.run({
command: this.options.command,
platform: this.options.platform,
user: user,
environment: this.options.environment,
entrypoint: this.options.entrypoint,
Expand Down
29 changes: 29 additions & 0 deletions packages/aws-cdk-lib/core/test/private/asset-staging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,33 @@ describe('bundling', () => {
'public.ecr.aws/docker/library/alpine',
]), { encoding: 'utf-8', stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);
});

test('AssetBundlingBindMount bundles with given platform', () => {
// GIVEN
sinon.stub(process, 'platform').value('darwin');
const spawnSyncStub = sinon.stub(child_process, 'spawnSync').returns({
status: 0,
stderr: Buffer.from('stderr'),
stdout: Buffer.from('stdout'),
pid: 123,
output: ['stdout', 'stderr'],
signal: null,
});
const options = {
sourcePath: '/tmp/source',
bundleDir: '/tmp/output',
image: DockerImage.fromRegistry('public.ecr.aws/docker/library/alpine'),
user: '1000',
platform: 'linux/arm64',
};
const helper = new AssetBundlingBindMount(options);
helper.run();

// actual docker run with bind mount is called
expect(spawnSyncStub.calledWith(DOCKER_CMD, sinon.match.array.contains([
'run', '--rm',
'--platform', 'linux/arm64',
'public.ecr.aws/docker/library/alpine',
]), { encoding: 'utf-8', stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);
});
});
Loading