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(codebuild): add new image types #32979

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion packages/aws-cdk-lib/aws-codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,16 @@ is available for specifying Lambda-compatible images.
You can specify one of the predefined Windows/Linux images by using one
of the constants such as `WindowsBuildImage.WIN_SERVER_CORE_2019_BASE`,
`WindowsBuildImage.WINDOWS_BASE_2_0`, `LinuxBuildImage.STANDARD_2_0`,
`LinuxBuildImage.AMAZON_LINUX_2_5`, `MacBuildImage.BASE_14`, `LinuxArmBuildImage.AMAZON_LINUX_2_ARM`,
`LinuxBuildImage.AMAZON_LINUX_2_5`, `LinuxArmBuildImage.AMAZON_LINUX_2_ARM`,
`LinuxLambdaBuildImage.AMAZON_LINUX_2_NODE_18` or `LinuxArmLambdaBuildImage.AMAZON_LINUX_2_NODE_18`.

For non-containerized environment types:

* `LINUX_EC2`: `LinuxBuildImage.AMAZON_LINUX_2023_1_0_AMI`
* `ARM_EC2`: `LinuxArmBuildImage.AMAZON_LINUX_2023_1_0_AMI`
* `WINDOWS_EC2`: `WindowsBuildImage.WIN_SERVER_2022_1_0_AMI`
* `MAC_ARM`: `MacBuildImage.BASE_14`

Alternatively, you can specify a custom image using one of the static methods on
`LinuxBuildImage`:

Expand Down
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
Loading