Part of this article lets see how we can create a continuous integration and delivery pipeline (CI/CD) for applications deployed outside AWS cloud using ECS-anywhere. We will use CodeCommit
, CodeBuild
and CodePipeline
along with AWS ECR
to build this pipeline.
Here is the high level view of the pipeline, that we will build in this particle
Notes:
Here are the sequence of events:
- Developer makes the required changes and checks in the code available in
AWS CodeCommit
- AWS will automatically trigger the code pipeline that's listening to the git branch
- Part of this step,
AWS CodeBuild
will download the source, build the artifacts, create a docker image for the application, and push the artifacts toAWS ECR
AWS CodeBuild
takes care of the following part of this step:- Creates a new revision of ECS task definition with the updated docker image tag
- Updates the underlying ECS service with the new task definition
- Stops all the running tasks, so ECS service can re-provision the ECS tasks with the latest version of the application
- Setup the environment variables required to build ECS-anywhere cluster and run workloads using the newly created cluster.
Note: Change the name of the CLUSTER_NAME and SERVICE_NAME if desired, for running multiple tests.
export AWS_DEFAULT_REGION=us-east-1
export ROLE_NAME=ecsMithrilRole
export CLUSTER_NAME=test-ecs-anywhere
export SERVICE_NAME=test-ecs-anywhere-svc
Note: Change the value of AWS_DEFAULT_REGION to match the default AWS region.
- ECS cluster is up and running
- Vagrant VM is connected to ECS control plane and has the required network connectivity to access AWS cloud
Run the following command from root directory to create the required AWS artifacts and the sample application
chmod +x *.sh
cd workload-management/cicd-deploy
./setup.sh
The above shell script takes care of creating the following artifacts and deploying the sample application using ECS-anywhere
- Creates a
AWS ECR
repository to host the docker image for the sample application - Creates a
AWS CodeCommit
repository to host the source code for the sample application - Creates two
AWS CodeBuild
projects (one to package the application and another to update the deployed application with the latest version) - Creates a
AWS CodePipeline
listening to the changes to themaster
branch in the code repository - Creates a
ECS Task
andECS Service
definition to deploy the sample application withEXTERNAL
launch-type - Creates all the required IAM roles & policies
Note: Deploying this sample application will take sometime, so wait for couple of minutes before proceeding to next step
Here are some screenshots of the AWS artifact created by the shell script
-
Open the browser and navigate to
http://localhost:8080
. We should see the below screenshot that shows the sample application is deployed. -
Navigate to CodePipeline page in AWS Console, you should see the code pipeline running. Part of the Deploy stage ECS task will be deployed to AWS ECS, so wait for couple of seconds after a successful execution of this stage before proceeding to next step.
-
We will make a small change to
index.html
and check-in the updated files toAWS CodeCommit
. Navigate to gitrepo directory by running the following command:cd app/gitrepo
Open
index.html
in your favorite text editor and update the text fromHello world from ECS Anywhere!
toNew Hello world from ECS Anywhere!
. Save the file and run the following commands to push the changes back toAWS CodeCommit
git add . git commit -m "Check in with new changes" git push cd ../..
EcsAnywhereCiCdPipeline
(AWS CodePipeline) will get automatically triggered (like below) and this will take care of building the application and deploying the changesNote: Deploying the updated application will take sometime, so wait for couple of minutes before proceeding to next step. Use AWS console to check the status of the build and deploymen
-
Open the browser and navigate to this
http://localhost:8080
. We should see the below screenshot that shows the latest changes are successfully deployed
Run the following command to delete all the AWS resources created for this article
./cleanup.sh
cd ../..
This workload demostrates how easy is it to setup a CI/CD pipeline for applications running outside AWS cloud deployed using ECS-anywhere with the same set of fimilar tools.