Skip to content

Commit

Permalink
build(docker): created Dockerfile (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrielparizet authored Jul 2, 2024
1 parent d65d747 commit afe59cf
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_build
.elixir_ls
data
deps
15 changes: 15 additions & 0 deletions Dockerfile
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
4 changes: 2 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Config
config :book_my_gigs, BookMyGigs.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
hostname: "db",
database: "book_my_gigs_dev",
stacktrace: true,
show_sensitive_data_on_connection_error: true,
Expand All @@ -19,7 +19,7 @@ config :book_my_gigs, BookMyGigs.Repo,
config :book_my_gigs, BookMyGigsWeb.Endpoint,
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {127, 0, 0, 1}, port: 4000],
http: [ip: {0, 0, 0, 0}, port: 4000],
check_origin: false,
code_reloader: true,
debug_errors: true,
Expand Down
58 changes: 48 additions & 10 deletions docker-compose.yml
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:



20 changes: 20 additions & 0 deletions entrypoint.sh
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

0 comments on commit afe59cf

Please sign in to comment.