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 16, 2018
1 parent 39a3362 commit 5dde0fe
Show file tree
Hide file tree
Showing 7 changed files with 465 additions and 0 deletions.
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';
81 changes: 81 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,81 @@
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.
*/
application: string;

/**
* The name of the CodeDeploy deployment group to deploy to.
*/
deploymentGroup: 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.application,
DeploymentGroupName: props.deploymentGroup,
},
});

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

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

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

const actionsOnDeployConfig = [
'codedeploy:GetDeploymentConfig',
];
const deployConfigArn = cdk.Arn.fromComponents({
service: 'codedeploy',
resource: 'deploymentconfig',
resourceName: '*',
sep: ':',
});
props.stage.pipelineRole.addToPolicy(new cdk.PolicyStatement()
.addResource(deployConfigArn)
.addActions(...actionsOnDeployConfig));
}
}
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
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 5dde0fe

Please sign in to comment.