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

feat(lambda): docker platform for architecture #16858

Merged
merged 8 commits into from
Oct 11, 2021

Conversation

jogold
Copy link
Contributor

@jogold jogold commented Oct 7, 2021

Add a dockerPlatform property in Architecture and use it to pass the
correct platform when bundling in a container in aws-lambda-nodejs,
aws-lambda-go and aws-lambda-python.

Note that the SAM build images (public.ecr.aws/sam/build-<runtime>) are now
multi-arch.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Add a `dockerPlatform` property in `Architecture` and use it to pass the
correct `platform` when bundling in a container in `aws-lambda-nodejs`,
`aws-lambda-go` and `aws-lambda-python`.
@gitpod-io
Copy link

gitpod-io bot commented Oct 7, 2021

@@ -117,6 +122,7 @@ export class Bundling implements cdk.BundlingOptions {
...props.buildArgs ?? {},
IMAGE: Runtime.GO_1_X.bundlingImage.image, // always use the GO_1_X build image
},
platform: props.architecture.dockerPlatform,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably need to remove the GOARCH environment variable on line 112 above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@@ -104,7 +109,7 @@ export class Bundling implements cdk.BundlingOptions {
const environment = {
CGO_ENABLED: cgoEnabled,
GO111MODULE: 'on',
GOARCH: 'amd64',
GOARCH: props.architecture.dockerPlatform.split('/')[1],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corymhall what about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better!

@jogold
Copy link
Contributor Author

jogold commented Oct 8, 2021

@nija-at @eladb can you take a look?

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@@ -10,23 +10,29 @@ export class Architecture {
/**
* 64 bit architecture with the ARM instruction set.
*/
public static readonly ARM_64 = new Architecture('arm64');
public static readonly ARM_64 = new Architecture('arm64', 'linux/arm64');

/**
* Used to specify a custom architecture name.
* Use this if the architecture name is not yet supported by the CDK.
* @param name the architecture name as recognized by AWS Lambda.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring for param

*/
public readonly dockerPlatform: string;

private constructor(archName: string, dockerPlatform?: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For safety, maybe make explicit:

Suggested change
private constructor(archName: string, dockerPlatform?: string) {
private constructor(archName: string, dockerPlatform: string) {

@jogold jogold requested a review from eladb October 11, 2021 07:43
eladb
eladb previously approved these changes Oct 11, 2021
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this resolve #12472?

@mergify mergify bot dismissed eladb’s stale review October 11, 2021 09:32

Pull request has been modified.

@jogold
Copy link
Contributor Author

jogold commented Oct 11, 2021

Does this resolve #12472?

No, #16770 will.

#12472 is about docker build in cdk-assets.

Can you reapprove? The build will now pass (now that 1.127.0 was merged back).

@mergify
Copy link
Contributor

mergify bot commented Oct 11, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 3df2d09
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 5c258a3 into aws:master Oct 11, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 11, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@jogold jogold deleted the lambda-arch-bundling-image branch October 11, 2021 11:54
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
Add a `dockerPlatform` property in `Architecture` and use it to pass the
correct `platform` when bundling in a container in `aws-lambda-nodejs`,
`aws-lambda-go` and `aws-lambda-python`.

Note that the SAM build images (`public.ecr.aws/sam/build-<runtime>`) are now
multi-arch.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit that referenced this pull request May 26, 2022
…ker images (#20439)

This PR adds support for specifying the desired build platform when building docker images (ie: build an arm64 image on an amd64/x86_64 host). Closes #12472 

This PR does NOT touch Lambda builders, only ECR assets. #16770 attempted to implement support for ECR and Lambda but was abandoned. Meanwhile #16858 implemented lambda platform support. This implements the ECR side

I have run `yarn integ`

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants