Skip to content

Commit

Permalink
feat(aws-codebuild): add from codebuild image option (#7117)
Browse files Browse the repository at this point in the history
feat: add from codebuild image option

Addresses comment [here](#2606 (comment)).
  • Loading branch information
knorms101 authored Apr 2, 2020
1 parent b0a9024 commit de8e670
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ can use the `environment` property to customize the build environment:
The CodeBuild library supports both Linux and Windows images via the
`LinuxBuildImage` and `WindowsBuildImage` classes, respectively.

You can either specify one of the predefined Windows/Linux images by using one
You can specify one of the predefined Windows/Linux images by using one
of the constants such as `WindowsBuildImage.WINDOWS_BASE_2_0` or
`LinuxBuildImage.STANDARD_2_0`.

Expand All @@ -200,6 +200,7 @@ Alternatively, you can specify a custom image using one of the static methods on
ECR repository.
* Use `.fromAsset(directory)` to use an image created from a
local asset.
* Use `.fromCodeBuildImageId(id)` to reference a pre-defined, CodeBuild-provided Docker image.

The following example shows how to define an image from a Docker asset:

Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,20 @@ export class LinuxBuildImage implements IBuildImage {
});
}

/**
* Uses a Docker image provided by CodeBuild.
*
* @returns A Docker image provided by CodeBuild.
*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
*
* @param id The image identifier
* @example 'aws/codebuild/standard:4.0'
*/
public static fromCodeBuildImageId(id: string): IBuildImage {
return LinuxBuildImage.codeBuildImage(id);
}

private static codeBuildImage(name: string): IBuildImage {
return new LinuxBuildImage({
imageId: name,
Expand Down
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,23 @@ export = {
test.done();
},

'fromCodebuildImage'(test: Test) {
const stack = new cdk.Stack();
new codebuild.PipelineProject(stack, 'Project', {
environment: {
buildImage: codebuild.LinuxBuildImage.fromCodeBuildImageId('aws/codebuild/standard:4.0')
},
});

expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', {
"Environment": {
"Image": "aws/codebuild/standard:4.0",
},
}));

test.done();
},

'ARM image': {
'AMAZON_LINUX_2_ARM': {
'has type ARM_CONTAINER and default ComputeType LARGE'(test: Test) {
Expand Down

0 comments on commit de8e670

Please sign in to comment.