Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: CC-BY-SA-4.0
In this lab you will update our container image and then deploy in a Blue / Green fashion.
Before you can do that, you will delete the service we just deployed. Using the AWS console navigate to the ECS console select the cluster for the workshop.
In your Cloud9 editor, open the file /configs/docker_build_base.yml.
Change the following Before:
- docker build -t $project_name:$tag .
- docker tag $project_name:$tag $ecr:$tag
- docker push $ecr
After:
- docker build -t $project_name:$IMAGE_TAG .
- docker tag $project_name:$IMAGE_TAG $ecr:$IMAGE_TAG
- docker push $ecr
These changes will modify the tag which the container is tagged with in your ECR repository. The new tag will be the GUID of the build which produced the image. You can use this GUID to track back which code build action actually built the container.
open /app/index.html and add some text to the body of the html document to visualize changes made.
Push the changes to git
git add .
git commit -m "Update pipeline to tag container with build number"
git push origin master
There are a few files which are needed for the next process.
These files currently exist in the /configs directory. Also in this directory we have a python script produce-configs.py.
Once your previous push has completed and is built.
This script will produce the correct configs needed for the deployment. This script will query the previous environment we deploy to populate variables.
You will need to pass in the most currently docker image tag.
cd ~/environment/fargate-dev-workshop/configs/
python produce-configs.py fargate-dev-workshop test <AWS_ACC_NUMBER>dkr.ecr.<aws region>.amazonaws.com/fargate-dev-workshop:<gui>
Once we have created the necessary config files we can begin to create our new service.
aws ecs register-task-definition --cli-input-json file://./task-definition-test.json
aws ecs create-service --region --service-name fargate-dev-workshop-test --cli-input-json file://./service-definition-test.json
aws deploy create-application --region $AWS_REGION --application-name fargate-dev-workshop-test --compute-platform ECS
aws deploy create-deployment-group --region $AWS_REGION \
--deployment-group-name ecs-fargate-workshop-test-dg --cli-input-json file://./deployment-group-test.json
aws ecs deploy --region $AWS_REGION --service 'fargate-dev-workshop-test' \
--cluster 'fargate-dev-workshop-test' --codedeploy-application 'fargate-dev-workshop-test' \
--codedeploy-deployment-group 'ecs-fargate-workshop-test-dg' \
--task-definition task-definition-test.json --codedeploy-appspec appsectest.json
You will now be able to monitor your deployment in the AWS Code Deploy Console.
In this lab we ran the steps which may be ran as part of a CI/CD pipeline to deploy the updated container. Using modern deployment techniques (Canary, Blue / Green) in also assist in ensuring in the reduction of errors occurring in a production deployment.