Skip to content

Commit

Permalink
feat(aws-codedeploy): Add a CodeDeploy CodePipeline deployment Action.
Browse files Browse the repository at this point in the history
  • Loading branch information
skinny85 committed Aug 20, 2018
1 parent bca7b85 commit 895e92a
Show file tree
Hide file tree
Showing 9 changed files with 495 additions and 10 deletions.
28 changes: 27 additions & 1 deletion packages/@aws-cdk/aws-codedeploy/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
## The CDK Construct Library for AWS CodeDeploy
This module is part of the [AWS Cloud Development Kit](https://github.com/awslabs/aws-cdk) project.

### Use in CodePipeline

This module contains an Action that allows you to use CodeDeploy with AWS CodePipeline.

Example:

```ts
import codedeploy = require('@aws-cdk/aws-codedeploy');
import codepipeline = require('@aws-cdk/aws-codepipeline');

const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', {
pipelineName: 'MyPipeline',
});

// add the source and build Stages to the Pipeline...

const deployStage = new codepipeline.Stage(this, 'Deploy', {
pipeline,
}));
new codedeploy.PipelineDeployAction(this, 'CodeDeploy', {
stage: deployStage,
inputArtifact: buildAction.artifact, // taken from a build Action in a previous Stage
applicationName: 'YourCodeDeployApplicationName',
deploymentGroupName: 'YourCodeDeployDeploymentGroupName',
});
```
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-codedeploy/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './pipeline-action';

// AWS::CodeDeploy CloudFormation Resources:
export * from './codedeploy.generated';
84 changes: 84 additions & 0 deletions packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import actions = require('@aws-cdk/aws-codepipeline-api');
import cdk = require('@aws-cdk/cdk');

/**
* Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}.
*/
export interface PipelineDeployActionProps extends actions.CommonActionProps {
/**
* The name of the CodeDeploy application to deploy to.
*
* @note this will most likely be changed to a proper CodeDeploy AWS Construct reference
* once that functionality has been implemented for CodeDeploy
*/
applicationName: string;

/**
* The name of the CodeDeploy deployment group to deploy to.
*
* @note this will most likely be changed to a proper CodeDeploy AWS Construct reference
* once that functionality has been implemented for CodeDeploy
*/
deploymentGroupName: string;

/**
* The source to use as input for deployment.
*/
inputArtifact: actions.Artifact;
}

export class PipelineDeployAction extends actions.DeployAction {
constructor(parent: cdk.Construct, id: string, props: PipelineDeployActionProps) {
super(parent, id, {
stage: props.stage,
artifactBounds: { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 },
provider: 'CodeDeploy',
inputArtifact: props.inputArtifact,
configuration: {
ApplicationName: props.applicationName,
DeploymentGroupName: props.deploymentGroupName,
},
});

// permissions, based on:
// https://docs.aws.amazon.com/codedeploy/latest/userguide/auth-and-access-control-permissions-reference.html

const applicationArn = cdk.Arn.fromComponents({
service: 'codedeploy',
resource: 'application',
resourceName: props.applicationName,
sep: ':',
});
props.stage.pipelineRole.addToPolicy(new cdk.PolicyStatement()
.addResource(applicationArn)
.addActions(
'codedeploy:GetApplicationRevision',
'codedeploy:RegisterApplicationRevision',
));

const deploymentGroupArn = cdk.Arn.fromComponents({
service: 'codedeploy',
resource: 'deploymentgroup',
resourceName: `${props.applicationName}/${props.deploymentGroupName}`,
sep: ':',
});
props.stage.pipelineRole.addToPolicy(new cdk.PolicyStatement()
.addResource(deploymentGroupArn)
.addActions(
'codedeploy:CreateDeployment',
'codedeploy:GetDeployment',
));

const deployConfigArn = cdk.Arn.fromComponents({
service: 'codedeploy',
resource: 'deploymentconfig',
resourceName: '*',
sep: ':',
});
props.stage.pipelineRole.addToPolicy(new cdk.PolicyStatement()
.addResource(deployConfigArn)
.addActions(
'codedeploy:GetDeploymentConfig',
));
}
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-codedeploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"pkglint": "^0.8.2"
},
"dependencies": {
"@aws-cdk/aws-codepipeline-api": "^0.8.2",
"@aws-cdk/cdk": "^0.8.2"
},
"homepage": "https://github.com/awslabs/aws-cdk"
Expand Down
9 changes: 0 additions & 9 deletions packages/@aws-cdk/aws-codepipeline-api/lib/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,6 @@ export abstract class Action extends cdk.Construct {
// }
// }

// export class CodeDeploy extends DeployAction {
// constructor(parent: Stage, name: string, applicationName: string, deploymentGroupName: string) {
// super(parent, name, 'CodeDeploy', { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, {
// ApplicationName: applicationName,
// DeploymentGroupName: deploymentGroupName
// });
// }
// }

// export class ElasticBeanstalkDeploy extends DeployAction {
// constructor(parent: Stage, name: string, applicationName: string, environmentName: string) {
// super(parent, name, 'ElasticBeanstalk', { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, {
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-codepipeline-api/lib/deploy-action.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import cdk = require('@aws-cdk/cdk');
import { Action, ActionArtifactBounds, ActionCategory, CommonActionProps } from "./action";
import { Artifact } from './artifact';

export interface DeployActionProps extends CommonActionProps {
provider: string;

artifactBounds: ActionArtifactBounds;

inputArtifact?: Artifact;

configuration?: any;
}

Expand All @@ -18,5 +21,9 @@ export abstract class DeployAction extends Action {
artifactBounds: props.artifactBounds,
configuration: props.configuration,
});

if (props.inputArtifact) {
this.addInputArtifact(props.inputArtifact);
}
}
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-codepipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@aws-cdk/aws-cloudformation": "^0.8.2",
"@aws-cdk/aws-codebuild": "^0.8.2",
"@aws-cdk/aws-codecommit": "^0.8.2",
"@aws-cdk/aws-codedeploy": "^0.8.2",
"@aws-cdk/aws-lambda": "^0.8.2",
"@aws-cdk/aws-sns": "^0.8.2",
"cdk-build-tools": "^0.8.2",
Expand Down
Loading

0 comments on commit 895e92a

Please sign in to comment.