Skip to content

Commit b0b2ddb

Browse files
committed
reset/clean db, run test and server in docker image
simple doc
1 parent bbfde02 commit b0b2ddb

14 files changed

+43
-30
lines changed

Dockerfile

-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ RUN mix local.hex --force
99
RUN mix local.rebar --force
1010
RUN mix deps.get
1111
RUN mix compile
12-
13-
CMD ["mix", "phoenix.server"]

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,11 @@ GET /api/v1/sessions
4444
}
4545
]
4646
```
47+
48+
# Docker
49+
50+
* docker-server-init: create/poulate database and run serber in docker-compose env.
51+
* docker-server: Run server on docker-compose env.
52+
* docker-test: Run test on docker-compose env.
53+
* docker-reset: Reset(drop/create/migrate/populate) database in docker-compose env.
54+
* docker-clean: Clean(drop/create/migrate) database in docker-compose env.

config/dev.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ config :point, Point.Repo,
3737
username: "root",
3838
password: "1234",
3939
database: "point_dev",
40-
hostname: "database",
40+
hostname: System.get_env("DB_HOST") || "localhost",
4141
pool_size: 10,
4242
ownership_timeout: 60_000

config/prod.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ config :point, Point.Repo,
3535
username: "root",
3636
password: "1234",
3737
database: "point_prod",
38-
hostname: "database",
38+
hostname: System.get_env("DB_HOST") || "localhost",
3939
pool_size: 100,
4040
ownership_timeout: 60_000
4141

config/test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ config :point, Point.Repo,
2323
username: "root",
2424
password: "1234",
2525
database: "point_test",
26-
hostname: "localhost",
26+
hostname: System.get_env("DB_HOST") || "localhost",
2727
pool: Ecto.Adapters.SQL.Sandbox,
2828
ownership_timeout: 60_000
2929

docker-clean

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix ecto.clean" $1 $2

docker-compose.yml

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1+
database_storage:
2+
image: "busybox"
3+
volumes:
4+
- /var/lib/mysql
5+
16
database:
27
image: "mariadb:10"
38
ports:
4-
- "3307:3306"
9+
- "3306:3306"
510
environment:
611
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
712
MYSQL_DATABASE: "point_${MIX_ENV}"
813
volumes_from:
914
- database_storage
1015

11-
database_storage:
12-
image: "busybox"
13-
volumes:
14-
- /var/lib/mysql
15-
command: "true"
16-
1716
points:
18-
# build: "."
19-
image: adrianmarino/points:${VERSION}
17+
build: "."
2018
environment:
2119
MIX_ENV: ${MIX_ENV}
20+
DB_HOST: database
2221
ports:
2322
- "3000:3000"
2423
links:
25-
- "database"
24+
- database

docker-reset

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix ecto.reset" $1 $2

docker-run

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
COMMAND=$1
3+
4+
export MIX_ENV=${2:-dev}
5+
export MYSQL_ROOT_PASSWORD=${3:-1234}
6+
7+
echo "=========================================================="
8+
echo "Environment: $MIX_ENV"
9+
echo "Password: $MYSQL_ROOT_PASSWORD"
10+
echo "Command: $COMMAND"
11+
echo "=========================================================="
12+
13+
docker-compose run -p3000:3000 --rm points sh -c "$COMMAND"

docker-server

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix phoenix.server" $1 $2

docker-server-init

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix ecto.reset; mix phoenix.server" $1 $2

docker-test

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash docker-run "mix espec --format=doc" test $2

google-chrome-stable

-2
This file was deleted.

start

-13
This file was deleted.

0 commit comments

Comments
 (0)