Till now we have
- launched EC2 instance
- connected it via MobaXterm
- installed CodeDeploy-Agent on it
- Attached IAM Role to the instance.
If you want to visit Part 1 of this Blog, you can click here.
In this blog, we will create
- a Code Build Project
- Code Deploy Application
- Code Pipeline.
Let’s continue with our exercise.
- create Code Build Project
Under Environment type, select the following:
Rest of the features, keep them as default and create Code Build Project.
To build the project, Code Build looks for the buildspec.yml file at your source (GitHub) root location.
A sample buildspec.yml for a website running on nginx would look like this:
5. Create Code Deploy Application.
Navigate to Code Deploy Console, Click on Create an application
Next, create a Deployment group.
Enter the Deployment group name, create an IAM role for Code Deploy
And assign the following policies.
I have created a “RoleforcodeDeployEC2” role, with the following policies.
The attached policies are:
- AmazonEC2FullAccess
- AmazonEC2RoleforAWSCodeDeploy
- AmazonS3FullAccess
- AWSCodeDeployFullAccess
- AWSCodeDeployRole
- AmazonEC2RoleforAWSCodeDeployLimited
The Key and Value correspond to the values of the EC2 instance launched.
And disable the Load balancer part, as we will not be using the Load balancer.
Proceed to create a Deployment group.
Code Deploy looks for the appspec.yml file for continuous deployment.
Contents of appspec.yml :
Install_nginx.sh :
start_nginx.sh
6. Create Code Pipeline.
Keep the other settings default. Proceed to Next
Source provider: GitHub (Version 2).
Next, you need to connect to your GitHub account. For that Click on Connect GitHub
Provide the Connection Name and click on “Connect to GitHub”
Click on “Install an app”
Provide GitHub credentials
Select the Repo you want to connect to Code Pipeline and hit connect.
Select the Repo and Branch
Keep the setting as shown in the below image
Proceed to next.
We will be using Code Build to build our sample app.
If you do not have Code Build project created, please create a new Code Build Project
Proceed to Next
I have already created Code Deploy application, if you do not have it please create a new Code Deploy Application
Proceed to Next and create Pipeline
Below is the webpage deployed on Instance
Once there is any activity like merge, push, commit, etc on the GitHub branch we connected in Code Pipeline, the Pipeline will get triggered and we will get the changes in the webpage on the instance.
The changes are made in GitHub with the below comments
Once all the 3 stages are executed successfully, we will get changes on the webpage hosted by our EC2 instance.
We have successfully deployed our webpage on the EC2 instance with an automated procedure using a code pipeline.