Using Docker Containers as Jenkins Nodes

    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 built our project only for CentOS 6. Next, support for CentOS 5 was added, and it turned out that dependencies on specific versions of libraries did not allow the same binaries to work under different versions of CentOS, and needed to build different RPMs. This was decided by adding CentOS 5 nodes to jenkins, which was used by VirtualBox virtual machine. Then added support for Suse, and then Debian.

    The amount of RAM is not rubber, and using virtual machines only for assembly 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:
    • Rent instances / computers and use them as nodes
    • Use standard virtualization (hypervisor)
    • Containers (lxc, jail etc)

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

    • To build the project, the build script itself is launched, and nothing more. Whereas when using a virtual machine all system processes and daemons will be launched, which eats away host resources.
    • “Cheap” creation of a large number of independent clones of machines - sometimes an assembly environment is needed to build a project.

    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 inside the assembly session (LXC uses the init process, but the whole system is useless to us). Since jenkins will still need SSH to communicate with the node, this daemon will be the entry point.

    Docker suggests using Dockerfile files with machine assembly instructions to build a machine.

    In this repository: build rules are now available for 
    • CentOS 5
    • CentOS 6
    • Suse 12
    • Debian 6

    Pull requests with new systems and corrections in scripts are welcome :)

    Assembly and use

    It is assumed that you have Docker and Jenkins installed

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

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

        sudo bash SlaveName

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

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

    Also popular now: