Skip to content

Commit 7047a5c

Browse files
committed
ECS blue-green deployment
1 parent abca082 commit 7047a5c

12 files changed

+9827
-2
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out
9+
10+
# Parcel build directories
11+
.cache
12+
.build
13+

README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,60 @@
1-
# ecs-codepipeline-demo
2-
CI/CD demo using ECS
1+
# ECS blue/ green deployment
2+
3+
We will deploy a demo application on ECS Fargate and update the application using Blue/Green deployment capability of CodeDeploy and ECS
4+
5+
## Build and deploy the stack
6+
7+
* Install dependencies - `npm install`
8+
* Build the project - `npm run build`
9+
* Bootstrap CDK - `cdk bootstrap`
10+
* Synthesize the output - `cdk synth`
11+
* Review the proposed build - `cdk diff`
12+
* Deploy the CDK stack - `cdk deploy --require-approval never`
13+
14+
## Testing the Blue/Green Deployment
15+
16+
* Access the deployed version of the application using the output value of `BlueGreenUsingEcsStack.ecsBlueGreenLBDns`
17+
* This is the **Blue Deployment** live on Port **80**. The demo application will have a blue background
18+
* Push code to the code-commit repository
19+
* Open a new terminal session and export the temporary credentials for your AWS account
20+
* We will push the demo application code to a CodeCommit repository created by the above stack
21+
* Clone the reference GitHub repository
22+
```
23+
git clone https://github.com/smuralee/nginx-example.git
24+
```
25+
* Change the remote origin to the CodeCommit repository. We fetch the `demo-app` repository URL
26+
```
27+
cd nginx-example
28+
git remote set-url origin $(aws codecommit get-repository --repository-name demo-app | jq -r '.repositoryMetadata.cloneUrlHttp')
29+
```
30+
* Verify the remote origin url is pointing to the CodeCommit repository
31+
```
32+
git remote -v
33+
```
34+
* Edit the `index.html`. We change the `background-color` to `green`
35+
```html
36+
<head>
37+
<title>Demo Application</title>
38+
</head>
39+
<body style="background-color: green;">
40+
<h1 style="color: white; text-align: center;">
41+
Demo application - hosted with ECS
42+
</h1>
43+
</body>
44+
45+
```
46+
* Push the code to the CodeCommit repository
47+
```
48+
git add .
49+
git commit -m "Changed the background to green"
50+
git push
51+
```
52+
* This will trigger the Blue/Green deployment for the ECS application
53+
* The **Blue Deployment** is live on Port **80**
54+
* You can test the **Green Deployment** on port **8080**
55+
* Once the deployment is complete demo application with green background is visible
56+
57+
## Cleanup
58+
59+
* Delete the stack - `cdk destroy -f`
60+
* You will need to manually delete the S3 bucket and ECR repository since they are not empty

bin/blue-green-using-ecs.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from '@aws-cdk/core';
4+
import {BlueGreenUsingEcsStack} from "../lib/blue-green-using-ecs-stack";
5+
6+
const app = new cdk.App();
7+
new BlueGreenUsingEcsStack(app, 'BlueGreenUsingEcsStack');

cdk.context.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"@aws-cdk/core:enableStackNameDuplicates": "true",
3+
"aws-cdk:enableDiffNoFail": "true",
4+
"codeCommitRepoForAPIs": "backend-services"
5+
}

cdk.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"app": "npx ts-node bin/blue-green-using-ecs.ts"
3+
}

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
roots: ['<rootDir>/test'],
3+
testMatch: ['**/*.test.ts'],
4+
transform: {
5+
'^.+\\.tsx?$': 'ts-jest'
6+
}
7+
};

0 commit comments

Comments
 (0)