Simple CICD setup

IMPLEMENTING SIMPLE CICD PIPELINE

Prerequisites:

  1. Install MobaXterm.
  2. Create GitHub account. (Go to GitHub > Sign in by providing your details)
  3. Install latest version of Java.
    Open MobaXterm>Start a session>login using credentials>

sudo apt install openjdk-8-jdk

confirm installation using # java -version.

VM1:

1.Initialise the git local repository using “git init”.
2.Install Jenkins and start & enable it.

sudo apt-get update

wget -q -o – url | sudo apt-key add –

echo deb url binary/ | sudo tee/etc/apt/sources.list.d/jenkins.list

sudo apt-get install jenkins

sudo systemctl start Jenkins

sudo systemctl status jenkins

3.Install Maven & Git plugins and configure

wget url

mvn -version

Login to Jenkins console, install maven & git plugins.
Manage Jenkins > manage plugins > available > Maven Invoker
Manage Jenkins > manage plugins > available > github
Set maven & git path
Manage Jenkins > Global tool configurations > add maven
Manage Jenkins > global tool configuration > add Github
4. Need to create a slave node in Jenkins.
Jenkins > manage Jenkins > manage nodes > new node > name: slave 1, enable permanent > save.
Credentails > global credentials > private key from terminal > save.
5.Need install docker and start the services.

sudo apt-get update

sudo apt install docker

docker - - version

sudo systemctl start docker

sudo docker hello-world

6.Write a docker file to pull the base image.
FROM ubuntu:12.04

MAINTAINER Valaxy Technologies [email protected]


LABEL version="1.1.0" \
      app_name="Training registration application" \
	  release_date="9-Sep-2018"
RUN apt-get update && apt-get install -y apache2 && apt-get clean


ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2


EXPOSE 80


COPY index.html /var/www/html
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

7.Login to Jenkins and add docker serer to execute commands from Jenkins.
Manage Jenkins>configure system>publish over ssh>add docker server and credentials.
8.In post build > send files or execute commands over ssh > name : docker-host, source code: /webapp/target/*.war/ > remove prefix:webapp/target > remote directory:/opt/docker >
9.And add another post build action to create images and containers in docker > name:docker-host > exec command : docker run -d - - name valaxy_demo -p 8090:8080 valaxy_demo.
10.Now build the job in Jenkins and it will create a image & container on docker.

VM2:

1.To install ansible initially we need to install python latest version.

sudo apt-get install python3

python --version

2.After installation we need to create a user by going into root user. Assign credentials for that user.

sudo su

sudo add user

sudo passwd username

3.Then switch to user and install ansible.

sudo install ansible

ansible –version

vi sudo (add password of the user)

4.Goto Jenkins console > manage Jenkins > manage plugins > available > public over ssh > install.

5.Write a playbook to copy jar/war on to tomcat.

hosts : web-servers
become : true
tasks:

  • name: copy war onto tomcat server
    copy:
    src:
    dest:
    6.Goto Jenkins console > project > configure > publish ssh > ssh server > name: ansible
    7.Post builds setup > send files/execute commands over ssh > save.
    8.Now build the project in Jenkins and it will update webapp directory in ansible and tomcat.
    Install Nexus

    sudo wget url

tar -zxvf nexus-3.0.2-02.unix.tar.gz

mv /opt/nexus-3.0.2-02 /opt/nexus

sudo add user nexus

vi sudo \ nexus all=(all) NoPASSWD: ALL

sudo service nexus start

Login to nexus using :8081
Default credentials: username : admin, passwd: admin123

Install sonarqube & sonar scanner.

sudo install mysql

sudo wget url

Mv /opt/sonarqube-6.0 /opt/sonar
1.Download sonar scanner plugins and update properties in Jenkins server.
Jenkins console > manage Jenkins > manage plugins > sonarqube scanner > install.
2.Got to manage Jenkins > Global tool configuration > sonar qube server > name:sonar_scanner, set Sonar_runner_Home path.
3.Create a job to set sonarqube and provide sonar properties in build.
Jenkins console > new job > sonar project > build > execute sonarqube scanner > save > build
4.Execute the job to get the report, use :9000/sonar.

VM3:

1.Install Tomcat Server.

wget url

tar -zxvf apache-tomcat-8.5.31.tar.gz

cd /bin

./startup.sh

#Project Plan:

image

#VM Requirements:

VM-1: For Git,Jenkins,Docker
OS: ubuntu
RAM: 2GB

VM-2: For Ansible and Nexus
OS: ubuntu
RAM: 2GB

VM-3: For Webserver
OS: ubuntu
RAM: 2GB