Add docker-compose dev

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-07-25 16:42:04 +02:00
parent bb1cdc2043
commit c4cfb081e7
8 changed files with 108 additions and 16 deletions

11
Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM elixir:1.6
RUN apt-get update && apt-get install -y build-essential inotify-tools postgresql-client
RUN mix local.hex --force && mix local.rebar --force
COPY docker/entrypoint.sh /bin/entrypoint
WORKDIR /app
EXPOSE 4000

View file

@ -47,15 +47,14 @@ config :logger, :console, format: "[$level] $message\n", level: :debug
# in production as building large stacktraces may be expensive. # in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 20 config :phoenix, :stacktrace_depth, 20
config :eventos, Eventos.Mailer, config :eventos, Eventos.Mailer, adapter: Bamboo.LocalAdapter
adapter: Bamboo.LocalAdapter
# Configure your database # Configure your database
config :eventos, Eventos.Repo, config :eventos, Eventos.Repo,
adapter: Ecto.Adapters.Postgres, adapter: Ecto.Adapters.Postgres,
types: Eventos.PostgresTypes, types: Eventos.PostgresTypes,
username: "elixir", username: System.get_env("POSTGRES_USER") || "elixir",
password: "elixir", password: System.get_env("POSTGRES_PASSWORD") || "elixir",
database: "eventos_dev", database: System.get_env("POSTGRES_DATABASE") || "eventos_dev",
hostname: "localhost", hostname: System.get_env("POSTGRES_HOST") || "localhost",
pool_size: 10 pool_size: 10

38
docker-compose.yml Normal file
View file

@ -0,0 +1,38 @@
version: '3'
services:
postgres:
container_name: eventos_db
restart: unless-stopped
image: mdillon/postgis:10
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: eventos_dev
front:
container_name: eventos_front
restart: unless-stopped
build: ./js
volumes:
- './js:/app/js'
ports:
- "80:8080"
entrypoint: entrypoint
api:
container_name: eventos_api
restart: unless-stopped
build: .
volumes:
- '.:/app'
ports:
- "4000:4000"
depends_on:
- postgres
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DATABASE: eventos_dev
POSTGRES_HOST: postgres
entrypoint: entrypoint

22
docker/entrypoint.sh Executable file
View file

@ -0,0 +1,22 @@
#!/bin/bash
mix deps.get
# Wait for Postgres to become available.
until PGPASSWORD=$POSTGRES_PASSWORD psql -h postgres -U "postgres" -c '\q' 2>/dev/null; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
echo "\nPostgres is available: continuing with database setup..."
# Potentially Set up the database
mix ecto.create
mix ecto.migrate
echo "\nTesting the installation..."
# "Proove" that install was successful by running the tests
mix test
echo "\n Launching Phoenix web server..."
iex -S mix phx.server

9
js/Dockerfile Normal file
View file

@ -0,0 +1,9 @@
FROM node:10
LABEL maintainer="tcit"
COPY docker/entrypoint.sh /bin/entrypoint
WORKDIR /app/js
EXPOSE 8080

5
js/docker/entrypoint.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
npm install
npm rebuild node-sass
npm run serve

19
mix.exs
View file

@ -6,13 +6,18 @@ defmodule Eventos.Mixfile do
app: :eventos, app: :eventos,
version: "0.0.1", version: "0.0.1",
elixir: "~> 1.4", elixir: "~> 1.4",
elixirc_paths: elixirc_paths(Mix.env), elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers, compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env == :prod, start_permanent: Mix.env() == :prod,
aliases: aliases(), aliases: aliases(),
deps: deps(), deps: deps(),
test_coverage: [tool: ExCoveralls], test_coverage: [tool: ExCoveralls],
preferred_cli_env: ["coveralls": :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test], preferred_cli_env: [
coveralls: :test,
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test
],
name: "Eventos", name: "Eventos",
source_url: "https://framagit.org/tcit/eventos", source_url: "https://framagit.org/tcit/eventos",
homepage_url: "https://framagit.org/tcit/eventos", homepage_url: "https://framagit.org/tcit/eventos",
@ -32,7 +37,7 @@ defmodule Eventos.Mixfile do
# Specifies which paths to compile per environment. # Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"] defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"] defp elixirc_paths(_), do: ["lib"]
# Specifies your project dependencies. # Specifies your project dependencies.
# #
@ -72,7 +77,7 @@ defmodule Eventos.Mixfile do
{:geolix, "~> 0.16"}, {:geolix, "~> 0.16"},
# Dev and test dependencies # Dev and test dependencies
{:phoenix_live_reload, "~> 1.0", only: :dev}, {:phoenix_live_reload, "~> 1.0", only: :dev},
{:ex_machina, "~> 2.1", only: :test}, {:ex_machina, "~> 2.2", only: [:dev, :test]},
{:credo, "~> 0.8", only: [:dev, :test], runtime: false}, {:credo, "~> 0.8", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.8", only: :test}, {:excoveralls, "~> 0.8", only: :test},
{:ex_doc, "~> 0.16", only: :dev, runtime: false}, {:ex_doc, "~> 0.16", only: :dev, runtime: false},
@ -91,7 +96,7 @@ defmodule Eventos.Mixfile do
[ [
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"], "ecto.reset": ["ecto.drop", "ecto.setup"],
"test": ["ecto.create --quiet", "ecto.migrate", "test"] test: ["ecto.create --quiet", "ecto.migrate", "test"]
] ]
end end
end end

View file

@ -2,15 +2,18 @@ defmodule Eventos.Repo.Migrations.Prerequites do
use Ecto.Migration use Ecto.Migration
def up do def up do
execute """ execute("""
CREATE TYPE datetimetz AS ( CREATE TYPE datetimetz AS (
dt timestamptz, dt timestamptz,
tz varchar tz varchar
); );
""" """)
execute("CREATE EXTENSION IF NOT EXISTS postgis")
end end
def down do def down do
execute "DROP TYPE IF EXISTS datetimetz;" execute("DROP TYPE IF EXISTS datetimetz;")
execute("DROP EXTENSION IF EXISTS postgis")
end end
end end