Skip to content

Commit b7c985d

Browse files
committed
Configure tests with docker
1 parent 41ad0c2 commit b7c985d

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Ready to run in production? Please [check our deployment guides](http://www.phoe
2121

2222
## Docker
2323

24+
### Running the application
25+
26+
```shell
27+
docker-compose run --rm local
28+
```
29+
2430
### Provisioning the Database
2531

2632
```shell
@@ -32,3 +38,9 @@ docker-compose run --rm local sh -c "mix ecto.create"
3238
```shell
3339
docker-compose run --rm local sh -c "mix ecto.migrate"
3440
```
41+
42+
### Running Tests
43+
44+
```shell
45+
docker-compose run --rm test
46+
```

config/test.exs

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,5 @@ config :logger, level: :warn
1212
# Configure your database
1313
config :rest_api, RestApi.Repo,
1414
adapter: Ecto.Adapters.Postgres,
15-
username: "postgres",
16-
password: "postgres",
17-
database: "rest_api_test",
18-
hostname: "localhost",
15+
url: {:system, "DATABASE_URL"},
1916
pool: Ecto.Adapters.SQL.Sandbox

docker-compose.yml

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1+
db: &DB
2+
image: postgres:9.4.5
3+
ports:
4+
- 5432
5+
environment:
6+
POSTGRES_USER: user
7+
POSTGRES_PASSWORD: password
8+
9+
10+
# Separate database for testing (since it gets deleted)
11+
dbTest:
12+
<<: *DB
13+
14+
115
local:
216
build: .
17+
command: sh -c "mix phoenix.server"
318
ports:
419
- 4000
5-
environment:
20+
environment: &ENV
621
VIRTUAL_HOST: api.local.dockito.org
722
VIRTUAL_PORT: 4000
823
DATABASE_URL: ecto://user:password@db/rest_api_dev
924
volumes:
1025
- ./:/usr/src/app
1126
links:
12-
- postgres:db
27+
- db:db
1328

1429

15-
postgres:
16-
image: postgres:9.4.5
17-
ports:
18-
- '5432:5432'
30+
test:
31+
build: .
32+
command: sh -c "mix test"
1933
environment:
20-
POSTGRES_USER: user
21-
POSTGRES_PASSWORD: password
34+
DATABASE_URL: ecto://user:password@db/rest_api_test
35+
volumes:
36+
- ./:/usr/src/app
37+
links:
38+
- dbTest:db

0 commit comments

Comments
 (0)