GitLab CI Images

Building Docker Images for GitLab CI

We have found it valuable to build project-specific Docker images, using
Packer, and using these to drive our CI process. The key
reason for this is it allows us to prime the CI image with exactly the pieces
our project needs, so that each CI pipeline doesn’t need to set everything up
from scratch.

Drumkit includes a number of helpers to scaffold this setup for you. The key
pieces are:

GitLab image registry (to store your container images)

Layered packer build scripts

Helper scripts for packer to call when provisioning images

Drumkit targets for easy make ci-image setup

GitLab Image Registry

Your GitLab project should have a Docker image registry enabled by default,
assuming your instance has the feature enabled.

While it is possible to automate authenticating to your image registry, the
simplest solution is to do a docker login before building the images below,
using your regular gitlab credentials. This just authenticates that you have
access to the project and permission to push container images:

docker login registry.gitlab.com

Layered packer build scripts

The idea is to build up layers of Docker images, to build up your technology
stack. Each is built up based on the previous layer, but also easy to override
if you need to customize what a layer does.

For example, as Drupal developers, we typically want a LAMP stack, which
the core Drumkit targets provide:

#!/bin/bash
# Steps for setting up CV inside a CI docker image at packer time.
# Run a composer install to pre-populate its cache, which should speed up the process in CI.
cd /var/www/[PROJECT]
. d
make build VERBOSE=1

Drumkit Targets

In our top-level Makefile we create targets like this:

TBD: except for the top-level one, these should probably move up into drumkit