Skip to content

Commit 118e529

Browse files
committed
docs: update readme
1 parent c93f168 commit 118e529

File tree

1 file changed

+59
-46
lines changed
  • packages/cdk-blue-green-container-deployment

1 file changed

+59
-46
lines changed

packages/cdk-blue-green-container-deployment/README.md

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![cloudcomponents Logo](https://raw.githubusercontent.com/cloudcomponents/cdk-constructs/master/logo.png)](https://github.com/cloudcomponents/cdk-constructs)
22

3-
# @cloudcomponents/cdk-blue-green-container-deployment
3+
# @cloudcomponents/cdk-blue-green-container-deployment
44

55
[![Build Status](https://github.com/cloudcomponents/cdk-constructs/workflows/Build/badge.svg)](https://github.com/cloudcomponents/cdk-constructs/actions?query=workflow=Build)
66
[![cdkdx](https://img.shields.io/badge/buildtool-cdkdx-blue.svg)](https://github.com/hupe1980/cdkdx)
@@ -11,6 +11,7 @@
1111
> Blue green container deployment with CodeDeploy
1212
1313
## Install
14+
1415
TypeScript/JavaScript:
1516

1617
```bash
@@ -26,97 +27,97 @@ pip install cloudcomponents.cdk-blue-green-container-deployment
2627
## How to use
2728

2829
```typescript
29-
import { Construct, Stack, StackProps } from '@aws-cdk/core';
30-
import { Repository } from '@aws-cdk/aws-codecommit';
31-
import { Pipeline, Artifact } from '@aws-cdk/aws-codepipeline';
32-
import { Vpc, Port } from '@aws-cdk/aws-ec2';
33-
import { Cluster } from '@aws-cdk/aws-ecs';
30+
import { Construct, Stack, StackProps } from "@aws-cdk/core";
31+
import { Repository } from "@aws-cdk/aws-codecommit";
32+
import { Pipeline, Artifact } from "@aws-cdk/aws-codepipeline";
33+
import { Vpc, Port } from "@aws-cdk/aws-ec2";
34+
import { Cluster } from "@aws-cdk/aws-ecs";
3435
import {
3536
ApplicationLoadBalancer,
3637
ApplicationTargetGroup,
3738
TargetType,
38-
} from '@aws-cdk/aws-elasticloadbalancingv2';
39+
} from "@aws-cdk/aws-elasticloadbalancingv2";
3940
import {
4041
CodeBuildAction,
4142
CodeCommitSourceAction,
4243
CodeDeployEcsDeployAction,
43-
} from '@aws-cdk/aws-codepipeline-actions';
44+
} from "@aws-cdk/aws-codepipeline-actions";
4445

45-
import { ImageRepository } from '@cloudcomponents/cdk-container-registry';
46+
import { ImageRepository } from "@cloudcomponents/cdk-container-registry";
4647
import {
4748
EcsService,
4849
DummyTaskDefinition,
4950
EcsDeploymentGroup,
5051
PushImageProject,
51-
} from '@cloudcomponents/cdk-blue-green-container-deployment';
52+
} from "@cloudcomponents/cdk-blue-green-container-deployment";
5253

5354
export class BlueGreenContainerDeploymentStack extends Stack {
5455
constructor(scope: Construct, id: string, props?: StackProps) {
5556
super(scope, id, props);
5657

57-
const vpc = new Vpc(this, 'Vpc', {
58+
const vpc = new Vpc(this, "Vpc", {
5859
maxAzs: 2,
5960
});
6061

61-
const cluster = new Cluster(this, 'Cluster', {
62+
const cluster = new Cluster(this, "Cluster", {
6263
vpc,
63-
clusterName: 'blue-green-cluster',
64+
clusterName: "blue-green-cluster",
6465
});
6566

66-
const loadBalancer = new ApplicationLoadBalancer(this, 'LoadBalancer', {
67+
const loadBalancer = new ApplicationLoadBalancer(this, "LoadBalancer", {
6768
vpc,
6869
internetFacing: true,
6970
});
7071

71-
const prodListener = loadBalancer.addListener('ProfListener', {
72+
const prodListener = loadBalancer.addListener("ProfListener", {
7273
port: 80,
7374
});
7475

75-
const testListener = loadBalancer.addListener('TestListener', {
76+
const testListener = loadBalancer.addListener("TestListener", {
7677
port: 8080,
7778
});
7879

7980
const prodTargetGroup = new ApplicationTargetGroup(
8081
this,
81-
'ProdTargetGroup',
82+
"ProdTargetGroup",
8283
{
8384
port: 80,
8485
targetType: TargetType.IP,
8586
vpc,
86-
},
87+
}
8788
);
8889

89-
prodListener.addTargetGroups('AddProdTg', {
90+
prodListener.addTargetGroups("AddProdTg", {
9091
targetGroups: [prodTargetGroup],
9192
});
9293

9394
const testTargetGroup = new ApplicationTargetGroup(
9495
this,
95-
'TestTargetGroup',
96+
"TestTargetGroup",
9697
{
9798
port: 8080,
9899
targetType: TargetType.IP,
99100
vpc,
100-
},
101+
}
101102
);
102103

103-
testListener.addTargetGroups('AddTestTg', {
104+
testListener.addTargetGroups("AddTestTg", {
104105
targetGroups: [testTargetGroup],
105106
});
106107

107108
// Will be replaced by CodeDeploy in CodePipeline
108109
const taskDefinition = new DummyTaskDefinition(
109110
this,
110-
'DummyTaskDefinition',
111+
"DummyTaskDefinition",
111112
{
112-
image: 'nginx',
113-
family: 'blue-green',
114-
},
113+
image: "nginx",
114+
family: "blue-green",
115+
}
115116
);
116117

117-
const ecsService = new EcsService(this, 'EcsService', {
118+
const ecsService = new EcsService(this, "EcsService", {
118119
cluster,
119-
serviceName: 'blue-green-service',
120+
serviceName: "blue-green-service",
120121
desiredCount: 2,
121122
taskDefinition,
122123
prodTargetGroup,
@@ -125,9 +126,9 @@ export class BlueGreenContainerDeploymentStack extends Stack {
125126
ecsService.connections.allowFrom(loadBalancer, Port.tcp(80));
126127
ecsService.connections.allowFrom(loadBalancer, Port.tcp(8080));
127128

128-
const deploymentGroup = new EcsDeploymentGroup(this, 'DeploymentGroup', {
129-
applicationName: 'blue-green-application',
130-
deploymentGroupName: 'blue-green-deployment-group',
129+
const deploymentGroup = new EcsDeploymentGroup(this, "DeploymentGroup", {
130+
applicationName: "blue-green-application",
131+
deploymentGroupName: "blue-green-deployment-group",
131132
ecsServices: [ecsService],
132133
targetGroupNames: [
133134
prodTargetGroup.targetGroupName,
@@ -136,66 +137,78 @@ export class BlueGreenContainerDeploymentStack extends Stack {
136137
prodTrafficListener: prodListener,
137138
testTrafficListener: testListener,
138139
terminationWaitTimeInMinutes: 100,
140+
autoRollbackOnEvents: [RollbackEvent.DEPLOYMENT_FAILURE],
141+
createDeploymentConfigInput: {
142+
computePlatform: "ECS",
143+
deploymentConfigName: "Canary20Percent5Minute",
144+
trafficRoutingConfig: {
145+
type: "TimeBasedCanary",
146+
timeBasedCanary: {
147+
canaryInterval: 5,
148+
canaryPercentage: 20,
149+
},
150+
},
151+
},
139152
});
140153

141154
// @see https://github.com/cloudcomponents/cdk-constructs/tree/master/examples/blue-green-container-deployment-example/blue-green-repository
142-
const repository = new Repository(this, 'CodeRepository', {
143-
repositoryName: 'blue-green-repository',
155+
const repository = new Repository(this, "CodeRepository", {
156+
repositoryName: "blue-green-repository",
144157
});
145158

146-
const imageRepository = new ImageRepository(this, 'ImageRepository', {
159+
const imageRepository = new ImageRepository(this, "ImageRepository", {
147160
forceDelete: true, //Only for tests
148161
});
149162

150163
const sourceArtifact = new Artifact();
151164

152165
const sourceAction = new CodeCommitSourceAction({
153-
actionName: 'CodeCommit',
166+
actionName: "CodeCommit",
154167
repository,
155168
output: sourceArtifact,
156169
});
157170

158-
const imageArtifact = new Artifact('ImageArtifact');
159-
const manifestArtifact = new Artifact('ManifestArtifact');
171+
const imageArtifact = new Artifact("ImageArtifact");
172+
const manifestArtifact = new Artifact("ManifestArtifact");
160173

161-
const pushImageProject = new PushImageProject(this, 'PushImageProject', {
174+
const pushImageProject = new PushImageProject(this, "PushImageProject", {
162175
imageRepository,
163176
taskDefinition,
164177
});
165178

166179
const buildAction = new CodeBuildAction({
167-
actionName: 'PushImage',
180+
actionName: "PushImage",
168181
project: pushImageProject,
169182
input: sourceArtifact,
170183
outputs: [imageArtifact, manifestArtifact],
171184
});
172185

173186
const deployAction = new CodeDeployEcsDeployAction({
174-
actionName: 'CodeDeploy',
187+
actionName: "CodeDeploy",
175188
taskDefinitionTemplateInput: manifestArtifact,
176189
appSpecTemplateInput: manifestArtifact,
177190
containerImageInputs: [
178191
{
179192
input: imageArtifact,
180-
taskDefinitionPlaceholder: 'IMAGE1_NAME',
193+
taskDefinitionPlaceholder: "IMAGE1_NAME",
181194
},
182195
],
183196
deploymentGroup,
184197
});
185198

186-
new Pipeline(this, 'Pipeline', {
187-
pipelineName: 'blue-green-pipeline',
199+
new Pipeline(this, "Pipeline", {
200+
pipelineName: "blue-green-pipeline",
188201
stages: [
189202
{
190-
stageName: 'Source',
203+
stageName: "Source",
191204
actions: [sourceAction],
192205
},
193206
{
194-
stageName: 'Build',
207+
stageName: "Build",
195208
actions: [buildAction],
196209
},
197210
{
198-
stageName: 'Deploy',
211+
stageName: "Deploy",
199212
actions: [deployAction],
200213
},
201214
],

0 commit comments

Comments
 (0)