Using Phoenix on Gitlab CI

Creating the .gitlab-ci.yml File

Manthan Mallikarjun
nahtnam
1 min readJul 4, 2016

--

We will use Gitlab’s Docker build system to so we wont have to install Elixir ourselves. Create a .gitlab-ci.yml file with the following inside it:

image: elixir:1.3

Tells gitlab to use the Elixir dockerfile. Change the version number to suit your needs.

services:
- postgres:9.6

Imports the postgres service, change the version to suit your needs. If you don’t use postgres, you will have to swap this out with your respective DBMS.

variables:
MIX_ENV: "test"

Ensure mix uses the testing environment.

before_script:
# Setup phoenix dependencies
- apt-get update
- apt-get install -y postgresql-client
- mix local.hex --force
- mix deps.get --only test
- mix ecto.reset

Update the system, and install the postgres client (psql command) which is required by postgrex. Install hex. Then get the required dependencies and create the test database and run your migrations.

test:
script:
- mix test

Runs your tests.

Updating the Config Settings

In config/test.exs, update the database hostname:

config :my_app, MyApp.Repo,
hostname: if(System.get_env("CI"), do: "postgres", else: "localhost"),

This will set the hostname to postgres when the CI is running to be able to connect to the test database.

Add Migrations Folder

If you do not have any migrations, the migrations folder will be empty, and so it will not be added to git which means that Phoenix will throw an error. Go to priv/repo/migrations and create an empty file named .gitkeep if you do not have any migrations yet.

--

--