Dockerize your builds in GitLab CI

GitLab CI is an CI/CD tool integrated directly into GitLab.com. GitLab CI uses a distributed approach for running its jobs and offers shared runners running on Digital Ocean. They also have Docker support and even an integrated Docker registry for each project. This short (four source files) tutorial will show how you can deploy your own Dockerized build environment and use that in the CI pipeline of your service.

1

First we define our build environment through ad Dockerfile. In this example I’m going to build a Standalone Spring Boot application so I start with a Java based image and then installs the Spring Boot CLI.

2

We then define the CI integration in a .gitlab-ci.yml file that will be automatically picked up by GitLab CI. The runner used here is docker based with support for docker-in-docker (i.e. we can run Docker commands from within the runner). This gives us the ability to build our image and publish it to the built in registry.

3

Now let’s define a service that we will build with our newly created builder. It’s a simple Spring Boot application in Groovy.

4

And finally we can tell GitLab CI to use our Dockerized build environment when building our service. At the end we specify the artifacts, an executable fat jar in this case, that will be downloadable from GitLab.

With Docker support in GitLab CI we can do really powerful things when building, testing and deploying our applications.

You can find the source code for this example here:

Leave a Reply

Your email address will not be published. Required fields are marked *