From 4f446fdc5f69b8b9f029fc810aee67d7cc159743 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Mon, 13 Aug 2018 16:25:56 -0700 Subject: [PATCH] refactor(aws-s3, aws-codepipeline): Align the S3 CodePipeline Action with other Actions. BREAKING CHANGE: move the S3 CodePipeline Action out of the aws-codepipeline package and into the aws-s3 package, and rename it from AmazonS3Source to PipelineSource. --- .../aws-codepipeline-api/lib/source-action.ts | 2 +- .../@aws-cdk/aws-codepipeline/lib/index.ts | 1 - .../test/integ.lambda-pipeline.ts | 2 +- .../test/integ.pipeline-cfn.ts | 2 +- .../test/test.general-validation.ts | 5 ++-- .../aws-codepipeline/test/test.pipeline.ts | 2 +- packages/@aws-cdk/aws-s3/README.md | 24 +++++++++++++++++++ packages/@aws-cdk/aws-s3/lib/index.ts | 1 + .../lib/pipeline-action.ts} | 12 +++++----- packages/@aws-cdk/aws-s3/package.json | 1 + 10 files changed, 38 insertions(+), 14 deletions(-) rename packages/@aws-cdk/{aws-codepipeline/lib/s3-source-action.ts => aws-s3/lib/pipeline-action.ts} (77%) diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/source-action.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/source-action.ts index 3ccea318f59ec..beb3d193fb2c4 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/source-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/source-action.ts @@ -44,7 +44,7 @@ export interface SourceActionProps extends CommonActionProps { /** * Low-level class for source actions. * It is recommended that concrete types are used instead, - * such as {@link codepipeline.AmazonS3Source} or + * such as {@link s3.PipelineSource} or * {@link codecommit.PipelineSource}. */ export abstract class SourceAction extends Action { diff --git a/packages/@aws-cdk/aws-codepipeline/lib/index.ts b/packages/@aws-cdk/aws-codepipeline/lib/index.ts index 98b314f4f59aa..4875bcc768b76 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/index.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/index.ts @@ -1,7 +1,6 @@ export * from './github-source-action'; export * from './manual-approval-action'; export * from './pipeline'; -export * from './s3-source-action'; export * from './stage'; // AWS::CodePipeline CloudFormation Resources: diff --git a/packages/@aws-cdk/aws-codepipeline/test/integ.lambda-pipeline.ts b/packages/@aws-cdk/aws-codepipeline/test/integ.lambda-pipeline.ts index 2ec41e9e8a5a9..c526fde753311 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/integ.lambda-pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/integ.lambda-pipeline.ts @@ -13,7 +13,7 @@ const sourceStage = new codepipeline.Stage(pipeline, 'Source'); const bucket = new s3.Bucket(stack, 'PipelineBucket', { versioned: true, }); -new codepipeline.AmazonS3Source(stack, 'Source', { +new s3.PipelineSource(stack, 'Source', { stage: sourceStage, artifactName: 'SourceArtifact', bucket, diff --git a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-cfn.ts b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-cfn.ts index 6ff220dfc3fe5..68d7061d4fa80 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-cfn.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-cfn.ts @@ -16,7 +16,7 @@ const sourceStage = new codepipeline.Stage(pipeline, 'Source'); const bucket = new s3.Bucket(stack, 'PipelineBucket', { versioned: true, }); -const source = new codepipeline.AmazonS3Source(stack, 'Source', { +const source = new s3.PipelineSource(stack, 'Source', { stage: sourceStage, artifactName: 'SourceArtifact', bucket, diff --git a/packages/@aws-cdk/aws-codepipeline/test/test.general-validation.ts b/packages/@aws-cdk/aws-codepipeline/test/test.general-validation.ts index 655cc7d555792..bd924908ff957 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/test.general-validation.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/test.general-validation.ts @@ -3,7 +3,6 @@ import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; import { Pipeline } from '../lib/pipeline'; -import { AmazonS3Source } from '../lib/s3-source-action'; import { Stage } from '../lib/stage'; interface NameValidationTestCase { @@ -61,13 +60,13 @@ export = { const secondStage = new Stage(pipeline, 'SecondStage'); const bucket = new s3.Bucket(stack, 'PipelineBucket'); - new AmazonS3Source(stack, 'FirstAction', { + new s3.PipelineSource(stack, 'FirstAction', { stage: firstStage, artifactName: 'FirstArtifact', bucket, bucketKey: 'key', }); - new AmazonS3Source(stack, 'SecondAction', { + new s3.PipelineSource(stack, 'SecondAction', { stage: secondStage, artifactName: 'SecondAction', bucket, diff --git a/packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts b/packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts index 71606d3ca6df1..48de451528ec1 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts @@ -137,7 +137,7 @@ export = { const pipeline = new codepipeline.Pipeline(stack, 'PL'); const stage1 = new codepipeline.Stage(pipeline, 'S1'); - new codepipeline.AmazonS3Source(stack, 'A1', { + new s3.PipelineSource(stack, 'A1', { stage: stage1, artifactName: 'Artifact', bucket: new s3.Bucket(stack, 'Bucket'), diff --git a/packages/@aws-cdk/aws-s3/README.md b/packages/@aws-cdk/aws-s3/README.md index 4b51848ed16e8..eaf25155b5b56 100644 --- a/packages/@aws-cdk/aws-s3/README.md +++ b/packages/@aws-cdk/aws-s3/README.md @@ -73,6 +73,30 @@ const policy = new BucketPolicy(this, 'MyBucketPolicy'); const bucket = new Bucket(this, 'MyBucket', { policy }); ``` +### Buckets as sources in CodePipeline + +This package also defines an Action that allows you to use a +Bucket as a source in CodePipeline: + +```ts +import codepipeline = require('@aws-cdk/aws-codepipeline'); +import s3 = require('@aws-cdk/aws-s3'); + +const sourceBucket = new s3.Bucket(this, 'MyBucket', { + versioned: true, // a Bucket used as a source in CodePipeline must be versioned +}); + +const pipeline = new codepipeline.Pipeline(this, 'MyPipeline'); +const sourceStage = new codepipeline.Stage(pipeline, 'Source'); +const sourceAction = new s3.PipelineSource(this, 'S3Source', { + stage: sourceStage, + bucket: sourceBucket, + bucketKey: 'path/to/file.zip', + artifactName: 'SourceOuptut', //name can be arbitrary +}); +// use sourceAction.artifact as the inputArtifact to later Actions... +``` + ### Importing and Exporting Buckets You can create a `Bucket` construct that represents an external/existing/unowned bucket by using the `Bucket.import` factory method. diff --git a/packages/@aws-cdk/aws-s3/lib/index.ts b/packages/@aws-cdk/aws-s3/lib/index.ts index e0d99e5e7ebe1..7ec115ab75fce 100644 --- a/packages/@aws-cdk/aws-s3/lib/index.ts +++ b/packages/@aws-cdk/aws-s3/lib/index.ts @@ -1,5 +1,6 @@ export * from './bucket'; export * from './bucket-policy'; +export * from './pipeline-action'; export * from './rule'; export * from './notification-dest'; diff --git a/packages/@aws-cdk/aws-codepipeline/lib/s3-source-action.ts b/packages/@aws-cdk/aws-s3/lib/pipeline-action.ts similarity index 77% rename from packages/@aws-cdk/aws-codepipeline/lib/s3-source-action.ts rename to packages/@aws-cdk/aws-s3/lib/pipeline-action.ts index d134810d76794..384b33fc012fd 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/s3-source-action.ts +++ b/packages/@aws-cdk/aws-s3/lib/pipeline-action.ts @@ -1,11 +1,11 @@ import actions = require('@aws-cdk/aws-codepipeline-api'); -import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); +import { BucketRef } from './bucket'; /** - * Construction properties of the {@link AmazonS3Source S3 source action}. + * Construction properties of the {@link PipelineSource S3 source Action}. */ -export interface AmazonS3SourceProps extends actions.CommonActionProps { +export interface PipelineSourceProps extends actions.CommonActionProps { /** * The name of the source's output artifact. Output artifacts are used by CodePipeline as * inputs into other actions. @@ -15,7 +15,7 @@ export interface AmazonS3SourceProps extends actions.CommonActionProps { /** * The Amazon S3 bucket that stores the source code */ - bucket: s3.BucketRef; + bucket: BucketRef; /** * The key within the S3 bucket that stores the source code @@ -34,8 +34,8 @@ export interface AmazonS3SourceProps extends actions.CommonActionProps { /** * Source that is provided by a specific Amazon S3 object. */ -export class AmazonS3Source extends actions.SourceAction { - constructor(parent: cdk.Construct, name: string, props: AmazonS3SourceProps) { +export class PipelineSource extends actions.SourceAction { + constructor(parent: cdk.Construct, name: string, props: PipelineSourceProps) { super(parent, name, { stage: props.stage, provider: 'S3', diff --git a/packages/@aws-cdk/aws-s3/package.json b/packages/@aws-cdk/aws-s3/package.json index f5639f2bac27e..08d7cc63ce781 100644 --- a/packages/@aws-cdk/aws-s3/package.json +++ b/packages/@aws-cdk/aws-s3/package.json @@ -53,6 +53,7 @@ "pkglint": "^0.8.1" }, "dependencies": { + "@aws-cdk/aws-codepipeline-api": "^0.8.1", "@aws-cdk/aws-iam": "^0.8.1", "@aws-cdk/aws-kms": "^0.8.1", "@aws-cdk/cdk": "^0.8.1"