-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha! How was this not here yet? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
|
@@ -18,5 +21,9 @@ export abstract class DeployAction extends Action { | |
artifactBounds: props.artifactBounds, | ||
configuration: props.configuration, | ||
}); | ||
|
||
if (props.inputArtifact) { | ||
this.addInputArtifact(props.inputArtifact); | ||
} | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.