What do my MacBook Pro and my container workload running on ECS and Fargate have in common? They both run amazingly well on the ARM processor architecture. However, building Docker images for Apple Silicon and AWS Graviton is challenging. Because a container image made for the X86_64 architecture -which is good old Intel and AMD processors- does not run on the ARM processor architecture out of the box. Therefore, you will learn how to build multi-architecture images for X86_64 as well as for ARM64 in the following.
Watch the following video to learn how to build multi-architecture images locally and with AWS CodeBuild. Besides that, we will show you how to deploy a container image to ECS and Fargate running on X86_64 and ARM64 (AWS Graviton).
JavaScript is disabled. Please visit YouTube.com to watch the video.
To test the image on your local machine, use the docker run command.
docker run 486555357186.dkr.ecr.eu-central-1.amazonaws.com/nodejs-express
That’s how to build a multi-architecture image locally. But how to do so as part of a CI/CD pipeline?
How to build a multi-arch container image with AWS CodeBuild
The following snippets give you an idea of how to build a multi-architecture image with the help of AWS CodeBuild as part of a deployment pipeline.
The following snippet shows a CloudFormation resource to configure a CodeBuild project. Check out the comments for explanations.
Project: Type:'AWS::CodeBuild::Project' Properties: Artifacts: Type:NO_ARTIFACTS Environment: ComputeType:BUILD_GENERAL1_SMALL# The build job itself runs on X86_64 but builds a multi-arch image EnvironmentVariables:# Some environment variables needed for the build -Name:ACCOUNT_ID Type:PLAINTEXT Value:!Ref'AWS::AccountId' -Name:REGION Type:PLAINTEXT Value:!Ref'AWS::Region' # ... Image:'aws/codebuild/standard:5.0'# CodeBuild provides Docker images to run the build PrivilegedMode:true# Required to build Docker images Type:LINUX_CONTAINER LogsConfig: CloudWatchLogs: GroupName:!RefProjectLogGroup Status:ENABLED Name:!Ref'AWS::StackName' ServiceRole:!GetAtt'ProjectRole.Arn' Source:# Run the build job for each commit pushed to your CodeCommit repository Location:!Sub'https://git-codecommit.${AWS::Region}.amazonaws.com/v1/repos/${CodeCommitRepositoryName}' Type:CODECOMMIT TimeoutInMinutes:45
The buildspec.yml file is used to define the build job. The aws/codebuild/standard:5.0 does not ship with the buildx plugin. That’s why we need to add the plugin during the install phase.
Unfortunately, the AWS Management Console does not show whether a container runs on X86_64 or ARM64. Use the following AWS CLI command to fetch more detailed information about a task, including the processor architecture.