Maksym Prokopov personal blog
Idea is a something worth sharing

Gitlab: continuous delivery setup for Clojure/Java with Docker

01.01.0001

Reading time: 2 min.

Recently I was doing a https://github.com/mprokopov/it-service-sse and I though it should be a good idea to implement automatic build and deployment to docker registry container. I already have Gitlab installed and started to play around.

Long story short, here my .gitlab-ci.yml which took me a couple of days to figure out what is the “artifact” in Gitlab and how is it suppose to survive between artifact builds and docker builds.

My current setup has two stages, java build and then docker build. At the first stage we use clojure:lein-2.7.1-alpine, which is quite small, to build jar file from the sources. Then we try to assemble docker container and reuse artifact from the previous build. I was lucky enough to discover that artifact could be saved with help of “cache” option in YML file which preserves folder in “path” for the next build.

So here is the working Gitlab CI configuration which builds JAR as artifact and uploads to the Pipeline page and then creates docker container and publishes it to the internal Gitlab registry.

# Based on openjdk:8, already includes lein

# If you need to configure a database, add a `services` section here

# See https://docs.gitlab.com/ce/ci/services/postgres.html

# Make sure you configure the connection as well

#before_script:

# If you need to install any external applications, like a

# postgres client, you may want to uncomment the line below:

#- apt-get update -y

# Retrieve project dependencies

# Do this on before_script since it’ll be shared between both test and

# any production sections a user adds

#- lein deps

stages:

- jar

- docker

#test:

# script:

# If you need to run any migrations or configure the database, this

# would be the point to do it.