Skip to content

Commit 6d756e2

Browse files
committed
feat(codebuild): add new image types
1 parent 2b2443d commit 6d756e2

File tree

4 files changed

+77
-7
lines changed

4 files changed

+77
-7
lines changed

packages/aws-cdk-lib/aws-codebuild/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,16 @@ is available for specifying Lambda-compatible images.
329329
You can specify one of the predefined Windows/Linux images by using one
330330
of the constants such as `WindowsBuildImage.WIN_SERVER_CORE_2019_BASE`,
331331
`WindowsBuildImage.WINDOWS_BASE_2_0`, `LinuxBuildImage.STANDARD_2_0`,
332-
`LinuxBuildImage.AMAZON_LINUX_2_5`, `MacBuildImage.BASE_14`, `LinuxArmBuildImage.AMAZON_LINUX_2_ARM`,
332+
`LinuxBuildImage.AMAZON_LINUX_2_5`, `LinuxArmBuildImage.AMAZON_LINUX_2_ARM`,
333333
`LinuxLambdaBuildImage.AMAZON_LINUX_2_NODE_18` or `LinuxArmLambdaBuildImage.AMAZON_LINUX_2_NODE_18`.
334334

335+
For non-containerized environment types:
336+
337+
* `LINUX_EC2`: `LinuxBuildImage.AMAZON_LINUX_2023_1_0_AMI`
338+
* `ARM_EC2`: `LinuxArmBuildImage.AMAZON_LINUX_2023_1_0_AMI`
339+
* `WINDOWS_EC2`: `WindowsBuildImage.WIN_SERVER_2022_1_0_AMI`
340+
* `MAC_ARM`: `MacBuildImage.BASE_14`
341+
335342
Alternatively, you can specify a custom image using one of the static methods on
336343
`LinuxBuildImage`:
337344

packages/aws-cdk-lib/aws-codebuild/lib/linux-arm-build-image.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ import { BuildEnvironment, IBuildImage, ImagePullPrincipalType, DockerImageOptio
66
import * as ecr from '../../aws-ecr';
77
import * as secretsmanager from '../../aws-secretsmanager';
88

9+
/**
10+
* Environment type for Linux Arm Docker images or AMI
11+
*/
12+
export enum LinuxArmImageType {
13+
/**
14+
* The ARM_CONTAINER environment type
15+
*/
16+
ARM_CONTAINER = EnvironmentType.ARM_CONTAINER,
17+
18+
/**
19+
* The ARM_EC2 environment type
20+
*/
21+
ARM_EC2 = EnvironmentType.ARM_EC2,
22+
}
23+
924
/**
1025
* Construction properties of `LinuxArmBuildImage`.
1126
* Module-private, as the constructor of `LinuxArmBuildImage` is private.
@@ -15,6 +30,7 @@ interface LinuxArmBuildImageProps {
1530
readonly imagePullPrincipalType?: ImagePullPrincipalType;
1631
readonly secretsManagerCredentials?: secretsmanager.ISecret;
1732
readonly repository?: ecr.IRepository;
33+
readonly imageType?: LinuxArmImageType;
1834
}
1935

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

65+
/** The Amazon Linux aarch64 1.0 AMI, based on Amazon Linux 2023. */
66+
public static readonly AMAZON_LINUX_2023_1_0_AMI: IBuildImage = new LinuxArmBuildImage({
67+
imageId: 'aws/codebuild/ami/amazonlinux-arm-base:2023-1.0',
68+
imagePullPrincipalType: ImagePullPrincipalType.CODEBUILD,
69+
imageType: LinuxArmImageType.ARM_EC2,
70+
});
71+
4972
/**
5073
* @returns a aarch-64 Linux build image from a Docker Hub image.
5174
*/
@@ -93,14 +116,15 @@ export class LinuxArmBuildImage implements IBuildImage {
93116
});
94117
}
95118

96-
public readonly type = EnvironmentType.ARM_CONTAINER as string;
119+
public readonly type: string;
97120
public readonly defaultComputeType = ComputeType.LARGE;
98121
public readonly imageId: string;
99122
public readonly imagePullPrincipalType?: ImagePullPrincipalType;
100123
public readonly secretsManagerCredentials?: secretsmanager.ISecret;
101124
public readonly repository?: ecr.IRepository;
102125

103126
private constructor(props: LinuxArmBuildImageProps) {
127+
this.type = (props.imageType ?? LinuxArmImageType.ARM_CONTAINER).toString();
104128
this.imageId = props.imageId;
105129
this.imagePullPrincipalType = props.imagePullPrincipalType;
106130
this.secretsManagerCredentials = props.secretsManagerCredentials;

packages/aws-cdk-lib/aws-codebuild/lib/project.ts

+38-2
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,21 @@ export interface DockerImageOptions {
17791779
readonly secretsManagerCredentials?: secretsmanager.ISecret;
17801780
}
17811781

1782+
/**
1783+
* Environment type for Linux Docker images or AMI
1784+
*/
1785+
export enum LinuxImageType {
1786+
/**
1787+
* The LINUX_CONTAINER environment type
1788+
*/
1789+
LINUX_CONTAINER = EnvironmentType.LINUX_CONTAINER,
1790+
1791+
/**
1792+
* The LINUX_EC2 environment type
1793+
*/
1794+
LINUX_EC2 = EnvironmentType.LINUX_EC2,
1795+
}
1796+
17821797
/**
17831798
* Construction properties of `LinuxBuildImage`.
17841799
* Module-private, as the constructor of `LinuxBuildImage` is private.
@@ -1788,6 +1803,7 @@ interface LinuxBuildImageProps {
17881803
readonly imagePullPrincipalType?: ImagePullPrincipalType;
17891804
readonly secretsManagerCredentials?: secretsmanager.ISecret;
17901805
readonly repository?: ecr.IRepository;
1806+
readonly imageType?: LinuxImageType;
17911807
}
17921808

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

1874+
/** The Amazon Linux x86_64 1.0 AMI, based on Amazon Linux 2023. */
1875+
public static readonly AMAZON_LINUX_2023_1_0_AMI: IBuildImage = new LinuxBuildImage({
1876+
imageId: 'aws/codebuild/ami/amazonlinux-x86_64-base:2023-1.0',
1877+
imagePullPrincipalType: ImagePullPrincipalType.CODEBUILD,
1878+
imageType: LinuxImageType.LINUX_EC2,
1879+
});
1880+
18581881
/**
18591882
* Image "aws/codebuild/amazonlinux2-aarch64-standard:1.0".
18601883
* @see {LinuxArmBuildImage.AMAZON_LINUX_2_STANDARD_1_0}
@@ -1997,14 +2020,15 @@ export class LinuxBuildImage implements IBuildImage {
19972020
});
19982021
}
19992022

2000-
public readonly type = EnvironmentType.LINUX_CONTAINER as string;
2023+
public readonly type: string;
20012024
public readonly defaultComputeType = ComputeType.SMALL;
20022025
public readonly imageId: string;
20032026
public readonly imagePullPrincipalType?: ImagePullPrincipalType;
20042027
public readonly secretsManagerCredentials?: secretsmanager.ISecret;
20052028
public readonly repository?: ecr.IRepository;
20062029

20072030
private constructor(props: LinuxBuildImageProps) {
2031+
this.type = (props.imageType ?? LinuxImageType.LINUX_CONTAINER).toString();
20082032
this.imageId = props.imageId;
20092033
this.imagePullPrincipalType = props.imagePullPrincipalType;
20102034
this.secretsManagerCredentials = props.secretsManagerCredentials;
@@ -2027,7 +2051,7 @@ export class LinuxBuildImage implements IBuildImage {
20272051
}
20282052

20292053
/**
2030-
* Environment type for Windows Docker images
2054+
* Environment type for Windows Docker images or AMI
20312055
*/
20322056
export enum WindowsImageType {
20332057
/**
@@ -2049,6 +2073,11 @@ export enum WindowsImageType {
20492073
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/fleets.html
20502074
*/
20512075
SERVER_2022 = EnvironmentType.WINDOWS_SERVER_2022_CONTAINER,
2076+
2077+
/**
2078+
* The WINDOWS_EC2 environment type
2079+
*/
2080+
WINDOWS_EC2 = EnvironmentType.WINDOWS_EC2,
20522081
}
20532082

20542083
/**
@@ -2143,6 +2172,13 @@ export class WindowsBuildImage implements IBuildImage {
21432172
imageType: WindowsImageType.SERVER_2022,
21442173
});
21452174

2175+
/** The CodeBuild Windows Server 2022 1.0 AMI */
2176+
public static readonly WIN_SERVER_2022_1_0_AMI: IBuildImage = new WindowsBuildImage({
2177+
imageId: 'aws/codebuild/ami/windows-base:2022-1.0',
2178+
imagePullPrincipalType: ImagePullPrincipalType.CODEBUILD,
2179+
imageType: WindowsImageType.WINDOWS_EC2,
2180+
});
2181+
21462182
/**
21472183
* @returns a Windows build image from a Docker Hub image.
21482184
*/

packages/aws-cdk-lib/aws-codebuild/test/project.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -966,16 +966,19 @@ describe('Environment', () => {
966966
});
967967

968968
test.each([
969-
['Base 14', codebuild.MacBuildImage.BASE_14, 'aws/codebuild/macos-arm-base:14'],
970-
])('has build image for %s', (_, buildImage, expected) => {
969+
['macOS Base 14', codebuild.EnvironmentType.MAC_ARM, codebuild.MacBuildImage.BASE_14, 'aws/codebuild/macos-arm-base:14'],
970+
['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'],
971+
['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'],
972+
['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'],
973+
])('has build image for %s', (_, environmentType, buildImage, expected) => {
971974
// GIVEN
972975
const stack = new cdk.Stack();
973976
const bucket = s3.Bucket.fromBucketName(stack, 'Bucket', 'my-bucket'); // (stack, 'Bucket');
974977
const fleet = new codebuild.Fleet(stack, 'Fleet', {
975978
fleetName: 'MyFleet',
976979
baseCapacity: 1,
977980
computeType: codebuild.FleetComputeType.MEDIUM,
978-
environmentType: codebuild.EnvironmentType.MAC_ARM,
981+
environmentType: environmentType,
979982
});
980983

981984
// WHEN

0 commit comments

Comments
 (0)