-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(docker): created Dockerfile (#1)
- Loading branch information
1 parent
d65d747
commit afe59cf
Showing
5 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
_build | ||
.elixir_ls | ||
data | ||
deps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM elixir:1.14.5 | ||
|
||
RUN apt update && apt install -y build-essential inotify-tools | ||
|
||
RUN mkdir /book_my_gigs | ||
COPY . /book_my_gigs | ||
WORKDIR /book_my_gigs | ||
|
||
RUN mix local.hex --force && \ | ||
mix local.rebar --force | ||
|
||
CMD mix deps.get && \ | ||
mix ecto.create && \ | ||
mix ecto.migrate && \ | ||
mix phx.server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,51 @@ | ||
volumes: | ||
data: | ||
|
||
services: | ||
postgres: | ||
services: | ||
phoenix: | ||
build: | ||
context: . | ||
environment: | ||
PGUSER: postgres | ||
PGPASSWORD: postgres | ||
PGDATABASE: book_my_gigs_dev | ||
PGPORT: 5432 | ||
PGHOST: db | ||
ports: | ||
- '4000:4000' | ||
depends_on: | ||
- db | ||
networks: | ||
- backend | ||
volumes: | ||
- phoenix_deps:/book_my_gigs/deps | ||
- phoenix_build:/book_my_gigs/_build | ||
- ./:/book_my_gigs | ||
expose: | ||
- 4000 | ||
|
||
db: | ||
image: postgres:latest | ||
hostname: db # facultatif car par défaut il prend le nom du service | ||
environment: | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=postgres | ||
ports: | ||
- 5432:5432 | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: book_my_gigs_dev | ||
restart: always | ||
# name:/docker_path (but this time docker containes the data file) | ||
# ./local_path:/docker_path | ||
volumes: | ||
- data:/var/lib/postgresql | ||
- ./data:/var/lib/postrgresql/data | ||
networks: | ||
- backend | ||
ports: | ||
- '5432:5432' | ||
|
||
# Allows containers to communicate over the same network | ||
networks: | ||
backend: | ||
driver: bridge | ||
|
||
volumes: | ||
phoenix_deps: | ||
phoenix_build: | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# Docker entrypoint script. | ||
|
||
# Wait until Postgres is ready. | ||
while ! pg_isready -q -h $PGHOST -p $PGPORT -U $PGUSER | ||
do | ||
echo "$(date) - waiting for database to start" | ||
sleep 2 | ||
done | ||
|
||
# Create, migrate, and seed database if it doesn't exist. | ||
if [[ -z `psql -Atqc "\\list $PGDATABASE"` ]]; then | ||
echo "Database $PGDATABASE does not exist. Creating..." | ||
createdb -E UTF8 $PGDATABASE -l en_US.UTF-8 -T template0 | ||
mix ecto.migrate | ||
mix run priv/repo/seeds.exs | ||
echo "Database $PGDATABASE created." | ||
fi | ||
|
||
exec mix phx.server |