-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
Added a default image |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
.
- Let's remove
Windows2019BuildImage
completely for now. Everything will be part ofWindowsBuildImage
. - Let's create a public, exported enum,
WindowsImageType
. It will have 2 members:STANDARD
, with value'WINDOWS_CONTAINER'
, andSERVER_2019
, with value'WINDOWS_SERVER_2019_CONTAINER'
. - Add an optional property
imageType?: WindowsImageType
toWindowsBuildImageProps
. - In
WindowsBuildImage
, changetype
from being hard-coded in the property declaration, to being assigned in the constructor:this.type = props.imageType?.toString() ?? WindowsImageType.STANDARD.toString();
. - Have
WIN_SERVER_CORE_2019_BASE
be a constant inWindowsBuildImage
:
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,
});
- Change
WindowsBuildImage.fromDockerRegistry()
to take a new interface,WindowsDockerImageOptions
, instead ofDockerImageOptions
:
export interface WindowsDockerImageOptions extends DockerImageOptions {
/** @default WindowsImageType.STANDARD */
readonly imageType?: WindowsImageType;
}
- In the implementation of
WindowsBuildImage.fromDockerRegistry()
, passoptions.imageType
when creating a newWindowsBuildImage
.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@@ -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 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks @ermanno !
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
…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*
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