Skip to content

Commit f5b2b36

Browse files
Merge branch 'master' of github.com:aws/aws-cdk into v2/forward-merge-20220413
2 parents 2900675 + 47f6e50 commit f5b2b36

File tree

35 files changed

+1323
-311
lines changed

35 files changed

+1323
-311
lines changed

packages/@aws-cdk-containers/ecs-service-extensions/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
<!--END STABILITY BANNER-->
1111

12+
> ⚠️ v2 of this library is now available! It is compatible with AWS CDK v2 and available in
13+
> multiple languages.
14+
> The source code for v2 lives [here](https://github.com/cdklabs/cdk-ecs-service-extensions).
15+
> To migrate from this library to v2, see the [Migration Guide](https://github.com/cdklabs/cdk-ecs-service-extensions/blob/main/MIGRATING.md).
16+
1217
This library provides a high level, extensible pattern for constructing services
1318
deployed using Amazon ECS.
1419

packages/@aws-cdk/aws-apprunner/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ new apprunner.Service(this, 'Service', {
6565
source: apprunner.Source.fromEcr({
6666
imageConfiguration: { port: 80 },
6767
repository: ecr.Repository.fromRepositoryName(this, 'NginxRepository', 'nginx'),
68-
tag: 'latest',
68+
tagOrDigest: 'latest',
6969
}),
7070
});
7171
```

packages/@aws-cdk/aws-apprunner/lib/service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,14 @@ export interface EcrProps {
219219
/**
220220
* Image tag.
221221
* @default - 'latest'
222+
* @deprecated use `tagOrDigest`
222223
*/
223224
readonly tag?: string;
225+
/**
226+
* Image tag or digest (digests must start with `sha256:`).
227+
* @default - 'latest'
228+
*/
229+
readonly tagOrDigest?: string;
224230
}
225231

226232
/**
@@ -313,7 +319,9 @@ export class EcrSource extends Source {
313319
return {
314320
imageRepository: {
315321
imageConfiguration: this.props.imageConfiguration,
316-
imageIdentifier: this.props.repository.repositoryUriForTag(this.props.tag || 'latest'),
322+
imageIdentifier: this.props.repository.repositoryUriForTagOrDigest(
323+
this.props.tagOrDigest || this.props.tag || 'latest',
324+
),
317325
imageRepositoryType: ImageRepositoryType.ECR,
318326
},
319327
ecrRepository: this.props.repository,

packages/@aws-cdk/aws-codebuild/lib/linux-arm-build-image.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export class LinuxArmBuildImage implements IBuildImage {
4242
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-ecr.html
4343
*
4444
* @param repository The ECR repository
45-
* @param tag Image tag (default "latest")
45+
* @param tagOrDigest Image tag or digest (default "latest", digests must start with `sha256:`)
4646
* @returns An aarch64 Linux build image from an ECR repository.
4747
*/
48-
public static fromEcrRepository(repository: ecr.IRepository, tag: string = 'latest'): IBuildImage {
48+
public static fromEcrRepository(repository: ecr.IRepository, tagOrDigest: string = 'latest'): IBuildImage {
4949
return new LinuxArmBuildImage({
50-
imageId: repository.repositoryUriForTag(tag),
50+
imageId: repository.repositoryUriForTagOrDigest(tagOrDigest),
5151
imagePullPrincipalType: ImagePullPrincipalType.SERVICE_ROLE,
5252
repository,
5353
});

packages/@aws-cdk/aws-codebuild/lib/project.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,11 +1785,11 @@ export class LinuxBuildImage implements IBuildImage {
17851785
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-ecr.html
17861786
*
17871787
* @param repository The ECR repository
1788-
* @param tag Image tag (default "latest")
1788+
* @param tagOrDigest Image tag or digest (default "latest", digests must start with `sha256:`)
17891789
*/
1790-
public static fromEcrRepository(repository: ecr.IRepository, tag: string = 'latest'): IBuildImage {
1790+
public static fromEcrRepository(repository: ecr.IRepository, tagOrDigest: string = 'latest'): IBuildImage {
17911791
return new LinuxBuildImage({
1792-
imageId: repository.repositoryUriForTag(tag),
1792+
imageId: repository.repositoryUriForTagOrDigest(tagOrDigest),
17931793
imagePullPrincipalType: ImagePullPrincipalType.SERVICE_ROLE,
17941794
repository,
17951795
});
@@ -1946,15 +1946,15 @@ export class WindowsBuildImage implements IBuildImage {
19461946
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-ecr.html
19471947
*
19481948
* @param repository The ECR repository
1949-
* @param tag Image tag (default "latest")
1949+
* @param tagOrDigest Image tag or digest (default "latest", digests must start with `sha256:`)
19501950
*/
19511951
public static fromEcrRepository(
19521952
repository: ecr.IRepository,
1953-
tag: string = 'latest',
1953+
tagOrDigest: string = 'latest',
19541954
imageType: WindowsImageType = WindowsImageType.STANDARD): IBuildImage {
19551955

19561956
return new WindowsBuildImage({
1957-
imageId: repository.repositoryUriForTag(tag),
1957+
imageId: repository.repositoryUriForTagOrDigest(tagOrDigest),
19581958
imagePullPrincipalType: ImagePullPrincipalType.SERVICE_ROLE,
19591959
imageType,
19601960
repository,

packages/@aws-cdk/aws-codebuild/lib/source.ts

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,18 @@ interface ThirdPartyGitSourceProps extends GitSourceProps {
496496
* @default every push and every Pull Request (create or update) triggers a build
497497
*/
498498
readonly webhookFilters?: FilterGroup[];
499+
500+
/**
501+
* The URL that the build will report back to the source provider.
502+
* Can use built-in CodeBuild variables, like $AWS_REGION.
503+
*
504+
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html#cli.source.buildstatusconfig.targeturl
505+
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
506+
*
507+
* @example "$CODEBUILD_PUBLIC_BUILD_URL"
508+
* @default - link to the AWS Console for CodeBuild to a particular build execution
509+
*/
510+
readonly buildStatusUrl?: string;
499511
}
500512

501513
/**
@@ -507,6 +519,7 @@ abstract class ThirdPartyGitSource extends GitSource {
507519
private readonly reportBuildStatus: boolean;
508520
private readonly webhook?: boolean;
509521
private readonly webhookTriggersBatchBuild?: boolean;
522+
protected readonly buildStatusUrl?: string;
510523

511524
protected constructor(props: ThirdPartyGitSourceProps) {
512525
super(props);
@@ -515,6 +528,7 @@ abstract class ThirdPartyGitSource extends GitSource {
515528
this.reportBuildStatus = props.reportBuildStatus ?? true;
516529
this.webhookFilters = props.webhookFilters || [];
517530
this.webhookTriggersBatchBuild = props.webhookTriggersBatchBuild;
531+
this.buildStatusUrl = props.buildStatusUrl;
518532
}
519533

520534
public bind(_scope: Construct, project: IProject): SourceConfig {
@@ -633,10 +647,53 @@ class S3Source extends Source {
633647
}
634648
}
635649

650+
/**
651+
* Common properties between {@link GitHubSource} and {@link GitHubEnterpriseSource}.
652+
*/
653+
interface CommonGithubSourceProps extends ThirdPartyGitSourceProps {
654+
/**
655+
* This parameter is used for the `context` parameter in the GitHub commit status.
656+
* Can use built-in CodeBuild variables, like $AWS_REGION.
657+
*
658+
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html#cli.source.buildstatusconfig.context
659+
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
660+
*
661+
* @example "My build #$CODEBUILD_BUILD_NUMBER"
662+
* @default "AWS CodeBuild $AWS_REGION ($PROJECT_NAME)"
663+
*/
664+
readonly buildStatusContext?: string
665+
}
666+
667+
abstract class CommonGithubSource extends ThirdPartyGitSource {
668+
private readonly buildStatusContext?: string;
669+
670+
constructor(props: CommonGithubSourceProps) {
671+
super(props);
672+
this.buildStatusContext = props.buildStatusContext;
673+
}
674+
675+
public bind(scope: CoreConstruct, project: IProject): SourceConfig {
676+
const superConfig = super.bind(scope, project);
677+
return {
678+
sourceProperty: {
679+
...superConfig.sourceProperty,
680+
buildStatusConfig: this.buildStatusContext !== undefined || this.buildStatusUrl !== undefined
681+
? {
682+
context: this.buildStatusContext,
683+
targetUrl: this.buildStatusUrl,
684+
}
685+
: undefined,
686+
},
687+
sourceVersion: superConfig.sourceVersion,
688+
buildTriggers: superConfig.buildTriggers,
689+
};
690+
}
691+
}
692+
636693
/**
637694
* Construction properties for {@link GitHubSource} and {@link GitHubEnterpriseSource}.
638695
*/
639-
export interface GitHubSourceProps extends ThirdPartyGitSourceProps {
696+
export interface GitHubSourceProps extends CommonGithubSourceProps {
640697
/**
641698
* The GitHub account/user that owns the repo.
642699
*
@@ -655,7 +712,7 @@ export interface GitHubSourceProps extends ThirdPartyGitSourceProps {
655712
/**
656713
* GitHub Source definition for a CodeBuild project.
657714
*/
658-
class GitHubSource extends ThirdPartyGitSource {
715+
class GitHubSource extends CommonGithubSource {
659716
public readonly type = GITHUB_SOURCE_TYPE;
660717
private readonly httpsCloneUrl: string;
661718

@@ -680,7 +737,7 @@ class GitHubSource extends ThirdPartyGitSource {
680737
/**
681738
* Construction properties for {@link GitHubEnterpriseSource}.
682739
*/
683-
export interface GitHubEnterpriseSourceProps extends ThirdPartyGitSourceProps {
740+
export interface GitHubEnterpriseSourceProps extends CommonGithubSourceProps {
684741
/**
685742
* The HTTPS URL of the repository in your GitHub Enterprise installation.
686743
*/
@@ -697,7 +754,7 @@ export interface GitHubEnterpriseSourceProps extends ThirdPartyGitSourceProps {
697754
/**
698755
* GitHub Enterprise Source definition for a CodeBuild project.
699756
*/
700-
class GitHubEnterpriseSource extends ThirdPartyGitSource {
757+
class GitHubEnterpriseSource extends CommonGithubSource {
701758
public readonly type = GITHUB_ENTERPRISE_SOURCE_TYPE;
702759
private readonly httpsCloneUrl: string;
703760
private readonly ignoreSslErrors?: boolean;
@@ -765,6 +822,18 @@ export interface BitBucketSourceProps extends ThirdPartyGitSourceProps {
765822
* @example 'aws-cdk'
766823
*/
767824
readonly repo: string;
825+
826+
/**
827+
* This parameter is used for the `name` parameter in the Bitbucket commit status.
828+
* Can use built-in CodeBuild variables, like $AWS_REGION.
829+
*
830+
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html#cli.source.buildstatusconfig.context
831+
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
832+
*
833+
* @example "My build #$CODEBUILD_BUILD_NUMBER"
834+
* @default "AWS CodeBuild $AWS_REGION ($PROJECT_NAME)"
835+
*/
836+
readonly buildStatusName?: string;
768837
}
769838

770839
/**
@@ -773,10 +842,12 @@ export interface BitBucketSourceProps extends ThirdPartyGitSourceProps {
773842
class BitBucketSource extends ThirdPartyGitSource {
774843
public readonly type = BITBUCKET_SOURCE_TYPE;
775844
private readonly httpsCloneUrl: any;
845+
private readonly buildStatusName?: string;
776846

777847
constructor(props: BitBucketSourceProps) {
778848
super(props);
779849
this.httpsCloneUrl = `https://bitbucket.org/${props.owner}/${props.repo}.git`;
850+
this.buildStatusName = props.buildStatusName;
780851
}
781852

782853
public bind(_scope: Construct, _project: IProject): SourceConfig {
@@ -790,6 +861,12 @@ class BitBucketSource extends ThirdPartyGitSource {
790861
sourceProperty: {
791862
...superConfig.sourceProperty,
792863
location: this.httpsCloneUrl,
864+
buildStatusConfig: this.buildStatusName !== undefined || this.buildStatusUrl !== undefined
865+
? {
866+
context: this.buildStatusName,
867+
targetUrl: this.buildStatusUrl,
868+
}
869+
: undefined,
793870
},
794871
sourceVersion: superConfig.sourceVersion,
795872
buildTriggers: superConfig.buildTriggers,

packages/@aws-cdk/aws-codebuild/test/codebuild.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,78 @@ describe('secondary sources', () => {
10281028
});
10291029
});
10301030

1031+
describe('sources with customised build status configuration', () => {
1032+
test('GitHub', () => {
1033+
const context = 'My custom CodeBuild worker!';
1034+
const stack = new cdk.Stack();
1035+
const source = codebuild.Source.gitHub({
1036+
owner: 'awslabs',
1037+
repo: 'aws-cdk',
1038+
buildStatusContext: context,
1039+
});
1040+
1041+
new codebuild.Project(stack, 'MyProject', { source });
1042+
Template.fromStack(stack).findParameters('AWS::CodeBuild::Project', {
1043+
Source: {
1044+
buildStatusConfig: {
1045+
context: context,
1046+
},
1047+
},
1048+
});
1049+
});
1050+
1051+
test('GitHub Enterprise', () => {
1052+
const context = 'My custom CodeBuild worker!';
1053+
const stack = new cdk.Stack();
1054+
const source = codebuild.Source.gitHubEnterprise({
1055+
httpsCloneUrl: 'url',
1056+
buildStatusContext: context,
1057+
});
1058+
new codebuild.Project(stack, 'MyProject', { source });
1059+
Template.fromStack(stack).findParameters('AWS::CodeBuild::Project', {
1060+
Source: {
1061+
buildStatusConfig: {
1062+
context: context,
1063+
},
1064+
},
1065+
});
1066+
});
1067+
1068+
test('BitBucket', () => {
1069+
const context = 'My custom CodeBuild worker!';
1070+
const stack = new cdk.Stack();
1071+
const source = codebuild.Source.bitBucket({ owner: 'awslabs', repo: 'aws-cdk' });
1072+
new codebuild.Project(stack, 'MyProject', { source });
1073+
Template.fromStack(stack).findParameters('AWS::CodeBuild::Project', {
1074+
Source: {
1075+
buildStatusConfig: {
1076+
context: context,
1077+
},
1078+
},
1079+
});
1080+
});
1081+
});
1082+
1083+
describe('sources with customised build status configuration', () => {
1084+
test('GitHub with targetUrl', () => {
1085+
const targetUrl = 'https://example.com';
1086+
const stack = new cdk.Stack();
1087+
const source = codebuild.Source.gitHub({
1088+
owner: 'awslabs',
1089+
repo: 'aws-cdk',
1090+
buildStatusUrl: targetUrl,
1091+
});
1092+
new codebuild.Project(stack, 'MyProject', { source });
1093+
Template.fromStack(stack).findParameters('AWS::CodeBuild::Project', {
1094+
Source: {
1095+
buildStatusConfig: {
1096+
targetUrl: targetUrl,
1097+
},
1098+
},
1099+
});
1100+
});
1101+
});
1102+
10311103
describe('secondary source versions', () => {
10321104
test('allow secondary source versions', () => {
10331105
const stack = new cdk.Stack();

packages/@aws-cdk/aws-ecr/lib/repository.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,24 @@ export interface IRepository extends IResource {
4242
repositoryUriForTag(tag?: string): string;
4343

4444
/**
45-
* Returns the URI of the repository for a certain tag. Can be used in `docker push/pull`.
45+
* Returns the URI of the repository for a certain digest. Can be used in `docker push/pull`.
4646
*
4747
* ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[@DIGEST]
4848
*
4949
* @param digest Image digest to use (tools usually default to the image with the "latest" tag if omitted)
5050
*/
5151
repositoryUriForDigest(digest?: string): string;
5252

53+
/**
54+
* Returns the URI of the repository for a certain tag or digest, inferring based on the syntax of the tag. Can be used in `docker push/pull`.
55+
*
56+
* ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[:TAG]
57+
* ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[@DIGEST]
58+
*
59+
* @param tagOrDigest Image tag or digest to use (tools usually default to the image with the "latest" tag if omitted)
60+
*/
61+
repositoryUriForTagOrDigest(tagOrDigest?: string): string;
62+
5363
/**
5464
* Add a policy statement to the repository's resource policy
5565
*/
@@ -162,6 +172,22 @@ export abstract class RepositoryBase extends Resource implements IRepository {
162172
return this.repositoryUriWithSuffix(digestSuffix);
163173
}
164174

175+
/**
176+
* Returns the URL of the repository. Can be used in `docker push/pull`.
177+
*
178+
* ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[:TAG]
179+
* ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPOSITORY[@DIGEST]
180+
*
181+
* @param tagOrDigest Optional image tag or digest (digests must start with `sha256:`)
182+
*/
183+
public repositoryUriForTagOrDigest(tagOrDigest?: string): string {
184+
if (tagOrDigest?.startsWith('sha256:')) {
185+
return this.repositoryUriForDigest(tagOrDigest);
186+
} else {
187+
return this.repositoryUriForTag(tagOrDigest);
188+
}
189+
}
190+
165191
/**
166192
* Returns the repository URI, with an appended suffix, if provided.
167193
* @param suffix An image tag or an image digest.

packages/@aws-cdk/aws-ecs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ obtained from either DockerHub or from ECR repositories, built directly from a l
393393

394394
- `ecs.ContainerImage.fromRegistry(imageName)`: use a public image.
395395
- `ecs.ContainerImage.fromRegistry(imageName, { credentials: mySecret })`: use a private image that requires credentials.
396-
- `ecs.ContainerImage.fromEcrRepository(repo, tag)`: use the given ECR repository as the image
397-
to start. If no tag is provided, "latest" is assumed.
396+
- `ecs.ContainerImage.fromEcrRepository(repo, tagOrDigest)`: use the given ECR repository as the image
397+
to start. If no tag or digest is provided, "latest" is assumed.
398398
- `ecs.ContainerImage.fromAsset('./image')`: build and upload an
399399
image directly from a `Dockerfile` in your source directory.
400400
- `ecs.ContainerImage.fromDockerImageAsset(asset)`: uses an existing

0 commit comments

Comments
 (0)