Skip to content

Commit

Permalink
fix(codebuild): add possibility to specify BUILD_GENERAL1_SMALL com…
Browse files Browse the repository at this point in the history
…pute 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*
  • Loading branch information
lpizzinidev committed Jun 12, 2023
1 parent e6073fc commit 2d74a46
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ export class LinuxGpuBuildImage implements IBindableBuildImage {
public validate(buildEnvironment: BuildEnvironment): string[] {
const ret = [];
if (buildEnvironment.computeType &&
buildEnvironment.computeType !== ComputeType.LARGE) {
ret.push(`GPU images only support ComputeType '${ComputeType.LARGE}' - ` +
buildEnvironment.computeType !== ComputeType.LARGE &&
buildEnvironment.computeType !== ComputeType.SMALL) {
ret.push(`GPU images only support ComputeType '${ComputeType.LARGE}' and '${ComputeType.SMALL}' - ` +
`'${buildEnvironment.computeType}' was given`);
}
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,39 @@ describe('Linux GPU build image', () => {
},
});
});

test('allows to specify a BUILD_GENERAL1_SMALL build environment', () => {
const stack = new cdk.Stack();

new codebuild.Project(stack, 'Project', {
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
build: { commands: ['ls'] },
},
}),
environment: {
buildImage: codebuild.LinuxGpuBuildImage.awsDeepLearningContainersImage(
'my-repo', 'my-tag', '123456789012'),
computeType: codebuild.ComputeType.SMALL,
},
});

Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::Project', {
Environment: {
ComputeType: 'BUILD_GENERAL1_SMALL',
Image: {
'Fn::Join': ['', [
'123456789012.dkr.ecr.',
{ Ref: 'AWS::Region' },
'.',
{ Ref: 'AWS::URLSuffix' },
'/my-repo:my-tag',
]],
},
},
});
});
});

describe('ECR Repository', () => {
Expand Down

0 comments on commit 2d74a46

Please sign in to comment.