GitLab Runners

Featured image

I wanted to move away from using webhooks to control my deployment. I didn’t really like the idea of having to run a server just to listen for deployments. Plus it meant I had some deployment scripts sitting on my server and not in source control which I really didn’t like.

I know I shouldn’t have been but I was surprised with how easy it was to get it set up and running1. Install the runner, make a couple of changes to the .gitlab-ci.yml file and I was up and running.

Setting up the Runner

I used the GitLab instructions for configuring the runner. The only change I made was to the /etc/gitlab-runner/config.toml file to enable checking out to a specific directory2.

concurrent = 1
check_interval = 0

  session_timeout = 1800

  name = ""
  url = ""
  token = "yRTZzdV-5FHnMwcyiRyn"
  executor = "shell"
    enabled = true

GitLab CI Config

My deployment steps for staging are shown below.

  stage: deploy
  # Only run on my self-hosted staging runner
    - self-hosted
    - staging
    # GIT_CLONE_PATH is not required anymore
    - docker pull $DOCKER_IMAGE_NAME:$IMAGE_TAG
    - docker stack deploy --compose-file docker-compose-dev.yml devblog
    name: Staging
    - develop

I’m currently using Docker Swarm for deployments as a lightweight way to get rolling updates. I would like to move to Kubernetes but the extra overhead on my small VPS was not going to work.

Using GitLab runners also means I know the deployment has actually finished and worked. Previously when using webhooks I just had to assume the deployment had worked.

I’ve also got distracted again about hosting my images somewhere other than in my git repo. I still haven’t written my watch app…

  1. At least that’s what I thought when I started writing this blog post. 8 hours later and I’ve only just got it fully working so maybe not as easy as I thought. Among other things I stumbled across a weird issue that meant environment variables weren’t expanding. ↩︎

  2. In the end I didn’t need this - my old deployment method required a specific folder name but the new method doesn’t. But I’m leaving this paragraph in for my own records. ↩︎