-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-codedeploy): Add a CodeDeploy CodePipeline deployment Action.
- Loading branch information
Showing
9 changed files
with
495 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.