Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: re-structure the CodePipeline Construct library API #1590

Merged
merged 1 commit into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions packages/@aws-cdk/alexa-ask/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ You can deploy to Alexa using CodePipeline with the following DeployAction.

```ts
// Read the secrets from ParameterStore
const clientId = new cdk.SecretParameter(stack, 'AlexaClientId', {ssmParameter: '/Alexa/ClientId'});
const clientSecret = new cdk.SecretParameter(stack, 'AlexaClientSecret', {ssmParameter: '/Alexa/ClientSecret'});
const refreshToken = new cdk.SecretParameter(stack, 'AlexaRefreshToken', {ssmParameter: '/Alexa/RefreshToken'});
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 alexa.AlexaSkillDeployAction(stack, 'DeploySkill', {
stage: deployStage,
new alexaAsk.AlexaSkillDeployAction({
actionName: 'DeploySkill',
runOrder: 1,
inputArtifact: sourceAction.outputArtifact,
clientId: clientId.value,
Expand All @@ -26,12 +26,14 @@ new alexa.AlexaSkillDeployAction(stack, 'DeploySkill', {
});
```

If you need manifest overrides you can specify them as `overrideArtifact` in the action.
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 PipelineExecuteChangeSetAction(this, 'ExecuteChangesTest', {
stage: deployStage,
const executeChangeSetAction = new cloudformation.PipelineExecuteChangeSetAction({
actionName: 'ExecuteChangesTest',
runOrder: 2,
stackName,
changeSetName,
Expand All @@ -40,8 +42,8 @@ const executeChangeSetAction = new PipelineExecuteChangeSetAction(this, 'Execute
});

// Provide CFN output as manifest overrides
new AlexaSkillDeployAction(this, 'DeploySkill', {
stage: deployStage,
new alexaAsk.AlexaSkillDeployAction({
actionName: 'DeploySkill',
runOrder: 1,
inputArtifact: sourceAction.outputArtifact,
parameterOverridesArtifact: executeChangeSetAction.outputArtifact,
Expand All @@ -50,4 +52,4 @@ new AlexaSkillDeployAction(this, 'DeploySkill', {
refreshToken: refreshToken.value,
skillId: 'amzn1.ask.skill.12345678-1234-1234-1234-123456789012',
});
```
```
15 changes: 9 additions & 6 deletions packages/@aws-cdk/alexa-ask/lib/pipeline-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import cdk = require('@aws-cdk/cdk');
/**
* Construction properties of the {@link AlexaSkillDeployAction Alexa deploy Action}.
*/
export interface AlexaSkillDeployActionProps extends codepipeline.CommonActionProps,
codepipeline.CommonActionConstructProps {

export interface AlexaSkillDeployActionProps extends codepipeline.CommonActionProps {
/**
* The client id of the developer console token
*/
Expand All @@ -30,7 +28,7 @@ export interface AlexaSkillDeployActionProps extends codepipeline.CommonActionPr
/**
* The source artifact containing the voice model and skill manifest
*/
inputArtifact?: codepipeline.Artifact;
inputArtifact: codepipeline.Artifact;

/**
* An optional artifact containing overrides for the skill manifest
Expand All @@ -42,8 +40,8 @@ export interface AlexaSkillDeployActionProps extends codepipeline.CommonActionPr
* Deploys the skill to Alexa
*/
export class AlexaSkillDeployAction extends codepipeline.DeployAction {
constructor(scope: cdk.Construct, id: string, props: AlexaSkillDeployActionProps) {
super(scope, id, {
constructor(props: AlexaSkillDeployActionProps) {
super({
...props,
artifactBounds: {
minInputs: 1,
Expand All @@ -60,8 +58,13 @@ export class AlexaSkillDeployAction extends codepipeline.DeployAction {
SkillId: props.skillId,
},
});

if (props.parameterOverridesArtifact) {
this.addInputArtifact(props.parameterOverridesArtifact);
}
}

protected bind(_stage: codepipeline.IStage, _scope: cdk.Construct): void {
// nothing to do
}
}
41 changes: 27 additions & 14 deletions packages/@aws-cdk/app-delivery/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Continuous Integration / Continuous Delivery for CDK Applications
This library includes a *CodePipeline* action for deploying AWS CDK Applications.
This library includes a *CodePipeline* composite Action for deploying AWS CDK Applications.

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

Expand Down Expand Up @@ -29,7 +29,7 @@ The example below defines a *CDK App* that contains 3 stacks:
```

#### `index.ts`
```ts
```typescript
import codebuild = require('@aws-cdk/aws-codebuild');
import codepipeline = require('@aws-cdk/aws-codepipeline');
import cdk = require('@aws-cdk/cdk');
Expand All @@ -46,36 +46,48 @@ const pipeline = new codepipeline.Pipeline(pipelineStack, 'CodePipeline', {
restartExecutionOnUpdate: true,
/* ... */
});

// Configure the CodePipeline source - where your CDK App's source code is hosted
const source = new codepipeline.GitHubSourceAction(pipelineStack, 'GitHub', {
stage: pipeline.addStage('source'),
const source = new codepipeline.GitHubSourceAction({
actionName: 'GitHub',
/* ... */
});
pipeline.addStage({
name: 'source',
actions: [source],
});

const project = new codebuild.PipelineProject(pipelineStack, 'CodeBuild', {
/**
* Choose an environment configuration that meets your use case. For NodeJS
* this might be
* Choose an environment configuration that meets your use case.
* For NodeJS, this might be:
*
* environment: {
* buildImage: codebuild.LinuxBuildImage.UBUNTU_14_04_NODEJS_10_1_0,
* buildImage: codebuild.LinuxBuildImage.UBUNTU_14_04_NODEJS_10_1_0,
* },
*/
});
const buildStage = pipeline.addStage('build');
const buildAction = project.addToPipeline(buildStage, 'CodeBuild');
const buildAction = project.toCodePipelineBuildAction({
actionName: 'CodeBuild',
inputArtifact: source.outputArtifact,
});
pipeline.addStage({
name: 'build',
actions: [buildAction],
});
const synthesizedApp = buildAction.outputArtifact;

// Optionally, self-update the pipeline stack
const selfUpdateStage = pipeline.addStage('SelfUpdate');
const selfUpdateStage = pipeline.addStage({ name: 'SelfUpdate' });
new cicd.PipelineDeployStackAction(pipelineStack, 'SelfUpdatePipeline', {
stage: selfUpdateStage,
stack: pipelineStack,
inputArtifact: synthesizedApp,
});

// Now add our service stacks
const deployStage = pipeline.addStage('Deploy');
const deployStage = pipeline.addStage({ name: 'Deploy' });
const serviceStackA = new MyServiceStackA(app, 'ServiceStackA', { /* ... */ });
const serviceStackB = new MyServiceStackB(app, 'ServiceStackB', { /* ... */ });
// Add actions to deploy the stacks in the deploy stage:
const deployServiceAAction = new cicd.PipelineDeployStackAction(pipelineStack, 'DeployServiceStackA', {
stage: deployStage,
Expand All @@ -84,7 +96,6 @@ const deployServiceAAction = new cicd.PipelineDeployStackAction(pipelineStack, '
// See the note below for details about this option.
adminPermissions: false,
});

// Add the necessary permissions for you service deploy action. This role is
// is passed to CloudFormation and needs the permissions necessary to deploy
// stack. Alternatively you can enable [Administrator](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_job-functions.html#jf_administrator) permissions above,
Expand All @@ -95,7 +106,9 @@ deployServiceAAction.addToRolePolicy(
.addResource(myResource.myResourceArn)
// add more Action(s) and/or Resource(s) here, as needed
);
const deployServiceBAction = new cicd.PipelineDeployStackAction(pipelineStack, 'DeployServiceStackB', {

const serviceStackB = new MyServiceStackB(app, 'ServiceStackB', { /* ... */ });
new cicd.PipelineDeployStackAction(pipelineStack, 'DeployServiceStackB', {
stage: deployStage,
stack: serviceStackB,
inputArtifact: synthesizedApp,
Expand Down
19 changes: 10 additions & 9 deletions packages/@aws-cdk/app-delivery/lib/pipeline-deploy-stack-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export interface PipelineDeployStackActionProps {
}

/**
* A CodePipeline action to deploy a stack that is part of a CDK App. This
* action takes care of preparing and executing a CloudFormation ChangeSet.
* A Construct to deploy a stack that is part of a CDK App, using CodePipeline.
* This composite Action takes care of preparing and executing a CloudFormation ChangeSet.
*
* It currently does *not* support stacks that make use of ``Asset``s, and
* requires the deployed stack is in the same account and region where the
Expand Down Expand Up @@ -120,24 +120,25 @@ 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(this, 'ChangeSet', {
const changeSetAction = new cfn.PipelineCreateReplaceChangeSetAction({
actionName: 'ChangeSet',
changeSetName,
runOrder: createChangeSetRunOrder,
stackName: props.stack.name,
stage: props.stage,
templatePath: props.inputArtifact.atPath(`${props.stack.name}.template.yaml`),
adminPermissions: props.adminPermissions,
deploymentRole: props.role,
capabilities,
});
this.deploymentRole = changeSetAction.deploymentRole;

new cfn.PipelineExecuteChangeSetAction(this, 'Execute', {
props.stage.addAction(changeSetAction);
props.stage.addAction(new cfn.PipelineExecuteChangeSetAction({
actionName: 'Execute',
changeSetName,
runOrder: executeChangeSetRunOrder,
stackName: props.stack.name,
stage: props.stage,
});
}));

this.deploymentRole = changeSetAction.deploymentRole;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/app-delivery/test/integ.cicd.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"DeployStackChangeSetRole4923A126",
"CodePipelineDeployChangeSetRoleF9F2B343",
"Arn"
]
}
Expand Down Expand Up @@ -202,7 +202,7 @@
"TemplatePath": "Artifact_CICDGitHubF8BA7ADD::CICD.template.yaml",
"RoleArn": {
"Fn::GetAtt": [
"DeployStackChangeSetRole4923A126",
"CodePipelineDeployChangeSetRoleF9F2B343",
"Arn"
]
}
Expand Down Expand Up @@ -243,7 +243,7 @@
"CodePipelineRoleB3A660B4"
]
},
"DeployStackChangeSetRole4923A126": {
"CodePipelineDeployChangeSetRoleF9F2B343": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
Expand Down
11 changes: 8 additions & 3 deletions packages/@aws-cdk/app-delivery/test/integ.cicd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ const pipeline = new code.Pipeline(stack, 'CodePipeline', {
removalPolicy: cdk.RemovalPolicy.Destroy
})
});
const source = new code.GitHubSourceAction(stack, 'GitHub', {
stage: pipeline.addStage('Source'),
const source = new code.GitHubSourceAction({
actionName: 'GitHub',
owner: 'awslabs',
repo: 'aws-cdk',
oauthToken: new cdk.Secret('DummyToken'),
pollForSourceChanges: true,
outputArtifactName: 'Artifact_CICDGitHubF8BA7ADD',
});
const stage = pipeline.addStage('Deploy');
pipeline.addStage({
name: 'Source',
actions: [source],
});
const stage = pipeline.addStage({ name: 'Deploy' });
new cicd.PipelineDeployStackAction(stack, 'DeployStack', {
stage,
stack,
Expand Down
Loading