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

CodeBuild: Cannot create Arm64 CodeBuild image in CDK running on Amd64 #28863

Closed
m17kea opened this issue Jan 25, 2024 · 5 comments
Closed

CodeBuild: Cannot create Arm64 CodeBuild image in CDK running on Amd64 #28863

m17kea opened this issue Jan 25, 2024 · 5 comments
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@m17kea
Copy link

m17kea commented Jan 25, 2024

Describe the bug

We are migrating from x86 to ARM and replicated our custom x86 CodeBuild Asset, configuring it to arm64. On deploying CDK the Arm64 image generates an error.

Expected Behavior

The --platform linux/arm64 flag should be respected and create the Asset successfully

Current Behavior

When this is built in the Docker Assets section of the pipeline it passes the correct --platform flag but errors with exec format error:

[Container] 2024/01/10 17:25:57.077503 Running command cdk-assets --path "assembly-PipelineStack-Shared/PipelineStackShared9B4542E9.assets.json" --verbose publish "f6f587c6f6c04d3ede0cca15a7c920f0e3cc960dd23723b26a1f969681050bc3:333996703325-us-east-1"
11708 | verbose: Loaded manifest from assembly-PipelineStack-Shared/PipelineStackShared9B4542E9.assets.json: 24 assets found
11709 | verbose: Applied selection: 1 assets selected.
11710 | info   : [0%] start: Publishing f6f587c6f6c04d3ede0cca15a7c920f0e3cc960dd23723b26a1f969681050bc3:333996703325-us-east-1
11711 | verbose: [0%] check: Check 333996703325.dkr.ecr.us-east-1.amazonaws.com/cdk-hnb659fds-container-assets-333996703325-us-east-1:f6f587c6f6c04d3ede0cca15a7c920f0e3cc960dd23723b26a1f969681050bc3
11712 | verbose: [0%] debug: docker login --username AWS --password-stdin https://333996703325.dkr.ecr.us-east-1.amazonaws.com
11713 | verbose: [0%] debug: docker inspect cdkasset-f6f587c6f6c04d3ede0cca15a7c920f0e3cc960dd23723b26a1f969681050bc3
11714 | verbose: [0%] build: Building Docker image at /codebuild/output/src3223018135/src/asset.f6f587c6f6c04d3ede0cca15a7c920f0e3cc960dd23723b26a1f969681050bc3
11715 | verbose: [0%] debug: docker build --tag cdkasset-f6f587c6f6c04d3ede0cca15a7c920f0e3cc960dd23723b26a1f969681050bc3 --file ./Amazon2023_ARM/Dockerfile --platform linux/arm64 .
11716 | #0 building with "default" instance using docker driver
11717 |  
11718 | #1 [internal] load .dockerignore
11719 | #1 transferring context: 2B done
11720 | #1 DONE 0.1s
11721 |  
11722 | #2 [internal] load build definition from Dockerfile
11723 | #2 transferring dockerfile: 2.83kB done
11724 | #2 DONE 0.1s
11725 |  
11726 | #3 [internal] load metadata for public.ecr.aws/codebuild/amazonlinux2-aarch64-standard:3.0
11727 | #3 DONE 0.4s
11728 |  
11729 | #4 [internal] load build context
11730 | #4 transferring context: 6.30kB done
11731 | #4 DONE 0.0s
11732 |  
11733 | #5 [derivitec_arm  1/11] FROM public.ecr.aws/codebuild/amazonlinux2-aarch64-standard:3.0@sha256:eceb7e9bbe9f9f2cd45610f6e2c60ee598d70df743b0cd6e4e6612f1e8fc55cf
11734 | #5 resolve public.ecr.aws/codebuild/amazonlinux2-aarch64-standard:3.0@sha256:eceb7e9bbe9f9f2cd45610f6e2c60ee598d70df743b0cd6e4e6612f1e8fc55cf 0.0s done
11998 | #5 DONE 85.4s
11999 |  
12000 | #6 [derivitec_arm  2/11] RUN set -ex     && yum update -y     && yum clean metadata     && yum install -y postgresql15-server     && yum install -y boost     && yum install -y boost-devel     && yum install -y cmake     && yum install -y ninja-build
12001 | #6 0.371 exec /bin/sh: exec format error
12002 | #6 ERROR: process "/bin/sh -c set -ex     && yum update -y     && yum clean metadata     && yum install -y postgresql15-server     && yum install -y boost     && yum install -y boost-devel     && yum install -y cmake     && yum install -y ninja-build" did not complete successfully: exit code: 1
12003 | ------
12004 | > [derivitec_arm  2/11] RUN set -ex     && yum update -y     && yum clean metadata     && yum install -y postgresql15-server     && yum install -y boost     && yum install -y boost-devel     && yum install -y cmake     && yum install -y ninja-build:
12005 | 0.371 exec /bin/sh: exec format error
12006 | ------
12007 | Dockerfile:8
12008 | --------------------
12009 | 7 \|     # Install utilities
12010 | 8 \| >>> RUN set -ex \
12011 | 9 \| >>>     && yum update -y \
12012 | 10 \| >>>     && yum clean metadata \
12013 | 11 \| >>>     && yum install -y postgresql15-server \
12014 | 12 \| >>>     && yum install -y boost \
12015 | 13 \| >>>     && yum install -y boost-devel \
12016 | 14 \| >>>     && yum install -y cmake \
12017 | 15 \| >>>     && yum install -y ninja-build
12018 | 16 \|
12019 | --------------------
12020 | ERROR: failed to solve: process "/bin/sh -c set -ex     && yum update -y     && yum clean metadata     && yum install -y postgresql15-server     && yum install -y boost     && yum install -y boost-devel     && yum install -y cmake     && yum install -y ninja-build" did not complete successfully: exit code: 1
12021 | error  : [100%] fail: docker build --tag cdkasset-f6f587c6f6c04d3ede0cca15a7c920f0e3cc960dd23723b26a1f969681050bc3 --file ./Amazon2023_ARM/Dockerfile --platform linux/arm64 . exited with error code 1: #0 building with "default" instance using docker driver

Reproduction Steps

https://github.com/m17kea/cdk-arm

I've also included another branch arm which reverses the problem, building amd64 on arm build images which fails in the same way.

Possible Solution

Use docker buildx

Additional Information/Context

No response

CDK CLI Version

2.123.0 (build a594112)

Framework Version

No response

Node.js Version

v18.17.1

OS

Mac OS Sonoma 14.2.1

Language

TypeScript

Language Version

No response

Other information

No response

@m17kea m17kea added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 25, 2024
@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Jan 25, 2024
@pahud
Copy link
Contributor

pahud commented Jan 29, 2024

To build ARM images with CodeBuild, generally you have two options:

Option 1

  1. Use ARM64 build images with LinuxArmBuildImage. I guess you'll need to modify here.
  2. Specify a base image that is offering ARM64 compatibility. I guess your base image should be good.

Option 2

Using buildx as described here, which is a little bit tricky.

I would recommend option 1 in your case. The exec format error is usually due to incorrect build image architecture.

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 29, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 31, 2024
@m17kea
Copy link
Author

m17kea commented Jan 31, 2024

LinuxArmBuildImage does not have a FromAsset method. Shouldn't my code work as is? Otherwise why have platform as a property? It's smart enough to pass the correct --platform operator in the docker command so is it a problem with the build image CDK is using? This build image claims to be compatible with the --platform parameter, doesn't it?

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jan 31, 2024
@pahud
Copy link
Contributor

pahud commented Jun 3, 2024

Looking at the fromAsset() implementation, you will need to create DockerImageAsset by passing relevant props before you can create the LinuxBuildImage.

public static fromAsset(scope: Construct, id: string, props: DockerImageAssetProps): IBuildImage {
const asset = new DockerImageAsset(scope, id, props);
return new LinuxBuildImage({
imageId: asset.imageUri,
imagePullPrincipalType: ImagePullPrincipalType.SERVICE_ROLE,
repository: asset.repository,
});
}

@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 3, 2024
Copy link

github-actions bot commented Jun 6, 2024

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants