Friday, November 3, 2017

Installation of Apache Ant 1.10.x and docker-ce 17.x on CentOS7 Jenkins Master and Slaves

Installation of Apache Ant 1.10.x and docker-ce 17.x on CentOS7 Jenkins Master and Slaves 



This Requires that JRE is installed. Please note that the Ant 1.1o.x requires that JRE 1.8 to be installed. 

This will ensure that the Jenkins master identically have the Docker and the Ant installations so that the builds that need ant and docker can be identically run from the Jenkins master as well as Jenkins Slave servers.

Sources:


  • Also JAVA_HOME is to be set to the path where JRE is installed.
  • Latest versions of Apache ant are available from http://ant.apache.org/bindownload.cgi
  • Ant 1.10.x requires the Java8 JRE.
  • we have installed the Java8 from oracle for Linux as we are running these on the CentOS 7 server.


Please note that this is an RPM based installed of 64 Bit 1.8.0 update 152 from here



[root@jenkinsmaster ~]# which java
/usr/bin/java


[root@jenkinsmaster ~]# java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)



Installation of Ant 1.10.x


Download the ANT binaries 

wget http://redrockdigimark.com/apachemirror/ant/binaries/apache-ant-1.10.1-bin.tar.gz


Extract the Binaries to a folder, here the same is extracted into /opt

tar zxvf apache-ant-1.10.1-bin.tar.gz -C /opt


See the extracted folder

[root@jenkinsmaster apache-ant-1.10.1]# ls -la /opt
total 8
drwxr-xr-x.  3 root root   30 Nov  2 16:15 .
dr-xr-xr-x. 17 root root 4096 Oct 15 22:55 ..
drwxr-xr-x   6 root root 4096 Feb  2  2017 apache-ant-1.10.1
[root@jenkinsmaster apache-ant-1.10.1]#

This is optional if the ANT_HOME and PATH as shown below are set. This creates the soft link for the ant command in the extracted files to the /usr/bin/ant

[root@jenkinsmaster bin]# ln -s /opt/apache-ant-1.10.1/bin/ant /usr/bin/ant

Run ant command without any option to ensure that ant command runs properly 



[root@jenkinsmaster bin]# ant
Buildfile: build.xml does not exist!
Build failed
[root@jenkinsmaster bin]#


See the version of ant installed


[root@jenkinsmaster bin]# ant -version
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
[root@jenkinsmaster bin]#



Append these lines to the /etc/profile or BASH Profile or BASHRC  to set the ANT and JAVA environment variables



Here we had added these lines to the /etc/profile

export ANT_HOME=/opt/apache-ant-1.10.1
export PATH=$PATH:$ANT_HOME/bin
export JAVA_HOME=/usr/java/jdk1.8.0_152
export PATH=$PATH:$JAVA_HOME/bin


Ensure that these are working 

Environment Variables for JAVA_HOME, ANT_HOME, PATH


[root@jekninss1 ~]# env | grep -i -e ant -e java -e path
ANT_HOME=/opt/apache-ant-1.10.1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/apache-an -1.10.1/bin:/usr/java/jdk1.8.0_152/bin
JAVA_HOME=/usr/java/jdk1.8.0_152


Version of Apache ant installed


[root@jekninss1 ~]# ant -version
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
[root@jekninss1 ~]#


version of Java JRE installed 


[root@jekninss1 ~]# java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
[root@jekninss1 ~]#

Follow the same instruction to setup Apache ant on the Jenkins slave also. This is to ensure that if ant can be run in the same manner out of Jenkins master or Jenkins Slave


Installation of Docker on the Jenkins Master server and the Jenkins Slave servers


Add the Docker CE Repo 


Reference: 


yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo


[root@jenkinsmaster yum.repos.d]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@jenkinsmaster yum.repos.d]#

Ensure that the docker repository shows up in the repolist


[root@jenkinsmaster yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
docker-ce-stable                                         | 2.9 kB     00:00
docker-ce-stable/x86_64/primary_db                         | 9.3 kB   00:07
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: mirror2.totbb.net
 * extras: mirror.nbrc.ac.in
 * jpackage-generic: mirrors.dotsrc.org
 * jpackage-generic-updates: mirrors.dotsrc.org
 * updates: mirror.nbrc.ac.in
repo id                     repo name                                     status
base/7/x86_64               CentOS-7 - Base                                9,591
docker-ce-stable/x86_64     Docker CE Stable - x86_64                         10
*epel/x86_64                Extra Packages for Enterprise Linux 7 - x86_6 12,042
extras/7/x86_64             CentOS-7 - Extras                                280
jpackage-generic            JPackage (free), generic                       3,307
jpackage-generic-updates    JPackage (free), generic                          29
updates/7/x86_64            CentOS-7 - Updates                             1,052

[root@jenkinsmaster yum.repos.d]#

Install docker-ce


yum installation of docker-ce

yum -y install docker-ce


Enable the docker service

systemctl enable docker

[root@jenkinsmaster ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Start the docker service 

systemctl start docker


Ensure that docker is setup properly 

docker run 'hello-world'

This pulls the docker image of 'hello-world' and then runs 

[root@jenkinsmaster ~]# docker run 'hello-world'
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
5b0f327be733: Pull complete
Digest: sha256:175735360662078abd70dacb73c5518d5b3ae7c1ed069d22def5da57c3e917d6
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

[root@jenkinsmaster ~]#

Complete the same steps on the Jenkins Slave server(s) also.