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

feat(aws-codedeploy): add an addToPipeline method to Deployment Group #1166

Merged
merged 1 commit into from
Nov 14, 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
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-codedeploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', {
const deployStage = pipeline.addStage('Deploy');
new codedeploy.PipelineDeployAction(this, 'CodeDeploy', {
stage: deployStage,
applicationName: 'YourCodeDeployApplicationName',
deploymentGroupName: 'YourCodeDeployDeploymentGroupName',
deploymentGroup,
});
```

You can also add the Deployment Group to the Pipeline directly:

```ts
// equivalent to the code above:
deploymentGroup.addToPipeline(deployStage, 'CodeDeploy');
```
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import autoscaling = require("@aws-cdk/aws-autoscaling");
import cloudwatch = require("@aws-cdk/aws-cloudwatch");
import codedeploylb = require("@aws-cdk/aws-codedeploy-api");
import codepipeline = require("@aws-cdk/aws-codepipeline-api");
import ec2 = require("@aws-cdk/aws-ec2");
import iam = require('@aws-cdk/aws-iam');
import s3 = require("@aws-cdk/aws-s3");
import cdk = require("@aws-cdk/cdk");
import { ServerApplication, ServerApplicationRef } from "./application";
import { cloudformation } from './codedeploy.generated';
import { IServerDeploymentConfig, ServerDeploymentConfig } from "./deployment-config";
import { CommonPipelineDeployActionProps, PipelineDeployAction } from "./pipeline-action";

/**
* Properties of a reference to a CodeDeploy EC2/on-premise Deployment Group.
Expand Down Expand Up @@ -81,6 +83,24 @@ export abstract class ServerDeploymentGroupRef extends cdk.Construct {
deploymentConfig: this.deploymentConfig,
};
}

/**
* Convenience method for creating a new {@link PipelineDeployAction}
* and adding it to the given Stage.
*
* @param stage the Pipeline Stage to add the new Action to
* @param name the name of the newly created Action
* @param props the properties of the new Action
* @returns the newly created {@link PipelineDeployAction} deploy Action
*/
public addToPipeline(stage: codepipeline.IStage, name: string, props: CommonPipelineDeployActionProps = {}):
PipelineDeployAction {
return new PipelineDeployAction(this, name, {
deploymentGroup: this,
stage,
...props,
});
}
}

class ImportedServerDeploymentGroupRef extends ServerDeploymentGroupRef {
Expand Down
23 changes: 15 additions & 8 deletions packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import cdk = require('@aws-cdk/cdk');
import { ServerDeploymentGroupRef } from './deployment-group';

/**
* Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}.
* Common properties for creating a {@link PipelineDeployAction},
* either directly, through its constructor,
* or through {@link ServerDeploymentGroupRef#addToPipeline}.
*/
export interface PipelineDeployActionProps extends codepipeline.CommonActionProps,
codepipeline.CommonActionConstructProps {
/**
* The CodeDeploy Deployment Group to deploy to.
*/
deploymentGroup: ServerDeploymentGroupRef;

export interface CommonPipelineDeployActionProps extends codepipeline.CommonActionProps {
/**
* The source to use as input for deployment.
*
Expand All @@ -21,6 +17,17 @@ export interface PipelineDeployActionProps extends codepipeline.CommonActionProp
inputArtifact?: codepipeline.Artifact;
}

/**
* Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}.
*/
export interface PipelineDeployActionProps extends CommonPipelineDeployActionProps,
codepipeline.CommonActionConstructProps {
/**
* The CodeDeploy Deployment Group to deploy to.
*/
deploymentGroup: ServerDeploymentGroupRef;
}

export class PipelineDeployAction extends codepipeline.DeployAction {
constructor(parent: cdk.Construct, id: string, props: PipelineDeployActionProps) {
super(parent, id, {
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codepipeline-api/lib/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export interface IPipeline extends events.IEventRuleTarget {
*/
readonly role: iam.Role;

/* Grants read permissions to the Pipeline's S3 Bucket to the given Identity.
/**
* Grants read permissions to the Pipeline's S3 Bucket to the given Identity.
*
* @param identity the IAM Identity to grant the permissions to
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ bucket.addToPipeline(sourceStage, 'S3Source', {
});

const deployStage = new codepipeline.Stage(stack, 'Deploy', { pipeline });
new codedeploy.PipelineDeployAction(stack, 'CodeDeploy', {
stage: deployStage,
deploymentGroup,
});
deploymentGroup.addToPipeline(deployStage, 'CodeDeploy');

app.run();