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

Add a CodeDeploy CodePipeline deployment Action #593

Merged
merged 1 commit into from
Aug 20, 2018
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
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that everyone is super clear on what's going on, can you rename this to applicationName and note in the docstrings that this is a temporary API that will disappear until we get L2s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

*
* @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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! How was this not here yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess Breland didn't need it for the CloudFormation Actions...


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