In this article is a step-by-step guide on how-to deploy Tomcat App using CI/CD tools on AWS.
CI/CD (Continous Integration and Continous Delivery) is a DevOps practice which is used to increase velocity software delivery process. It focuses on automating manual tasks that are required to perform during a release cycle.
This article focuses on how to setup a CI/CD pipeline on AWS using their own services like :
By following this article you will accomplish a task which will help you setup a CI/CD pipeline manually on AWS.
- Fork existing source code repository that will be used while creating pipeline
- Create a CodeBuild project to build tomcat app
- Launch an EC2 instance with CodeDeploy agent installed
- Create a CodeDeploy application to deploy Tomcat application upon
- Create a CodePipeline by orchestrating all the services together
Getting started, pre-requisites:
- AWS account
- Switch to N.Virginia region
- Github account to fork source code for Tomcat application. You can use CodeCommit repo if you have one.
Step 1: Fork GitHub repository
Fork following GitHub repo to fetch tomcat app code:
Go to > https://github.com/bhargavamin/devops-techtalk
Select option to fork the same repo to personal account which will be used later in CodePipeline
Alternatively, you can use your own from personal repo also. If you plan to use CodeCommit then you’ll have to Migrate forked repo to CodeCommit.
Step 2: Create A CodeBuild Project
This project will consist of all the configuration required to build java application.
Go-to CodeBuild and create a project with following configurations:
Connect your github account and select the forked git repo.
Note: Leave Advanced Settings as it is.
Once you have configured everything and saved the build, your next step will be to create a CodeDeploy deployment group.
Step 3: Provision Ec2 instance for Deployment
To make this part quick there is a cloudformation template named “ec2-instance.yml” already written in git repo which will do following tasks:
- Create EC2 instance
- Install code deploy agent
- Create Role for CodeDeploy and EC2 Instance
- Attach Role to EC2 instance
Upload the same template to cloudformation and once it is created successfully moved to next step.
Note: Deploy cloudformation template in N.Virginia region
Step 4: Create a CodeDeploy Application
Goto CodeDeploy > create application with following configurations
In Environment Configurations select the EC2 instance which was launched by the cloudfromation template in step 2.
In Deployment configuration, keep everything default. In Service role ARN, select the role which was created by the cloudformation template in the previous step.
**Usually, the Role named includes CodeDeployRole word in it with cloudformation stack name**
If everything is configured as stated, create an application and move onto the last step which is to create a CodePipeline.
Step 5: Create CodePipline
This is the final step where everything comes together as a single pipeline.
Goto CodePipeline > create pipeline with following configurations :
Choose GitHub as source repo, connect the GitHub account and select the forked repo.
Choose Build provider as CodeBuild and Select existing project which you made in step 2.
Select Deployment provider as CodeDeploy with the application name you created in step 4.
Click on Create role button it will automatically redirect you and create a role for you. Once role is created its name will automatically appear in textbox and then you can move to next step.
Last, review the configurations and create a pipeline. That’s it you’ve successfully created pipeline which will now deploy JAVA application on EC2 instance.
Once pipeline finish executing the process it should look something like this :
If all the steps have succeeded that means the app was deployed successfully which you can check by typing IP address on EC2 instance in the browser.
If any of stage fails in CodePipeline you can check the reason for it by going onto respective service and troubleshoot it. Once the issue is resolved rerun the whole pipeline again.
I hope this help!
Feel free to reach out at email@example.com for any queries. thanks!