Deploy Java Web App Using CI/CD tools on AWS

CI-CD-TomcatApp-Architecture

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 :

  • CodePipeline
  • CodeDeploy
  • CodeBuild
  • CodeCommit/Github
  • S3

By following this article you will accomplish a task which will help you setup a CI/CD pipeline manually on AWS.

Overview 

  1. Fork existing source code repository that will be used while creating pipeline
  2. Create a CodeBuild project to build tomcat app
  3. Launch an EC2 instance with CodeDeploy agent installed
  4. Create a CodeDeploy application to deploy Tomcat application upon
  5. 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
 1-forkrepo

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.

2-CreateCB-Project-1

2-CreateCB-Project-2

2-CreateCB-Project-3

2-CreateCB-Project-4

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:

  1. Create EC2 instance
  2. Install code deploy agent
  3. Create Role for CodeDeploy and EC2 Instance
  4. 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

 3-CreateCDApp-1 

In Environment Configurations select the EC2 instance which was launched by the cloudfromation template in step 2.

3-CreateCDApp-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**

3-CreateCDApp-3

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.

4-Ec2template-1

Choose Build provider as CodeBuild and Select existing project which you made in step 2.

4-Ec2template-2

Select Deployment provider as CodeDeploy with the application name you created in step 4.

4-Ec2template-3

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.

4-Ec2template-4

 

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 :

5-CodePipeline

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.

6-AppLive

That’s it!

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 mail@bhargavamin.com for any queries. thanks!

 

 

 

Blogger & Assc Cloud Architect

Site Footer