Vickey Sandhu
4 min readApr 10, 2021

--

Deploy the Java-based application using Jenkins with DSL, Ansible Docker.

Task: Description
Create the Docker file to launch the image and deploy the application inside the container.
1. Design the Docker file which is used to launch the container.
2. Use Jenkin to Deploy the container in the respective node.
3. Use ansible to pull the image from the docker registry and launch the container using ansible.

Here are the steps to performs the task.
1. Write a docker file, You can use the directly JBoss image to launch the container, but this is my first time to work on the task assigned by Vimal Daga sir. So i have used the centos image to launch the container.
Using FROM keyword it will pull the image from the docker registry, Then I have defined the ADD keyword which is used to download the image and extract it in the root directory.
ENV is used to set the environment variable. ENTRY POINT is used to launch the JBoss application on the respective node

2. Create the seed job inside the Jenkins, The seed job is a Jenkins job that runs a DSL script, and then generates a new job. The seed job is a normal freestyle Jenkins job that you add the “Process Job DSL” build step. This step takes the DSL and generates the configured jobs. Basically, a seed job is a helper which is used to launch the new job. In my case, I have defined the seed job project name as Jenkins seed job and the things which are created from the seed job that is JBOSS_Deployment.

If you want to write the seed jobs, You need the Jenkins plugin i.e DSL. You can search the DSL plugins under manage Jenkins, Now create a frees style project and name which you want and you can define the DSL jobs under the build section that is processed DSL jobs.

In my case I have used two-node, one is ansible and another one is used to pull the image from the docker registry. You can also run on the same machine where Ansible is installed. but I have used another node, that ansible runs the playbook from the ansible node and launch the container in another node. Make sure you have performed the password-less authentication and also you need to tell the jenking the password of the respective node.
I am able to execute the jobs in the third node due to passwordless authentication, due to that ansible able to execute the job in the third node.
Please find the screenshot for the reference.

Also, you have to install ansible and docker on one m/c and another m/c you need to install the docker. Here are the DSL jobs which I have defined. During executing the seed job, it will automatically launch the container in the respective node.
Issue:- I am getting one issue during executing the jobs, i.e I am getting the timeout issue during running the job because i am going to deploying the image, installing the java on the centos machine and then deploying the file using the Docker file. I have defined the timeout in DSL jobs i,e 30minute. The timeout defines in miliseconds.

3. Here is the Ansible role. I have designed the simple playbook which is used to launch the container. I have defined the simple playbook which plays a simple role to launch the docker container.

Screenshot for the Success results. You can also launch the container directly by using the above command which showing in the ansible file.

You can find the DSL file, war and Docker file which I have used.
https://github.com/Vijay62020/jboss-task/
→ Docker IMAGE:- vijay62020/jbossfuse
Guys, here we come to the end of this blog I hope you all like it and found it informative.

--

--