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

asset-staging.ts: target platform ignored when bundling asset #30239

Open
t3r opened this issue May 16, 2024 · 2 comments · May be fixed by #30240
Open

asset-staging.ts: target platform ignored when bundling asset #30239

t3r opened this issue May 16, 2024 · 2 comments · May be fixed by #30240
Labels
@aws-cdk/aws-s3-deployment bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@t3r
Copy link

t3r commented May 16, 2024

Describe the bug

When bundling an asset e.g. in an s3_deployment using docker, the platform property gets ignored. The bundling always takes place on the host's platform.

Expected Behavior

Using
platform: 'linux/amd64'
should bundle for amd64 on M1 and
platform: 'linux/arm64'
should bundle for ARM on amd64 architecture as described in https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.BundlingOptions.html#platform

Current Behavior

platform: 'something' is silently ignored.

Reproduction Steps

Bundle for a s3_deployment like this:

new s3_deployment.BucketDeployment(this, 'platform-bug', {
      sources: [s3_deployment.Source.asset('.', {
        bundling: {
          image: lambda.Runtime.PYTHON_3_9.bundlingImage,
          platform: 'linux/amd64',
          //platform: 'linux/arm64',
          command: [
            'bash', '-c',
            'uname -m > /asset-output/uname-m.out.txt'
          ],
        },
      })],
      destinationBucket: bucket,
      destinationKeyPrefix: 'test',
    })

Do a cdk synthesize and look into the created output file 'uname-m.out.txt' asset in cdk.out. Whatever you put into 'platform', it always contains your host machine's platform string.

Possible Solution

The reason is that the platform given does not get propagated in aws-cdk-lib/core/lib/private/asset-staging.ts when calling image.run().
adding platform: this.options.platform at two places fixes the issue.
Pull request is on it's way.

Additional Information/Context

No response

CDK CLI Version

2.141.0 (build 3d1c06e)

Framework Version

No response

Node.js Version

v20.11.0

OS

macos 14.4.1 (23E224)

Language

TypeScript

Language Version

No response

Other information

As a sidenote: before changing the platform, the local docker build image, e.g. public.ecr.aws/sam/build-python3.9:latest has to be deleted manually using docker image rm public.ecr.aws/sam/build-python3.9:latest. Otherwise docker would use the same image for a different/wrong platform with unwanted behavior.
Fixing that is not within the scope of this issue.

@t3r t3r added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 16, 2024
@pahud
Copy link
Contributor

pahud commented May 16, 2024

Thank you for the report. We'll review your PR when it's ready.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels May 16, 2024
@t3r
Copy link
Author

t3r commented May 16, 2024

Thanks. PR#30240 is here.
Linter complains about missing tests but I intentionally did not implement it to not break tests on machines without docker buildx. Let me know if you need anything else.

t3r added a commit to kreuzwerker/aws-cdk that referenced this issue May 17, 2024
…th docker

Fixes aws#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3-deployment bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants