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 of 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 a Maven repository).
- GitLab (to host the sources of my Java projects).
- Jenkins (of course to make use of pipeline as code).
In this post, I describe how I set up each container and make them work together as one stack. I'll 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
… services: … nexus: image: clearent/nexus volumes: – /opt/data/nexus:/nexus-data ports: – 8081:8081 …
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.
To combine these images to one working GitLab, I use the following docker-compose snippet:
… services: … redis: image: sameersbn/redis:latest volumes: – /opt/data/gitlab/redis:/var/lib/redis postgresql: image: sameersbn/postgresql:9.6-1 environment: – DEBUG=true – DB_USER=gitlab – DB_PASS=password – DB_NAME=gitlabhq_production – DB_EXTENSION=pg_trgm – PG_TRUST_LOCALNET=true volumes: – /opt/data/gitlab/postgresql:/var/lib/postgresql ports: – “15432:5432” gitlab: image: sameersbn/gitlab:8.15.4 depends_on: – redis – postgresql ports: – “8082:80” – “8022:22” environment: – DEBUG=true – TZ=Europe/Berlin – GITLAB_TIMEZONE=Berlin – GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alphanumeric-string – GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string – GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string – GITLAB_HOST=localhost – GITLAB_PORT=8082 – GITLAB_SSH_PORT=8022 – DB_ADAPTER=postgresql – DB_HOST=postgresql – DB_PORT=5432 – DB_USER=gitlab – DB_PASS=password – DB_NAME=gitlabhq_production – REDIS_HOST=redis – REDIS_PORT=6379 … volumes: – /opt/data/gitlab/gitlab:/home/git/data …
See my GitLab repo here for the full docker-compose file.
Finally, there is Jenkins itself. I started out with the official Jenkins image, but that missed some options for me, so I created my own image, which can be found here. The things that I changed were adding an
httping package to the OS. I have the GitLab plugin installed as default since I need it in my setup. The Dockerfile looks like this:
FROM jenkins:2.32.1 USER root 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 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:
And we're done!