- General Info
- Technologies
- Setup
- Process -CI/CD pipeline
- Screenshot
The purpose of this project is to deploy a simple WAR file on Tomcat server which runs on Docker conatiners using Continuous Integration and Continuous Deployment. The source code to build the WAR file comes from Github, Jenkins pulls the code from Git and build the WAR file using MAVEN tools. After building the file, the artifact will be tested and pushed to remote server for deployment. On the remote server, we will have to write Dockerfile and Docker-compose file to run Tomcat server. Using a bash script, the copied artifact WAR file will be deploy onto Docker container where Tomcat server is running, this can be seen from web browser.
- Bash Scripting
- Github
- Maven
- Jenkins
- Docker
As per the aim of this project, we need 2 VM instances, here we are using AWS EC2 instances,
- Jenkins server
- Remote server for deployment
First thing, we need to install Jenkins for Continuous Integration and Continuous Deployment. To setup Jenkins please refer my Jenkins installation guide on here similarly, we will need Maven to build a WAR file from Github source code.
#goto https://maven.apache.org/download.cgi
cd /opt
sudo wget https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
#Extract tar
sudo mkdir maven && sudo tar -xvzf apache-maven-3.8.5-bin.tar.gz -C maven
For maven we need to set up PATH for two varibales M2_HOME & M2. M2_HOME should refer to /opt/maven and M2 should refer to /opt/maven/bin
vi ~/.profile
#add these lines
M2=/opt/maven/bin
M2_HOME=/opt/maven
#update PATH
PATH=$PATH:$M2:$M2_HOME
#save the file
-
install "Maven Invoker" plugin
-
goto "Manage Jenkins" --> Global Tool Configuration --> Add Maven Installation
-
Under Name "M2_HOME" and Maven Home is the path /opt/maven
To install docker and docker compose please refer my guide here
After installation, we will have to write Dockerfile to build docker image based on the apache tomcat server and write docker-compose yaml file to initiate docker container.
-
Dockerfile -please refer to my Dockerfile here
Base from tomcat server, however the latest version have two directories "webapps" & "webapps.dist", by deafult tomcat run files from "webapps", but in the latest version default files are loacted in "webapps.dist", so we will have to move the files from "webapps.dist" to "webapps"
-
Docker-compose.yml file - please refer here
-
Bash script for deployment - please refer here
This script will build the Docker image from docker-compose.yml and copy the artifact WAR file to Docker tomcat image.
In order to automate the whole CI/CD environment, we will have to establish the connections between servers Since we are going to connect to our remote server, we will have to install “SSH-Agent” plugin and make the connection, please refer my guide to Jenkins connections repo
Plan is to build Jenkins CI/CD pipeline with environmental variables, here we are going to pass the AWS IP as “secret text”, AWS IP = AWS_IP Since we are going to build WAR file from JAVA source code, we will need "tools" - here "maven"
tools {
maven "M2_HOME"
}
CI/CD Stages refer here
git branch: 'main', url: 'https://github.com/InverseInfinity/tomcat_test.git'
sh "mvn -Dmaven.test.failure.ignore=true clean package"
scp /var/lib/jenkins/workspace/tomcat_pipline/webapp/target/*.war ec2-user@$AWS_IP:~/
ssh ec2-user@$AWS_IP "cd /home/ec2-user && /home/ec2-user/deploy.sh"
Since we need to automate the process, that is whenever there is a change in the source code, Jenkins should trigger and run the pipeline, so we can see the change on the deployment.