6-part series - (6) Create a CodePipeline to see the changes that you made to the index.html file auto-populated
Revathi Joshi
Posted on February 18, 2023
In this 6-part series on configuring a CI/CD pipeline using Customized Docker image on an Apache Web Server, Application Load Balancer, ECS, ECR, CodeCommit, CodeBuild, CodeDeply services -
In the 6th article, We will create a CodePipeline to see the changes that you made to the index.html file autopopulated
1st article
- As a reference, please read my 1st article - 6-part series - (1) Deploy a Custom Docker Image with Centos on an Apache web server and Save it to AWS ECR Repository
2nd article
- As a reference, please read my 2nd article - 6-part series - (2) Create Task Definition in ECS and Application Load balancer for the Task to be run on Fargate Cluster
3rd article
- As a reference, please read my 3rd article - 6-part series - (3) Create Fargate Cluster, and a Service which can access customized Docker image
4th article
- As a reference, please read my 4th article - 6-part series - (4) Create, clone a CodeCommit Repo, move-push the Dockerfile and index.html to remote repository master branch
5th article
- As a reference, please read my 5th article - 6-part series - (5) Create a CodeBuild Project, upload the code and push it to the master repository
Let’s get started!
Please visit my GitHub Repository for CI-CD/Docker/ECS/ECR articles on various topics being updated on constant basis.
Objectives:
1. Create a CodePipeline
2. Add S3 policy to the role created by Codepipeline
3. Go to the CodePipeline, modify the Deploy stage
4. Test the Pipeline
5. Add, commit and push the file index.html to the remote repository’s master branch
6. Delete all the following services.
Pre-requisites:
- AWS user account with admin access, not a root account.
- AWS CLI.
Resources Used:
Steps for implementation to this project
1. Create a CodePipeline
on CodePipeline under Developer Tools, Pipelines, Create pipeline, my_codepipeline, Next
1. Add Source stage
Source provider : Choose AWS CodeCommit, Repository name : my-codecommit-repo, Branch name : master, default, Next
2. Add build stage
Build provider : Choose AWS CodeBuild, Region : Default (US East N.Virginia), Project name : Choose my_codebuild_project, default, Next
3. Add deploy stage
Deploy provider : Choose Amazon ECS, Cluster name : my_cluster, Service name : Choose my_service, Image definitions file : Enter imagedefinitions.json, Next
- Create Pipeline.
Source - AWS CodeCommit succeeded
Build - AWS CodeBuild succeeded
Deploy - AWS CodeDeploy failed
- Failed - Due to insufficient permissions as the created role does not have S3 permissions
- Add S3 policy to the role created by Codepipeline.
2. Add S3 policy to the role created by Codepipeline
On the IAM console, Roles, search and click for the role starting with AWSCodePipelineServiceRole-us-east-1-my-codepipeline which was created with the codepipeline, On the Permissions tab, Add permissions, Attach policies, Search and select AmazonS3FullAccess, Attach policies
3. Go to the CodePipeline, modify the Deploy stage
my-codepipeline, Edit in the Pipeline, edit the Deploy stage
Click on the Edit symbol.
In the Input artifacts, choose SourceArtifact, Done, Save and Save, Now click on Release change, Release
you can see that the pipeline restarts execution and it works now
4. Test the Pipeline
-
On to the EC2 instance terminal
sudo su
cd /opt/docker/my-codecommit-repo
the index.html file
- vi index.html, add the following code, save the file
<!doctype html>
<html>
<head>
<title>Codepipeline Project</title>
</head>
<body>
<h1>This is my Codepipeline with ECR, ECS, CodeCommit, CodeBuild and CodePipeline! </h1>
</body>
</html>
5. Add, commit and push the file index.html to the remote repository’s master branch
git add .
git status
git commit -m "changing index.html File"
git push
Wait for 4-5 minutes till all the execution stages are Successful.
Now, copy the load balancer DNS and paste it in a browser tab to check the changes done you made in the index.html file.
We have successfully deployed the CI/CD Pipeline for ECR, ECS, CodeCommit and CodeBuild
6. Delete all the following services
EC2 Instance
Application Load Balancer
Target Groups
ECR Repository
ECS Cluster
ECS Task Definitions
CodeCommit Repository - Desired tasks to 0
CodeBuild Project
CodePipeline
S3 Bucket
What we have done so far
- We have successfully deployed the CI/CD Pipeline for ECR, ECS, CodeCommit and CodeBuild
Posted on February 18, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.