Skip to content

Commit

Permalink
feat(codebuild): add new image types
Browse files Browse the repository at this point in the history
  • Loading branch information
awszhen committed Jan 17, 2025
1 parent 2b2443d commit 35f6153
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
26 changes: 25 additions & 1 deletion packages/aws-cdk-lib/aws-codebuild/lib/linux-arm-build-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import { BuildEnvironment, IBuildImage, ImagePullPrincipalType, DockerImageOptio
import * as ecr from '../../aws-ecr';
import * as secretsmanager from '../../aws-secretsmanager';

/**
* Environment type for Linux Arm Docker images or AMI
*/
export enum LinuxArmImageType {
/**
* The ARM_CONTAINER environment type
*/
ARM_CONTAINER = EnvironmentType.ARM_CONTAINER,

/**
* The ARM_EC2 environment type
*/
ARM_EC2 = EnvironmentType.ARM_EC2,
}

/**
* Construction properties of `LinuxArmBuildImage`.
* Module-private, as the constructor of `LinuxArmBuildImage` is private.
Expand All @@ -15,6 +30,7 @@ interface LinuxArmBuildImageProps {
readonly imagePullPrincipalType?: ImagePullPrincipalType;
readonly secretsManagerCredentials?: secretsmanager.ISecret;
readonly repository?: ecr.IRepository;
readonly imageType?: LinuxArmImageType;
}

/**
Expand Down Expand Up @@ -46,6 +62,13 @@ export class LinuxArmBuildImage implements IBuildImage {
/** Image "aws/codebuild/amazonlinux-aarch64-standard:3.0" based on Amazon Linux 2023. */
public static readonly AMAZON_LINUX_2023_STANDARD_3_0 = LinuxArmBuildImage.fromCodeBuildImageId('aws/codebuild/amazonlinux-aarch64-standard:3.0');

/** The Amazon Linux aarch64 1.0 AMI, based on Amazon Linux 2023. */
public static readonly AMAZON_LINUX_2023_1_0_AMI: IBuildImage = new LinuxArmBuildImage({
imageId: 'aws/codebuild/ami/amazonlinux-arm-base:2023-1.0',
imagePullPrincipalType: ImagePullPrincipalType.CODEBUILD,
imageType: LinuxArmImageType.ARM_EC2,
});

/**
* @returns a aarch-64 Linux build image from a Docker Hub image.
*/
Expand Down Expand Up @@ -93,14 +116,15 @@ export class LinuxArmBuildImage implements IBuildImage {
});
}

public readonly type = EnvironmentType.ARM_CONTAINER as string;
public readonly type: string;
public readonly defaultComputeType = ComputeType.LARGE;
public readonly imageId: string;
public readonly imagePullPrincipalType?: ImagePullPrincipalType;
public readonly secretsManagerCredentials?: secretsmanager.ISecret;
public readonly repository?: ecr.IRepository;

private constructor(props: LinuxArmBuildImageProps) {
this.type = (props.imageType ?? LinuxArmImageType.ARM_CONTAINER).toString();
this.imageId = props.imageId;
this.imagePullPrincipalType = props.imagePullPrincipalType;
this.secretsManagerCredentials = props.secretsManagerCredentials;
Expand Down
40 changes: 38 additions & 2 deletions packages/aws-cdk-lib/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,21 @@ export interface DockerImageOptions {
readonly secretsManagerCredentials?: secretsmanager.ISecret;
}

/**
* Environment type for Linux Docker images or AMI
*/
export enum LinuxImageType {
/**
* The LINUX_CONTAINER environment type
*/
LINUX_CONTAINER = EnvironmentType.LINUX_CONTAINER,

/**
* The LINUX_EC2 environment type
*/
LINUX_EC2 = EnvironmentType.LINUX_EC2,
}

/**
* Construction properties of `LinuxBuildImage`.
* Module-private, as the constructor of `LinuxBuildImage` is private.
Expand All @@ -1788,6 +1803,7 @@ interface LinuxBuildImageProps {
readonly imagePullPrincipalType?: ImagePullPrincipalType;
readonly secretsManagerCredentials?: secretsmanager.ISecret;
readonly repository?: ecr.IRepository;
readonly imageType?: LinuxImageType;
}

// Keep around to resolve a circular dependency until removing deprecated ARM image constants from LinuxBuildImage
Expand Down Expand Up @@ -1855,6 +1871,13 @@ export class LinuxBuildImage implements IBuildImage {
/** The Amazon Coretto 11 image x86_64, based on Amazon Linux 2023. */
public static readonly AMAZON_LINUX_2023_CORETTO_11 = LinuxBuildImage.codeBuildImage('aws/codebuild/amazonlinux-x86_64-standard:corretto11');

/** The Amazon Linux x86_64 1.0 AMI, based on Amazon Linux 2023. */
public static readonly AMAZON_LINUX_2023_1_0_AMI: IBuildImage = new LinuxBuildImage({
imageId: 'aws/codebuild/ami/amazonlinux-x86_64-base:2023-1.0',
imagePullPrincipalType: ImagePullPrincipalType.CODEBUILD,
imageType: LinuxImageType.LINUX_EC2,
});

/**
* Image "aws/codebuild/amazonlinux2-aarch64-standard:1.0".
* @see {LinuxArmBuildImage.AMAZON_LINUX_2_STANDARD_1_0}
Expand Down Expand Up @@ -1997,14 +2020,15 @@ export class LinuxBuildImage implements IBuildImage {
});
}

public readonly type = EnvironmentType.LINUX_CONTAINER as string;
public readonly type: string;
public readonly defaultComputeType = ComputeType.SMALL;
public readonly imageId: string;
public readonly imagePullPrincipalType?: ImagePullPrincipalType;
public readonly secretsManagerCredentials?: secretsmanager.ISecret;
public readonly repository?: ecr.IRepository;

private constructor(props: LinuxBuildImageProps) {
this.type = (props.imageType ?? LinuxImageType.LINUX_CONTAINER).toString();
this.imageId = props.imageId;
this.imagePullPrincipalType = props.imagePullPrincipalType;
this.secretsManagerCredentials = props.secretsManagerCredentials;
Expand All @@ -2027,7 +2051,7 @@ export class LinuxBuildImage implements IBuildImage {
}

/**
* Environment type for Windows Docker images
* Environment type for Windows Docker images or AMI
*/
export enum WindowsImageType {
/**
Expand All @@ -2049,6 +2073,11 @@ export enum WindowsImageType {
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/fleets.html
*/
SERVER_2022 = EnvironmentType.WINDOWS_SERVER_2022_CONTAINER,

/**
* The WINDOWS_EC2 environment type
*/
WINDOWS_EC2 = EnvironmentType.WINDOWS_EC2,
}

/**
Expand Down Expand Up @@ -2143,6 +2172,13 @@ export class WindowsBuildImage implements IBuildImage {
imageType: WindowsImageType.SERVER_2022,
});

/** The CodeBuild Windows Server 2022 1.0 AMI */
public static readonly WIN_SERVER_2022_1_0_AMI: IBuildImage = new WindowsBuildImage({
imageId: 'aws/codebuild/ami/windows-base:2022-1.0',
imagePullPrincipalType: ImagePullPrincipalType.CODEBUILD,
imageType: WindowsImageType.WINDOWS_EC2,
});

/**
* @returns a Windows build image from a Docker Hub image.
*/
Expand Down
9 changes: 6 additions & 3 deletions packages/aws-cdk-lib/aws-codebuild/test/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,16 +966,19 @@ describe('Environment', () => {
});

test.each([
['Base 14', codebuild.MacBuildImage.BASE_14, 'aws/codebuild/macos-arm-base:14'],
])('has build image for %s', (_, buildImage, expected) => {
['macOS Base 14', codebuild.EnvironmentType.MAC_ARM, codebuild.MacBuildImage.BASE_14, 'aws/codebuild/macos-arm-base:14'],
['Linux EC2 AL2023 1.0', codebuild.EnvironmentType.LINUX_EC2, codebuild.LinuxBuildImage.AMAZON_LINUX_2023_1_0_AMI, 'aws/codebuild/ami/amazonlinux-x86_64-base:2023-1.0'],
['Arm EC2 AL2023 1.0', codebuild.EnvironmentType.ARM_EC2, codebuild.LinuxArmBuildImage.AMAZON_LINUX_2023_1_0_AMI, 'aws/codebuild/ami/amazonlinux-arm-base:2023-1.0'],
['Windows EC2 Server 2022 1.0', codebuild.EnvironmentType.WINDOWS_EC2, codebuild.WindowsBuildImage.WIN_SERVER_2022_1_0_AMI, 'aws/codebuild/ami/windows-base:2022-1.0'],
])('has build image for %s', (_, environmentType, buildImage, expected) => {
// GIVEN
const stack = new cdk.Stack();
const bucket = s3.Bucket.fromBucketName(stack, 'Bucket', 'my-bucket'); // (stack, 'Bucket');
const fleet = new codebuild.Fleet(stack, 'Fleet', {
fleetName: 'MyFleet',
baseCapacity: 1,
computeType: codebuild.FleetComputeType.MEDIUM,
environmentType: codebuild.EnvironmentType.MAC_ARM,
environmentType: environmentType,
});

// WHEN
Expand Down

0 comments on commit 35f6153

Please sign in to comment.