Last week I wanted to try new things with ‘pipeline as code’ with Jenkins. The best way to try new things is running it as Docker containers. This way I can keep my MacBook clean and don’t mess up existing stuff I am working on (also see this article about what Docker can offer for a developer). Another big advantage by using Docker is that there is already a complete stack of Dockers available to set up the necessary tools. However, for some unclear reason this stack didn’t work on my MacBook (see this issue) so I took this opportunity to build my own stack with some Dockers of my own choice :-).
The tools in my stack are:
- Nexus (as Maven repository)
- Gitlab (to host the sources of my Java projects)
- Jenkins (of course to make use pipeline as code)
In this post I describe how I set up each container and made it working together as one stack. I start with the easiest one:
Actually I prefer Artifactory since I am more used to use that. But as you can read here I also had some trouble to get my Artifactory up and running as a Docker container. How different this was with Nexus. Just simply get a publicly available Docker image, set some port and off you go! Here is how I used it in my ‘docker-compose.yml’ file:
This one was somewhat harder to set it up. I ended up using the following Docker containers:
All of these containers are based on the work from Sameer Naik.
This one uses the Ubuntu image from the same guy as base and installs Redis on it. For more details see the sources of this image. The image itself can be found here.
Also based on the Ubuntu image, its sources (and detailed description) can be found here and the Docker image here.
Finally the Gitlab image, also based on the sources (here) and Docker image (here) of Sameer Naik.
To combine these images to one working Gitlab I use the following docker-compose snippet:
See my Gitlab repo here for the full docker-compose file.
Finally there is Jenkins itself. I started out with ‘official’ Jenkins image but that missed some options for me so I created my own image which can be found here.
The things I changed were adding ‘httping’ package to the OS and I have the GitLab plugin installed as default since I need it in my setup. The Dockerfile looks like this:
RUN apt-get update && apt-get install -y httping
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
Now I have all components complete for the stack. The complete Docker Compose file can be found here. As you might notice I use some directories on the host to store the data. You can read more about that here. To set this up in Docker on the Mac OS go to the Docker Preferences and the ‘File Sharing’ pane and add the directories you want to store the data in:
This way I can easily play around with the stack, remove it and create a new one without loosing the configuration and setup I had already added.
To start the stack I simply perform a ‘docker-compose up’ and the different Docker containers are started:
Now I can enter Jenkins via the browser: