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

feat(codebuild): support images with WINDOWS_SERVER_2019_CONTAINER environment type #9526

Merged
merged 2 commits into from Aug 18, 2020
Merged

feat(codebuild): support images with WINDOWS_SERVER_2019_CONTAINER environment type #9526

merged 2 commits into from Aug 18, 2020

Conversation

ermanno
Copy link
Member

@ermanno ermanno commented Aug 7, 2020

Windows Server 2019 based images should have environment type
WINDOWS_SERVER_2019_CONTAINER. WindowsBuildImage uses the
WINDOWS_CONTAINER environment type. This patch solves this by adding a
WindowsImageType enum to the options passed the WindowsBuildImage
constructor that is used to correctly populate the type field.

fixes #9484


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@skinny85 skinny85 self-assigned this Aug 7, 2020
@ermanno
Copy link
Member Author

ermanno commented Aug 8, 2020

Added a default image Windows2019BuildImage.WIN_SERVER_CORE_2019_BASE. According to this documentation and this example there is a built-in (CodeBuild-managed) image aws/codebuild/windows-base:2019-1.0 that uses WINDOWS_SERVER_2019_CONTAINER.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @ermanno ! I have an idea on how to modify the solution slightly, which (I hope!) addresses your concerns around duplication.

Let me know how you like my proposal!

Thanks,
Adam

*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
*/
export class Windows2019BuildImage implements IBuildImage {
Copy link
Contributor

Choose a reason for hiding this comment

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

While there's nothing wrong with this solution, I have a different idea that will reduce the duplication between WindowsBuildImage and Windows2019BuildImage.

  1. Let's remove Windows2019BuildImage completely for now. Everything will be part of WindowsBuildImage.
  2. Let's create a public, exported enum, WindowsImageType. It will have 2 members: STANDARD, with value 'WINDOWS_CONTAINER', and SERVER_2019, with value 'WINDOWS_SERVER_2019_CONTAINER'.
  3. Add an optional property imageType?: WindowsImageType to WindowsBuildImageProps.
  4. In WindowsBuildImage, change type from being hard-coded in the property declaration, to being assigned in the constructor: this.type = props.imageType?.toString() ?? WindowsImageType.STANDARD.toString();.
  5. Have WIN_SERVER_CORE_2019_BASE be a constant in WindowsBuildImage:
  public static readonly WIN_SERVER_CORE_2019_BASE: IBuildImage = new WindowsBuildImage({
    imageId: 'aws/codebuild/windows-base:2019-1.0',
    imagePullPrincipalType: ImagePullPrincipalType.CODEBUILD,
    imageType: WindowsImageType.SERVER_2019,
  });
  1. Change WindowsBuildImage.fromDockerRegistry() to take a new interface, WindowsDockerImageOptions, instead of DockerImageOptions:
export interface WindowsDockerImageOptions extends DockerImageOptions {
  /** @default WindowsImageType.STANDARD */
  readonly imageType?: WindowsImageType;
}
  1. In the implementation of WindowsBuildImage.fromDockerRegistry(), pass options.imageType when creating a new WindowsBuildImage.

Copy link
Member Author

@ermanno ermanno Aug 13, 2020

Choose a reason for hiding this comment

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

I will proceed to implement this change. Regarding the way we fix fromDockerRegistry with the WindowsDockerImageOptions, we also have fromEcrRepository and fromAsset... should I also add an imageType? property to a subclass of DockerImageAssetProps for the latter? For the ECR case, I don't see a way to get this information from the ecr.IRepository, so the only thing that comes to mind would be to add it to the function as an additional optional or default parameter, in which case maybe instead we should do the same thing for all three methods for consistency:

fromDockerRegistry(name: string, options: DockerImageOptions, imageType?: WindowsImageType)
fromAsset(scope: Construct, id: string, props: DockerImageAssetProps,  imageType?: WindowsImageType)
fromEcrRepository(repository: ecr.IRepository, tag: string = 'latest',  imageType?: WindowsImageType)

or

fromDockerRegistry(name: string, options: DockerImageOptions, imageType = WindowsImageType.STANDARD)
fromAsset(scope: Construct, id: string, props: DockerImageAssetProps,  imageType = WindowsImageType.STANDARD)
fromEcrRepository(repository: ecr.IRepository, tag: string = 'latest',  imageType = WindowsImageType.STANDARD)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, all 3 should be changed in a similar fashion, but I wouldn't do it by adding a new optional argument everywhere 🙂.

Same like I suggested creating interface WindowsDockerImageOptions extends DockerImageOptions for fromDockerRegistry(), I suggest creating interface WindowsDockerImageAssetProps extends DockerImageAssetProps for fromAsset().

The fromEcrRepository() is a harder one to crack, because of the default parameter already there... I think for that one, I'm fine with adding a third parameter with a default value, like you suggested.

Copy link
Member Author

@ermanno ermanno Aug 14, 2020

Choose a reason for hiding this comment

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

One difference here is that by using the Windows* classes we would change the signature of the method, and this would be a breaking/non backwards compatible change (for example, after updating CDK, old code calling WindowsBuildImage.fromDockerRegistry() with DockerImageOptions would fail to build).

By contrast, looking at the Java version of the WindowsBuildImage.fromEcrRepository() function, which has a default parameter tag, I see that if we introduce a default parameter the method is overloaded, so there are two versions of the function, one with and one without the default parameter.

@mergify mergify bot dismissed skinny85’s stale review August 13, 2020 23:18

Pull request has been modified.

@ermanno ermanno requested a review from skinny85 August 14, 2020 19:00
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks great @ermanno !

Some cosmetic comments.

packages/@aws-cdk/aws-codebuild/lib/project.ts Outdated Show resolved Hide resolved
@@ -213,7 +213,7 @@ The CodeBuild library supports both Linux and Windows images via the
`LinuxBuildImage` and `WindowsBuildImage` classes, respectively.

You can specify one of the predefined Windows/Linux images by using one
of the constants such as `WindowsBuildImage.WINDOWS_BASE_2_0` or
of the constants such as `WindowsBuildImage.WINDOWS_BASE_2_0`, or `WindowsBuildImage.WIN_SERVER_CORE_2019_BASE` or
Copy link
Contributor

Choose a reason for hiding this comment

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

This documentation is now out of date.

Please mention how to use the new Windows type somewhere in the ReadMe, preferably with code example(s).

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added details on how to pass the WindowsImageType optional parameter. I have also fixed a mistaken in the previous documentation: specifically, from the LinuxBuildImage and WindowsBuildImage documentation pages I see that fromCodeBuildImageId is present only in LinuxBuildImage.

@mergify mergify bot dismissed skinny85’s stale review August 16, 2020 10:56

Pull request has been modified.

Windows Server 2019 based images should have environment type
WINDOWS_SERVER_2019_CONTAINER. WindowsBuildImage uses the
WINDOWS_CONTAINER environment type. This patch solves this by adding a
WindowsImageType enum to the options passed the WindowsBuildImage
constructor that is used to correctly populate the type field.

fixes #9484
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @ermanno !

@mergify
Copy link
Contributor

mergify bot commented Aug 18, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: ecafcc1
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Aug 18, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit d3813e7 into aws:master Aug 18, 2020
misterjoshua pushed a commit to misterjoshua/aws-cdk that referenced this pull request Aug 19, 2020
…vironment type (aws#9526)

Windows Server 2019 based images should have environment type
WINDOWS_SERVER_2019_CONTAINER. WindowsBuildImage uses the
WINDOWS_CONTAINER environment type. This patch solves this by adding a
WindowsImageType enum to the options passed the WindowsBuildImage
constructor that is used to correctly populate the type field.

fixes aws#9484

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants