Skip to content

Commit 2d74a46

Browse files
authored
fix(codebuild): add possibility to specify BUILD_GENERAL1_SMALL compute type with Linux GPU build image (#25880)
This fix allows specifying the `BUILD_GENERAL1_SMALL` compute type when using a Linux GPU to build an image as defined in the [docs](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html). Closes #25857. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e6073fc commit 2d74a46

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ export class LinuxGpuBuildImage implements IBindableBuildImage {
142142
public validate(buildEnvironment: BuildEnvironment): string[] {
143143
const ret = [];
144144
if (buildEnvironment.computeType &&
145-
buildEnvironment.computeType !== ComputeType.LARGE) {
146-
ret.push(`GPU images only support ComputeType '${ComputeType.LARGE}' - ` +
145+
buildEnvironment.computeType !== ComputeType.LARGE &&
146+
buildEnvironment.computeType !== ComputeType.SMALL) {
147+
ret.push(`GPU images only support ComputeType '${ComputeType.LARGE}' and '${ComputeType.SMALL}' - ` +
147148
`'${buildEnvironment.computeType}' was given`);
148149
}
149150
return ret;

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

+33
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,39 @@ describe('Linux GPU build image', () => {
5757
},
5858
});
5959
});
60+
61+
test('allows to specify a BUILD_GENERAL1_SMALL build environment', () => {
62+
const stack = new cdk.Stack();
63+
64+
new codebuild.Project(stack, 'Project', {
65+
buildSpec: codebuild.BuildSpec.fromObject({
66+
version: '0.2',
67+
phases: {
68+
build: { commands: ['ls'] },
69+
},
70+
}),
71+
environment: {
72+
buildImage: codebuild.LinuxGpuBuildImage.awsDeepLearningContainersImage(
73+
'my-repo', 'my-tag', '123456789012'),
74+
computeType: codebuild.ComputeType.SMALL,
75+
},
76+
});
77+
78+
Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::Project', {
79+
Environment: {
80+
ComputeType: 'BUILD_GENERAL1_SMALL',
81+
Image: {
82+
'Fn::Join': ['', [
83+
'123456789012.dkr.ecr.',
84+
{ Ref: 'AWS::Region' },
85+
'.',
86+
{ Ref: 'AWS::URLSuffix' },
87+
'/my-repo:my-tag',
88+
]],
89+
},
90+
},
91+
});
92+
});
6093
});
6194

6295
describe('ECR Repository', () => {

0 commit comments

Comments
 (0)