summaryrefslogtreecommitdiff
path: root/doc/ci/examples/test-phoenix-application.md
blob: 78cab2c0aeb569123035aa3e7c8fca39b569b477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Test a Phoenix application

This example demonstrates the integration of Gitlab CI with Phoenix, elixir and
postgres.

### 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
image: elixir:1.3.1

services:
  - postgres:9.5.3

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
```

The variables will set the Mix environment to test. The
before_script will install `psql`, and other phoenix dependencies and will also
run your migrations.

Finally, the test script will run your tests.

### Update 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"),
```

### 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`.

**Source**: https://medium.com/@nahtnam/using-phoenix-on-gitlab-ci-5a51eec81142