@@ -3,9 +3,10 @@ import * as cp from '@aws-cdk/aws-codepipeline';
3
3
import { Artifact } from '@aws-cdk/aws-codepipeline' ;
4
4
import * as cp_actions from '@aws-cdk/aws-codepipeline-actions' ;
5
5
import { Action , CodeCommitTrigger , GitHubTrigger , S3Trigger } from '@aws-cdk/aws-codepipeline-actions' ;
6
+ import { IRepository } from '@aws-cdk/aws-ecr' ;
6
7
import * as iam from '@aws-cdk/aws-iam' ;
7
8
import { IBucket } from '@aws-cdk/aws-s3' ;
8
- import { SecretValue , Token } from '@aws-cdk/core' ;
9
+ import { Fn , SecretValue , Token } from '@aws-cdk/core' ;
9
10
import { Node } from 'constructs' ;
10
11
import { FileSet , Step } from '../blueprint' ;
11
12
import { CodePipelineActionFactoryResult , ProduceActionOptions , ICodePipelineActionFactory } from './codepipeline-action-factory' ;
@@ -57,6 +58,22 @@ export abstract class CodePipelineSource extends Step implements ICodePipelineAc
57
58
return new S3Source ( bucket , objectKey , props ) ;
58
59
}
59
60
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
+
60
77
/**
61
78
* Returns a CodeStar connection source. A CodeStar connection allows AWS CodePipeline to
62
79
* access external resources, such as repositories in GitHub, GitHub Enterprise or
@@ -264,6 +281,46 @@ class S3Source extends CodePipelineSource {
264
281
}
265
282
}
266
283
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
+
267
324
/**
268
325
* Configuration options for CodeStar source
269
326
*/
0 commit comments