From c4cfb081e79aa218d56e77ade3035c38bb06c601 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 25 Jul 2018 16:42:04 +0200 Subject: [PATCH] Add docker-compose dev Signed-off-by: Thomas Citharel --- Dockerfile | 11 ++++++ config/dev.exs | 11 +++--- docker-compose.yml | 38 +++++++++++++++++++ docker/entrypoint.sh | 22 +++++++++++ js/Dockerfile | 9 +++++ js/docker/entrypoint.sh | 5 +++ mix.exs | 19 ++++++---- .../migrations/20180109150000_prerequites.exs | 9 +++-- 8 files changed, 108 insertions(+), 16 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker/entrypoint.sh create mode 100644 js/Dockerfile create mode 100755 js/docker/entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..ff7e19c3 --- /dev/null +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/config/dev.exs b/config/dev.exs index 619571a4..6fecc048 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -47,15 +47,14 @@ config :logger, :console, format: "[$level] $message\n", level: :debug # in production as building large stacktraces may be expensive. config :phoenix, :stacktrace_depth, 20 -config :eventos, Eventos.Mailer, - adapter: Bamboo.LocalAdapter +config :eventos, Eventos.Mailer, adapter: Bamboo.LocalAdapter # Configure your database config :eventos, Eventos.Repo, adapter: Ecto.Adapters.Postgres, types: Eventos.PostgresTypes, - username: "elixir", - password: "elixir", - database: "eventos_dev", - hostname: "localhost", + username: System.get_env("POSTGRES_USER") || "elixir", + password: System.get_env("POSTGRES_PASSWORD") || "elixir", + database: System.get_env("POSTGRES_DATABASE") || "eventos_dev", + hostname: System.get_env("POSTGRES_HOST") || "localhost", pool_size: 10 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..0237d3f9 --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 00000000..7e126447 --- /dev/null +++ b/docker/entrypoint.sh @@ -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 \ No newline at end of file diff --git a/js/Dockerfile b/js/Dockerfile new file mode 100644 index 00000000..55c74ede --- /dev/null +++ b/js/Dockerfile @@ -0,0 +1,9 @@ +FROM node:10 + +LABEL maintainer="tcit" + +COPY docker/entrypoint.sh /bin/entrypoint + +WORKDIR /app/js + +EXPOSE 8080 \ No newline at end of file diff --git a/js/docker/entrypoint.sh b/js/docker/entrypoint.sh new file mode 100755 index 00000000..30417464 --- /dev/null +++ b/js/docker/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +npm install +npm rebuild node-sass +npm run serve \ No newline at end of file diff --git a/mix.exs b/mix.exs index 12fc2979..163c8f93 100644 --- a/mix.exs +++ b/mix.exs @@ -6,13 +6,18 @@ defmodule Eventos.Mixfile do app: :eventos, version: "0.0.1", elixir: "~> 1.4", - elixirc_paths: elixirc_paths(Mix.env), - compilers: [:phoenix, :gettext] ++ Mix.compilers, - start_permanent: Mix.env == :prod, + elixirc_paths: elixirc_paths(Mix.env()), + compilers: [:phoenix, :gettext] ++ Mix.compilers(), + start_permanent: Mix.env() == :prod, aliases: aliases(), deps: deps(), 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", source_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. defp elixirc_paths(:test), do: ["lib", "test/support"] - defp elixirc_paths(_), do: ["lib"] + defp elixirc_paths(_), do: ["lib"] # Specifies your project dependencies. # @@ -72,7 +77,7 @@ defmodule Eventos.Mixfile do {:geolix, "~> 0.16"}, # Dev and test dependencies {: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}, {:excoveralls, "~> 0.8", only: :test}, {: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.reset": ["ecto.drop", "ecto.setup"], - "test": ["ecto.create --quiet", "ecto.migrate", "test"] + test: ["ecto.create --quiet", "ecto.migrate", "test"] ] end end diff --git a/priv/repo/migrations/20180109150000_prerequites.exs b/priv/repo/migrations/20180109150000_prerequites.exs index 428ea724..b27db8ac 100644 --- a/priv/repo/migrations/20180109150000_prerequites.exs +++ b/priv/repo/migrations/20180109150000_prerequites.exs @@ -2,15 +2,18 @@ defmodule Eventos.Repo.Migrations.Prerequites do use Ecto.Migration def up do - execute """ + execute(""" CREATE TYPE datetimetz AS ( dt timestamptz, tz varchar ); - """ + """) + + execute("CREATE EXTENSION IF NOT EXISTS postgis") end def down do - execute "DROP TYPE IF EXISTS datetimetz;" + execute("DROP TYPE IF EXISTS datetimetz;") + execute("DROP EXTENSION IF EXISTS postgis") end end