|
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 |
0 commit comments