BigW Consortium Gitlab

test-phoenix-application.md 1.22 KB
Newer Older
1 2
## Test a Phoenix application

3 4
This example demonstrates the integration of Gitlab CI with Phoenix, Elixir and
Postgres.
5 6 7 8 9 10 11

### Add `.gitlab-ci.yml` file to project

The following `.gitlab-ci.yml` should be added in the root of your
repository to trigger CI:

```yaml
12
image: elixir:1.3
13 14

services:
15
  - postgres:9.6
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

variables:
  MIX_ENV: "test"

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

test:
  script:
    - mix test
```

33 34
The variables will set the Mix environment to "test". The
`before_script` will install `psql`, some Phoenix dependencies, and will also
35 36
run your migrations.

37
Finally, the test `script` will run your tests.
38 39 40 41

### Update the Config Settings

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

```elixir
44 45 46 47 48 49 50 51 52
config :my_app, MyApp.Repo,
  hostname: if(System.get_env("CI"), do: "postgres", else: "localhost"),
```

### Add the Migrations Folder

If you do not have any migrations yet, you will need to create an empty
`.gitkeep` file in `priv/repo/migrations`.

53 54 55 56
### Sources

- https://medium.com/@nahtnam/using-phoenix-on-gitlab-ci-5a51eec81142
- https://davejlong.com/ci-with-phoenix-and-gitlab/