Skip to content

Commit

Permalink
chore(codebuild): added validation when using Windows Image (aws#27946)
Browse files Browse the repository at this point in the history
When using `WINDOWS_SERVER_2019_CONTAINER`, only MEDIUM and LARGE computeType is supported.
https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html

However, currently only ComputeType `SMALL` is validated.
This PR modified to generate an error when ComputeType is specified as X2_LARGE in WindowsBuildImage.
```ts
    new codebuild.Project(this, 'CodeBuildCdk', {
      source: codebuild.Source.codeCommit({ repository: codecommit.Repository.fromRepositoryName(this, "Repo", "sample") }),
      environment: {
        computeType: codebuild.ComputeType.X2_LARGE, // generate error in synth stage
        buildImage:  codebuild.WindowsBuildImage.WINDOWS_BASE_2_0
      }
    });
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
sakurai-ryo authored and chenjane-dev committed Dec 5, 2023
1 parent 38c3adf commit 147420e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/aws-cdk-lib/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ export class WindowsBuildImage implements IBuildImage {
/**
* Corresponds to the standard CodeBuild image `aws/codebuild/windows-base:1.0`.
*
* @deprecated `WindowsBuildImage.WINDOWS_BASE_2_0` should be used instead.
* @deprecated `WindowsBuildImage.WIN_SERVER_CORE_2019_BASE_2_0` should be used instead.
*/
public static readonly WIN_SERVER_CORE_2016_BASE: IBuildImage = new WindowsBuildImage({
imageId: 'aws/codebuild/windows-base:1.0',
Expand All @@ -1965,6 +1965,8 @@ export class WindowsBuildImage implements IBuildImage {
/**
* The standard CodeBuild image `aws/codebuild/windows-base:2.0`, which is
* based off Windows Server Core 2016.
*
* @deprecated `WindowsBuildImage.WIN_SERVER_CORE_2019_BASE_2_0` should be used instead.
*/
public static readonly WINDOWS_BASE_2_0: IBuildImage = new WindowsBuildImage({
imageId: 'aws/codebuild/windows-base:2.0',
Expand Down Expand Up @@ -2066,8 +2068,8 @@ export class WindowsBuildImage implements IBuildImage {

public validate(buildEnvironment: BuildEnvironment): string[] {
const ret: string[] = [];
if (buildEnvironment.computeType === ComputeType.SMALL) {
ret.push('Windows images do not support the Small ComputeType');
if (buildEnvironment.computeType === ComputeType.SMALL || buildEnvironment.computeType === ComputeType.X2_LARGE) {
ret.push(`Windows images do not support the '${buildEnvironment.computeType}' compute type`);
}
return ret;
}
Expand Down
20 changes: 19 additions & 1 deletion packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,25 @@ test('using ComputeType.Small with a Windows image fails validation', () => {
}),
environment: invalidEnvironment,
});
}).toThrow(/Windows images do not support the Small ComputeType/);
}).toThrow(/Windows images do not support the 'BUILD_GENERAL1_SMALL' compute type/);
});

test('using ComputeType.X2Large with a Windows image fails validation', () => {
const stack = new cdk.Stack();
const invalidEnvironment: codebuild.BuildEnvironment = {
buildImage: codebuild.WindowsBuildImage.WIN_SERVER_CORE_2019_BASE,
computeType: codebuild.ComputeType.X2_LARGE,
};

expect(() => {
new codebuild.Project(stack, 'MyProject', {
source: codebuild.Source.s3({
bucket: new s3.Bucket(stack, 'MyBucket'),
path: 'path',
}),
environment: invalidEnvironment,
});
}).toThrow(/Windows images do not support the 'BUILD_GENERAL1_2XLARGE' compute type/);
});

test('fromCodebuildImage', () => {
Expand Down

0 comments on commit 147420e

Please sign in to comment.