Setting up Gitlab CI for Elixir/Phoenix on your VPS

Gitlab is a great development tool, getting better with every release. They give you access to their new-ish pipelining features on for free. However, I wanted to setup the Gitlab Runner (this is what executes your CI build) on my own VPS using Docker. Gitlab makes this very easy to install, but the documentation is spread out when it comes to setup and execution. I thought an all in one document showing all the steps would be helpful to the community.

I am hoping this post will help out others looking to run their Elixir/Phoenix application tests through the CI pipeline using their own VPS.

All commands were executed on my VPS as the root user. If you are logged in as a user that has sudo access, you will need to prepend all commands with sudo.

Prerequisites: A VPS or similar server (virtualbox, docker, …)

 Setup the Gitlab Runner

 Run on your VPS

Install docker

Install Gitlab Runner Repository

curl -L

Install Gitlab Runner

apt-get install gitlab-ci-multi-runner

Login to and navigate to the project you want to use the runner for. Open the project Settings -> CI/CD Pipelines section.


You will then see the Specific Runners section which contains the URL and key to use to setup your runner.


Register the runner

gitlab-ci-multi-runner register

When asked which executor to use, type in docker. You will need to provide the default docker image to use, I used elixir:1.4. Also I set the runner to not be project specific, and to only run tagged builds. The tag I am using for the runner is elixir.

 Configure your Elixir application

Create a .gitlab-ci.yml file, at the root of your repo, with the following contents.

image: elixir:1.4

  - postgres:9.6.2

  POSTGRES_DB: project_test
  POSTGRES_PASSWORD: “[email protected]”

  - test

  - mix local.hex –force
  - mix local.rebar –force
  - mix deps.get
  - MIX_ENV=test mix ecto.create
  - MIX_ENV=test mix ecto.migrate

  stage: test
    - MIX_ENV=test mix test

    - elixir

 Database configuration

The last step before any tests can be ran is to update the config/test.exs file. The database name, username, password, and host should match what was set in the .gitlab-ci.yml file. We didn’t explicitly set the host in that file because it is handled for us. The hostname would be postgres.

# Configure your database (config/test.exs)
config :project, Project.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "runner",
  password: "[email protected]",
  database: "project_test",
  hostname: "postgres",
  pool: Ecto.Adapters.SQL.Sandbox

 Finishing up

Push the branch to Gitlab, and open the Pipeline tab for the project. You should see the tests running for your branch. The page doesn’t appear to automatically update, a refresh may be needed to see latest pushes. If the tests pass, you should see something similar:


Gitlab also has badges build in to spice up your or project site.




Now read this

ElixirConf 2018 crunch time

Crunch time is here, ElixirConf is in 36 days! I started my presentation which is going to require a lot more time than previously imagined. My goal is to have the audience laugh a bit while learning how to build their own weather... Continue →