Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/container-image-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createHash } from 'crypto';
import { existsSync, readFileSync } from 'fs';
import { join } from 'path';
import { CfnResource, CustomResource, Duration, RemovalPolicy } from 'aws-cdk-lib';
import { BuildSpec, LinuxBuildImage } from 'aws-cdk-lib/aws-codebuild';
import { BuildSpec, ComputeType, LinuxArmBuildImage, LinuxBuildImage } from 'aws-cdk-lib/aws-codebuild';
import { IVpc } from 'aws-cdk-lib/aws-ec2';
import { IRepository, Repository } from 'aws-cdk-lib/aws-ecr';
import { DockerImageAssetProps } from 'aws-cdk-lib/aws-ecr-assets';
Expand Down Expand Up @@ -64,12 +64,12 @@ export class ContainerImageBuild extends Construct implements IGrantable {
timeout: Duration.minutes(5),
});

// use buildx for cross-platform image build.
// because soci-snapshotter currently only supports amd64 environment.
// const armImage = LinuxArmBuildImage.fromCodeBuildImageId('aws/codebuild/amazonlinux2-aarch64-standard:3.0');
// Use buildx for cross-platform image build
const armImage = LinuxArmBuildImage.fromCodeBuildImageId('aws/codebuild/amazonlinux2-aarch64-standard:3.0');
const x64Image = LinuxBuildImage.fromCodeBuildImageId('aws/codebuild/standard:7.0');
// const buildImage = props.platform == Platform.LINUX_ARM64 ? armImage : x64Image;
const buildImage = x64Image;
// Select the build image based on the target platform
const isArm64 = props.platform?.platform === 'linux/arm64';
const buildImage = isArm64 ? armImage : x64Image;

let repository = props.repository;
if (repository === undefined) {
Expand All @@ -79,8 +79,9 @@ export class ContainerImageBuild extends Construct implements IGrantable {

const project = new SingletonProject(this, 'Project', {
uuid: 'e83729fe-b156-4e70-9bec-452b15847a30',
projectPurpose: 'ContainerImageBuildAmd64',
projectPurpose: isArm64 ? 'ContainerImageBuildArm64' : 'ContainerImageBuildAmd64',
environment: {
computeType: ComputeType.SMALL,
buildImage: buildImage,
privileged: true,
},
Expand Down
5 changes: 5 additions & 0 deletions src/singleton-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ export class SingletonProject extends Construct {
// Things that can be added to the slug later (we have to create a new project per these properties):
// * vpc addr
// * instance type
// * platform (amd64/arm64)
// But actually, replacement will not cause any disruption because of its stateless nature.
let slug = '';
slug += props.vpc?.node.addr ?? '';
// Get platform info from environment.buildImage if available
if (props.environment?.buildImage) {
slug += props.environment.buildImage.toString().includes('aarch64') ? 'arm64' : 'amd64';
}
return slug;
}

Expand Down
Loading