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

chore(codebuild): added validation when using Windows Image #27946

Merged
Merged
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
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.
Copy link
Contributor Author

@sakurai-ryo sakurai-ryo Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @deprecated to WINDOWS_BASE_2_0.
Since WINDOWS_CONTAINER type is already deprecated, a new deployment of WINDOWS_BASE_2_0 will result in the following error.
The environment type WINDOWS_CONTAINER is deprecated for new projects or existing project environment updates. Please consider using Windows Server 2019 instead.

I could not find any mention of deprecation in the documentation, but Terraform has already deprecated it.
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codebuild_project#environment

This is not the main topic of this PR, so if it should be a separate PR, I will do so.

*/
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