Skip to content

Commit

Permalink
fix(asset-staging): ignored platform property on bundling an asset wi…
Browse files Browse the repository at this point in the history
…th docker

Fixes #30239

The bundling-properties value was not copied from the AssetBundling properties
to the image.run properties so the --platform option for docker run was never
added.

This patch copies the platform property for AssetBundlingBindMount and
AssetBundlingVolumeCopy.

This fix makes the 'platform' property work as described in
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.BundlingOptions.html#platform

    - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
  • Loading branch information
t3r committed May 17, 2024
1 parent 8bac15d commit d2f29bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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);
});
});

0 comments on commit d2f29bc

Please sign in to comment.