Set up your own Continuous Delivery Stack

Pascal Alma

Pascal Alma

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:

Nexus


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:


services:

nexus:
image: clearent/nexus
volumes:
– /opt/data/nexus:/nexus-data
ports:
– 8081:8081

GitLab

This one was somewhat harder to set it up. I ended up using the following Docker containers:

  • Redis
  • PostgreSql
  • GitLab

All of these containers are based on the work from Sameer Naik.

  • redis:latest
    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.
  • postgresql:9.6-1
    Also based on the Ubuntu image, its sources (and detailed description) can be found here and the Docker image here.
  • gitlab:8.15.4
    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:

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.

Jenkins


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:

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 the Docker Preferences and the ‘File Sharing’ pane and add the directories you want to store the data in:

pascal alma 2

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:

pascal alma 3

Now I can enter Jenkins via the browser:

pascal alma 4

 

 

The following two tabs change content below.
Pascal Alma
Pascal is a senior IT consultant and has been working in IT since 1997. He is closely following the latest development in new technologies (Mobile, Cloud, Big Data) and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring, Amazon AWS, API/REST, Big Data, Continuous Delivery, Swift/iOS
Pascal Alma

Latest posts by Pascal Alma (see all)

Authors

Related posts

*

Top