2016-07-04 13:20:16 -04:00
|
|
|
## Test a Phoenix application
|
|
|
|
|
2016-10-11 03:36:03 -04:00
|
|
|
This example demonstrates the integration of Gitlab CI with Phoenix, Elixir and
|
|
|
|
Postgres.
|
2016-07-04 13:20:16 -04:00
|
|
|
|
|
|
|
### 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
|
2016-10-11 03:36:03 -04:00
|
|
|
image: elixir:1.3
|
2016-07-04 13:20:16 -04:00
|
|
|
|
|
|
|
services:
|
2016-10-11 03:36:03 -04:00
|
|
|
- postgres:9.6
|
2016-07-04 13:20:16 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
```
|
|
|
|
|
2016-10-11 03:36:03 -04:00
|
|
|
The variables will set the Mix environment to "test". The
|
|
|
|
`before_script` will install `psql`, some Phoenix dependencies, and will also
|
2016-07-04 13:20:16 -04:00
|
|
|
run your migrations.
|
|
|
|
|
2016-10-11 03:36:03 -04:00
|
|
|
Finally, the test `script` will run your tests.
|
2016-07-04 13:20:16 -04:00
|
|
|
|
|
|
|
### Update the Config Settings
|
|
|
|
|
|
|
|
In `config/test.exs`, update the database hostname:
|
2016-10-11 03:36:03 -04:00
|
|
|
|
|
|
|
```elixir
|
2016-07-04 13:20:16 -04:00
|
|
|
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`.
|
|
|
|
|
2016-10-11 03:36:03 -04:00
|
|
|
### Sources
|
|
|
|
|
|
|
|
- https://medium.com/@nahtnam/using-phoenix-on-gitlab-ci-5a51eec81142
|
|
|
|
- https://davejlong.com/ci-with-phoenix-and-gitlab/
|