Skip to content

Commit

Permalink
feat(codepipeline): move all of the Pipeline Actions to their dedicat…
Browse files Browse the repository at this point in the history
…ed package.
  • Loading branch information
skinny85 committed Mar 26, 2019
1 parent 7416e9f commit f6d0b39
Show file tree
Hide file tree
Showing 100 changed files with 1,392 additions and 1,331 deletions.
50 changes: 0 additions & 50 deletions packages/@aws-cdk/alexa-ask/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,3 @@
```ts
const alexaAsk = require('@aws-cdk/alexa-ask');
```

### Alexa as deploy target for CodePipeline

You can deploy to Alexa using CodePipeline with the following DeployAction.

```ts
// Read the secrets from ParameterStore
const clientId = new cdk.SecretParameter(this, 'AlexaClientId', { ssmParameter: '/Alexa/ClientId' });
const clientSecret = new cdk.SecretParameter(this, 'AlexaClientSecret', { ssmParameter: '/Alexa/ClientSecret' });
const refreshToken = new cdk.SecretParameter(this, 'AlexaRefreshToken', { ssmParameter: '/Alexa/RefreshToken' });

// Add deploy action
new alexaAsk.AlexaSkillDeployAction({
actionName: 'DeploySkill',
runOrder: 1,
inputArtifact: sourceAction.outputArtifact,
clientId: clientId.value,
clientSecret: clientSecret.value,
refreshToken: refreshToken.value,
skillId: 'amzn1.ask.skill.12345678-1234-1234-1234-123456789012',
});
```

If you need manifest overrides you can specify them as `parameterOverridesArtifact` in the action:

```ts
const cloudformation = require('@aws-cdk/aws-cloudformation');

// Deploy some CFN change set and store output
const executeChangeSetAction = new cloudformation.PipelineExecuteChangeSetAction({
actionName: 'ExecuteChangesTest',
runOrder: 2,
stackName,
changeSetName,
outputFileName: 'overrides.json',
outputArtifactName: 'CloudFormation',
});

// Provide CFN output as manifest overrides
new alexaAsk.AlexaSkillDeployAction({
actionName: 'DeploySkill',
runOrder: 1,
inputArtifact: sourceAction.outputArtifact,
parameterOverridesArtifact: executeChangeSetAction.outputArtifact,
clientId: clientId.value,
clientSecret: clientSecret.value,
refreshToken: refreshToken.value,
skillId: 'amzn1.ask.skill.12345678-1234-1234-1234-123456789012',
});
```
1 change: 0 additions & 1 deletion packages/@aws-cdk/alexa-ask/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// Alexa::ASK CloudFormation Resources:
export * from './ask.generated';
export * from './pipeline-actions';
4 changes: 1 addition & 3 deletions packages/@aws-cdk/alexa-ask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@
"pkglint": "^0.26.0"
},
"dependencies": {
"@aws-cdk/aws-codepipeline-api": "^0.26.0",
"@aws-cdk/cdk": "^0.26.0"
},
"peerDependencies": {
"@aws-cdk/aws-codepipeline-api": "^0.26.0",
"@aws-cdk/cdk": "^0.26.0"
},
"engines": {
"node": ">= 8.10.0"
}
}
}
9 changes: 6 additions & 3 deletions packages/@aws-cdk/app-delivery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ The example below defines a *CDK App* that contains 3 stacks:
```

#### `index.ts`

```typescript
import codebuild = require('@aws-cdk/aws-codebuild');
import codepipeline = require('@aws-cdk/aws-codepipeline');
import codepipeline = require('@aws-cdk/aws-codepipeline-actions');
import codepipeline_actions = require('@aws-cdk/aws-codepipeline');
import cdk = require('@aws-cdk/cdk');
import cicd = require('@aws-cdk/cicd');

Expand All @@ -48,7 +50,7 @@ const pipeline = new codepipeline.Pipeline(pipelineStack, 'CodePipeline', {
});

// Configure the CodePipeline source - where your CDK App's source code is hosted
const source = new codepipeline.GitHubSourceAction({
const source = new codepipeline_actions.GitHubSourceAction({
actionName: 'GitHub',
/* ... */
});
Expand All @@ -67,8 +69,9 @@ const project = new codebuild.PipelineProject(pipelineStack, 'CodeBuild', {
* },
*/
});
const buildAction = project.toCodePipelineBuildAction({
const buildAction = new codepipeline_actions.CodeBuildBuildAction({
actionName: 'CodeBuild',
project,
inputArtifact: source.outputArtifact,
});
pipeline.addStage({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cfn = require('@aws-cdk/aws-cloudformation');
import codepipeline = require('@aws-cdk/aws-codepipeline-api');
import cpactions = require('@aws-cdk/aws-codepipeline-actions');
import cpapi = require('@aws-cdk/aws-codepipeline-api');
import iam = require('@aws-cdk/aws-iam');
import cdk = require('@aws-cdk/cdk');
import cxapi = require('@aws-cdk/cx-api');
Expand All @@ -13,13 +14,13 @@ export interface PipelineDeployStackActionProps {
/**
* The CodePipeline stage in which to perform the deployment.
*/
stage: codepipeline.IStage;
stage: cpapi.IStage;

/**
* The CodePipeline artifact that holds the synthesized app, which is the
* contents of the ``<directory>`` when running ``cdk synth -o <directory>``.
*/
inputArtifact: codepipeline.Artifact;
inputArtifact: cpapi.Artifact;

/**
* The name to use when creating a ChangeSet for the stack.
Expand Down Expand Up @@ -120,7 +121,7 @@ export class PipelineDeployStackAction extends cdk.Construct {
const changeSetName = props.changeSetName || 'CDK-CodePipeline-ChangeSet';

const capabilities = cfnCapabilities(props.adminPermissions, props.capabilities);
const changeSetAction = new cfn.PipelineCreateReplaceChangeSetAction({
const changeSetAction = new cpactions.CloudFormationCreateReplaceChangeSetAction({
actionName: 'ChangeSet',
changeSetName,
runOrder: createChangeSetRunOrder,
Expand All @@ -131,7 +132,7 @@ export class PipelineDeployStackAction extends cdk.Construct {
capabilities,
});
props.stage.addAction(changeSetAction);
props.stage.addAction(new cfn.PipelineExecuteChangeSetAction({
props.stage.addAction(new cpactions.CloudFormationExecuteChangeSetAction({
actionName: 'Execute',
changeSetName,
runOrder: executeChangeSetRunOrder,
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/app-delivery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"@aws-cdk/aws-cloudformation": "^0.26.0",
"@aws-cdk/aws-codebuild": "^0.26.0",
"@aws-cdk/aws-codepipeline-actions": "^0.26.0",
"@aws-cdk/aws-codepipeline-api": "^0.26.0",
"@aws-cdk/aws-iam": "^0.26.0",
"@aws-cdk/cdk": "^0.26.0",
Expand Down Expand Up @@ -66,11 +67,12 @@
],
"peerDependencies": {
"@aws-cdk/aws-cloudformation": "^0.26.0",
"@aws-cdk/aws-codepipeline-actions": "^0.26.0",
"@aws-cdk/aws-codepipeline-api": "^0.26.0",
"@aws-cdk/aws-iam": "^0.26.0",
"@aws-cdk/cdk": "^0.26.0"
},
"engines": {
"node": ">= 8.10.0"
}
}
}
7 changes: 4 additions & 3 deletions packages/@aws-cdk/app-delivery/test/integ.cicd.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import cfn = require('@aws-cdk/aws-cloudformation');
import code = require('@aws-cdk/aws-codepipeline');
import codepipeline = require('@aws-cdk/aws-codepipeline');
import cpactions = require('@aws-cdk/aws-codepipeline-actions');
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import cicd = require('../lib');

const app = new cdk.App();

const stack = new cdk.Stack(app, 'CICD');
const pipeline = new code.Pipeline(stack, 'CodePipeline', {
const pipeline = new codepipeline.Pipeline(stack, 'CodePipeline', {
artifactBucket: new s3.Bucket(stack, 'ArtifactBucket', {
removalPolicy: cdk.RemovalPolicy.Destroy
})
});
const source = new code.GitHubSourceAction({
const source = new cpactions.GitHubSourceAction({
actionName: 'GitHub',
owner: 'awslabs',
repo: 'aws-cdk',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import cfn = require('@aws-cdk/aws-cloudformation');
import codebuild = require('@aws-cdk/aws-codebuild');
import code = require('@aws-cdk/aws-codepipeline');
import api = require('@aws-cdk/aws-codepipeline-api');
import codepipeline = require('@aws-cdk/aws-codepipeline');
import cpactions = require('@aws-cdk/aws-codepipeline-actions');
import cpapi = require('@aws-cdk/aws-codepipeline-api');
import iam = require('@aws-cdk/aws-iam');
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
Expand All @@ -13,8 +14,8 @@ import { countResources, expect, haveResource, isSuperObject } from '@aws-cdk/as
import { PipelineDeployStackAction } from '../lib/pipeline-deploy-stack-action';

interface SelfUpdatingPipeline {
synthesizedApp: api.Artifact;
pipeline: code.Pipeline;
synthesizedApp: cpapi.Artifact;
pipeline: codepipeline.Pipeline;
}
const accountId = fc.array(fc.integer(0, 9), 12, 12).map(arr => arr.join());

Expand All @@ -28,7 +29,7 @@ export = nodeunit.testCase({
test.throws(() => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Test', { env: { account: pipelineAccount } });
const pipeline = new code.Pipeline(stack, 'Pipeline');
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
const fakeAction = new FakeAction('Fake');
pipeline.addStage({
name: 'FakeStage',
Expand Down Expand Up @@ -57,7 +58,7 @@ export = nodeunit.testCase({
test.throws(() => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Test');
const pipeline = new code.Pipeline(stack, 'Pipeline');
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
const fakeAction = new FakeAction('Fake');
pipeline.addStage({
name: 'FakeStage',
Expand Down Expand Up @@ -272,7 +273,7 @@ export = nodeunit.testCase({
(assetCount) => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Test');
const pipeline = new code.Pipeline(stack, 'Pipeline');
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
const fakeAction = new FakeAction('Fake');
pipeline.addStage({
name: 'FakeStage',
Expand All @@ -299,21 +300,21 @@ export = nodeunit.testCase({
}
});

class FakeAction extends api.Action {
public readonly outputArtifact: api.Artifact;
class FakeAction extends cpapi.Action {
public readonly outputArtifact: cpapi.Artifact;

constructor(actionName: string) {
super({
actionName,
artifactBounds: api.defaultBounds(),
category: api.ActionCategory.Test,
artifactBounds: cpapi.defaultBounds(),
category: cpapi.ActionCategory.Test,
provider: 'Test',
});

this.outputArtifact = new api.Artifact('OutputArtifact');
this.outputArtifact = new cpapi.Artifact('OutputArtifact');
}

protected bind(_info: api.IBindInfo): void {
protected bind(_info: cpapi.IBindInfo): void {
// do nothing
}
}
Expand All @@ -323,13 +324,13 @@ function getTestStack(): cdk.Stack {
}

function createSelfUpdatingStack(pipelineStack: cdk.Stack): SelfUpdatingPipeline {
const pipeline = new code.Pipeline(pipelineStack, 'CodePipeline', {
const pipeline = new codepipeline.Pipeline(pipelineStack, 'CodePipeline', {
restartExecutionOnUpdate: true,
});

// simple source
const bucket = s3.Bucket.import( pipeline, 'PatternBucket', { bucketArn: 'arn:aws:s3:::totally-fake-bucket' });
const sourceAction = new s3.PipelineSourceAction({
const sourceAction = new cpactions.S3SourceAction({
actionName: 'S3Source',
bucket,
bucketKey: 'the-great-key',
Expand All @@ -340,8 +341,9 @@ function createSelfUpdatingStack(pipelineStack: cdk.Stack): SelfUpdatingPipeline
});

const project = new codebuild.PipelineProject(pipelineStack, 'CodeBuild');
const buildAction = project.toCodePipelineBuildAction({
const buildAction = new cpactions.CodeBuildBuildAction({
actionName: 'CodeBuild',
project,
inputArtifact: sourceAction.outputArtifact,
});
pipeline.addStage({
Expand Down
25 changes: 0 additions & 25 deletions packages/@aws-cdk/aws-cloudformation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,6 @@

This module is part of the [AWS Cloud Development Kit](https://github.com/awslabs/aws-cdk) project.

### CodePipeline Actions for CloudFormation

This module contains Actions that allows you to deploy to CloudFormation from AWS CodePipeline.

For example, the following code fragment defines a pipeline that automatically deploys a CloudFormation template
directly from a CodeCommit repository, with a manual approval step in between to confirm the changes:

[example Pipeline to deploy CloudFormation](../aws-codepipeline/test/integ.cfn-template-from-repo.lit.ts)

See [the AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline.html)
for more details about using CloudFormation in CodePipeline.

#### Actions defined by this package

This package defines the following actions:

* **PipelineCreateUpdateStackAction** - Deploy a CloudFormation template directly from the pipeline. The indicated stack is created,
or updated if it already exists. If the stack is in a failure state, deployment will fail (unless `replaceOnFailure`
is set to `true`, in which case it will be destroyed and recreated).
* **PipelineDeleteStackAction** - Delete the stack with the given name.
* **PipelineCreateReplaceChangeSetAction** - Prepare a change set to be applied later. You will typically use change sets if you want
to manually verify the changes that are being staged, or if you want to separate the people (or system) preparing the
changes from the people (or system) applying the changes.
* **PipelineExecuteChangeSetAction** - Execute a change set prepared previously.

### Custom Resources

Custom Resources are CloudFormation resources that are implemented by
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Capabilities that affect whether CloudFormation is allowed to change IAM resources
*/
export enum CloudFormationCapabilities {
/**
* No IAM Capabilities
*
* Pass this capability if you wish to block the creation IAM resources.
* @link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html#using-iam-capabilities
*/
None = '',

/**
* Capability to create anonymous IAM resources
*
* Pass this capability if you're only creating anonymous resources.
* @link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html#using-iam-capabilities
*/
AnonymousIAM = 'CAPABILITY_IAM',

/**
* Capability to create named IAM resources.
*
* Pass this capability if you're creating IAM resources that have physical
* names.
*
* `CloudFormationCapabilities.NamedIAM` implies `CloudFormationCapabilities.IAM`; you don't have to pass both.
* @link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html#using-iam-capabilities
*/
NamedIAM = 'CAPABILITY_NAMED_IAM',
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudformation/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './cloud-formation-capabilities';
export * from './custom-resource';
export * from './pipeline-actions';

// AWS::CloudFormation CloudFormation Resources:
export * from './cloudformation.generated';
Loading

0 comments on commit f6d0b39

Please sign in to comment.