@@ -3,9 +3,10 @@ import * as cp from '@aws-cdk/aws-codepipeline';
33import { Artifact } from '@aws-cdk/aws-codepipeline' ;
44import * as cp_actions from '@aws-cdk/aws-codepipeline-actions' ;
55import { Action , CodeCommitTrigger , GitHubTrigger , S3Trigger } from '@aws-cdk/aws-codepipeline-actions' ;
6+ import { IRepository } from '@aws-cdk/aws-ecr' ;
67import * as iam from '@aws-cdk/aws-iam' ;
78import { IBucket } from '@aws-cdk/aws-s3' ;
8- import { SecretValue , Token } from '@aws-cdk/core' ;
9+ import { Fn , SecretValue , Token } from '@aws-cdk/core' ;
910import { Node } from 'constructs' ;
1011import { FileSet , Step } from '../blueprint' ;
1112import { CodePipelineActionFactoryResult , ProduceActionOptions , ICodePipelineActionFactory } from './codepipeline-action-factory' ;
@@ -57,6 +58,22 @@ export abstract class CodePipelineSource extends Step implements ICodePipelineAc
5758 return new S3Source ( bucket , objectKey , props ) ;
5859 }
5960
61+ /**
62+ * Returns an ECR source.
63+ *
64+ * @param repository The repository that will be watched for changes.
65+ * @param props The options, which include the image tag to be checked for changes.
66+ *
67+ * @example
68+ * declare const repository: ecr.IRepository;
69+ * pipelines.CodePipelineSource.ecr(repository, {
70+ * imageTag: 'latest',
71+ * });
72+ */
73+ public static ecr ( repository : IRepository , props : ECRSourceOptions = { } ) : CodePipelineSource {
74+ return new ECRSource ( repository , props ) ;
75+ }
76+
6077 /**
6178 * Returns a CodeStar connection source. A CodeStar connection allows AWS CodePipeline to
6279 * access external resources, such as repositories in GitHub, GitHub Enterprise or
@@ -264,6 +281,46 @@ class S3Source extends CodePipelineSource {
264281 }
265282}
266283
284+ /**
285+ * Options for ECR sources
286+ */
287+ export interface ECRSourceOptions {
288+ /**
289+ * The image tag that will be checked for changes.
290+ *
291+ * @default latest
292+ */
293+ readonly imageTag ?: string ;
294+
295+ /**
296+ * The action name used for this source in the CodePipeline
297+ *
298+ * @default - The repository name
299+ */
300+ readonly actionName ?: string ;
301+ }
302+
303+ class ECRSource extends CodePipelineSource {
304+ constructor ( readonly repository : IRepository , readonly props : ECRSourceOptions ) {
305+ super ( Node . of ( repository ) . addr ) ;
306+
307+ this . configurePrimaryOutput ( new FileSet ( 'Source' , this ) ) ;
308+ }
309+
310+ protected getAction ( output : Artifact , _actionName : string , runOrder : number , variablesNamespace : string ) {
311+ // RepositoryName can contain '/' that is not a valid ActionName character, use '_' instead
312+ const formattedRepositoryName = Fn . join ( '_' , Fn . split ( '/' , this . repository . repositoryName ) ) ;
313+ return new cp_actions . EcrSourceAction ( {
314+ output,
315+ actionName : this . props . actionName ?? formattedRepositoryName ,
316+ runOrder,
317+ repository : this . repository ,
318+ imageTag : this . props . imageTag ,
319+ variablesNamespace,
320+ } ) ;
321+ }
322+ }
323+
267324/**
268325 * Configuration options for CodeStar source
269326 */
0 commit comments