debian-mirror-gitlab/doc/ci/examples/test-phoenix-application.md

56 lines
1.2 KiB
Markdown
Raw Normal View History

2018-03-17 18:26:18 +05:30
# Test a Phoenix application with GitLab CI/CD
2016-11-03 12:29:30 +05:30
This example demonstrates the integration of Gitlab CI with Phoenix, Elixir and
Postgres.
2018-03-17 18:26:18 +05:30
## Add `.gitlab-ci.yml` to project
2016-11-03 12:29:30 +05:30
The following `.gitlab-ci.yml` should be added in the root of your
repository to trigger CI:
```yaml
image: elixir:1.3
services:
- postgres:9.6
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`, some Phoenix dependencies, and will also
run your migrations.
Finally, the test `script` will run your tests.
2018-03-17 18:26:18 +05:30
## Update the Config Settings
2016-11-03 12:29:30 +05:30
In `config/test.exs`, update the database hostname:
```elixir
config :my_app, MyApp.Repo,
hostname: if(System.get_env("CI"), do: "postgres", else: "localhost"),
```
2018-03-17 18:26:18 +05:30
## Add the Migrations Folder
2016-11-03 12:29:30 +05:30
If you do not have any migrations yet, you will need to create an empty
`.gitkeep` file in `priv/repo/migrations`.
2018-03-17 18:26:18 +05:30
## Sources
2016-11-03 12:29:30 +05:30
- https://medium.com/@nahtnam/using-phoenix-on-gitlab-ci-5a51eec81142