Using gitlab.com's CI for a project with submodules, lfs, and docker-compose

Hi

As a longtime user of github for open source (since 2008), and also as a user of bitbucket for work (since 2012), I’ve been watching gitlab for a while with interest. I finally got round to trying it out recently, and was impressed.

I would like to contribute some feedback based on my experience of setting up gitlab.com CI for projects that already use git submodules, git lfs, and docker-compose.

I’m sure some of the steps below could be done better - maybe someone can tell me how :slight_smile: . Or, maybe my notes will help someone else in a similar position.

Intro

I have a .gitlab-ci.yml starting with

image: docker:latest

services:
  - docker:dind

Getting submodules

  • My submodules are all in the same group on gitlab.

  • I generated a key pair and added the private key as a variable to
    the project. I added the public key as a deploy key to the project
    and all submodules.

.gitlab-ci.yml:

before_script:
  ...
  - apk add openssh-client git
  - eval $(ssh-agent -s)
  # maybe switch to bash and use process substitution instead
  - tmpfile=$(mktemp ~/pk.XXXXXX)
  - echo "$SSH_PRIVATE_KEY" > $tmpfile
  - ssh-add $tmpfile
  - rm $tmpfile
  - mkdir ~/.ssh && ssh-keyscan -H $GITLAB_URL >> ~/.ssh/known_hosts
  ...

build:
  ...
  script:
    ...
    - git submodule update --init --recursive 
    ...

lfs

  • I have to install git lfs myself.

  • I can’t seem to customize the clone command to do e.g. git lfs clone rather than git clone.

.gitlab-ci.yml:

before_script:
  ...
  - apk add wget
  - wget https://github.com/github/git-lfs/releases/download/v1.4.1/git-lfs-linux-amd64-1.4.1.tar.gz && tar xf git-lfs-linux-amd64-1.4.1.tar.gz && cd git-lfs-1.4.1/ && ./install.sh
  - git lfs install
  ...
build:
  script:
    ...
    - git lfs pull
    ...

docker compose

  • I have to install docker compose myself.

.gitlab-ci.yml:

before_script:
  ...
  - apk add python python-dev py-pip build-base
  - curl -L https://github.com/docker/compose/releases/download/1.8.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  - chmod +x /usr/local/bin/docker-compose
  - pip install docker-compose
  ...

(P. S. By default, docker-compose exec allocates a tty, so I needed to use docker-compose exec -T during CI.)

supplying my own runner

  • I found my builds were taking ages. I assumed the shared runners were really slow (see next section), so I switched to my own runner.

I needed to modify /etc/gitlab-runner/config.toml:

  [runners.docker]
    ...
    privileged = true
    ...

docker driver

  • I found my builds were taking ages. At first, I just assumed the shared runners were really slow, so I switched to my own runner. Although this didn’t speed things up, I noticed that builds were consuming a huge amount of disk space, so I realized the vfs driver was being used.

On my ubuntu/debian runners, I specified the following in .gitlab-ci.yml:

variables:
  ...
  DOCKER_DRIVER: aufs
  ...

I don’t know what is appropriate for the shared runners, or how I would handle needing different drivers for different systems (if that is necessary).

registry

I haven’t yet been able to use docker-compose to push to registry.gitlab.com during the CI - I always get an authentication error, even though a preceding docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $CI_REGISTRY appears to be successful.

cache

I haven’t yet tried to figure out if I can use caching appropriately for docker images and lfs.

General notes

  • I learned some of the things below from gitlab’s documentation, but I was often confused about which documentation I ought to be looking at (gitlab.com? gitlab CE?), and in any case, what to do wasn’t always clear to me from the documentation. Unfortunately I don’t have time right now to go back through and evaluate the documentation and submit pull requests. Sorry about that.

  • I had some initial difficulty finding the ‘gear’ icon on the project page to allow access to project settings! On my two laptops, using chrome, I had to change the zoom level to 90% before the icon appeared. That was very confusing before I knew of the icon’s existence. If I weren’t used to some regular confusion from switching between github and bitbucket, I might have given up! However, maybe this icon problem does not arise for other people.

  • Having to do all the things listed above for all my projects on gitlab.com is really a pain, but it’s great that this combination of submodules, lfs, and docker is available all on one site!