📜 ⬆️ ⬇️

Using Docker Containers as Jenkins Nod

This article describes the use of docker containers as separate nodes for a continuous integration system, in this case jenkins. Too lazy to read tl; dr
To build our project in RPM and DEB packages we use Jenkins, for which a special machine is allocated.

At first, we collected our project only for CentOS 6. Then CentOS 5 support was added, and it turned out that depending on specific versions of libraries do not allow the same binaries to work under different versions of CentOS, we needed to build different RPMs. This was decided by adding nodes to the jenkins with CentOS 5, which was served by the VirtualBox virtual box. Then added support for Suse, and then Debian.

The amount of RAM is not rubber, and using virtual machines only for building is an obvious overhead, and it was decided to rewrite the scripts using Docker .


Using Jenkins for continuous integration, you can connect nodes with the necessary operating systems and assign tasks to them, there are several options:

The advantages of containers over virtual machines are obvious in this case (the RAM is shared, dynamically changing, a large number of lifted containers do not slow down the system, unlike virtual machines), and Docker adds to them such important points as:
')


Docker as a jenkins node



For jenkins-slave we need:
  1. Java
  2. Entry Point - ssh
  3. Assembly tools


The entry point is needed to start the process in docker and save the file system within the build session (LXC uses the init process, but the whole system does not need anything). Since jenkins will still need SSH to communicate with the node, this daemon will be the entry point.

Docker suggests using Dockerfile files with instructions for building the machine to build the machine.

In this repository: https://github.com/antigluk/docker-jenkins-slave now build rules for

Pull-requests with new systems, and bug fixes are welcome :)

Assembly and use



It is assumed that you have Docker and Jenkins installed

1) Install the Jenkins Swarm Plugin (it allows slaves to be added to Jenkins automatically using the API)
 2) $ git clone git@github.com: antigluk / docker-jenkins-slave.git;  cd docker-jenkins-slave
 3) Go to the folder with the rules for the desired system
     $ cd centos6
 4) $ sudo bash build.sh


When the image is assembled, you can add as many nodes of this type as you like:

     sudo bash add_slave.sh SlaveName


After executing this command, you should see the new node on Jenkins-e.

Now, to use a new node, it is enough to indicate in the tags for assembling the necessary task “docker-tagname” - the name of the tag is the name of the system with the full version, the list of tags can be viewed on a special page in the wiki

Source: https://habr.com/ru/post/200244/


All Articles