From 3c26e08408926f540624b2fd0e9d0c4b50f00661 Mon Sep 17 00:00:00 2001 From: Nico Durstewitz Date: Tue, 25 Jul 2017 15:10:47 +0200 Subject: [PATCH 1/2] Fix a typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2567047..e59ecac 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ brew install redis ### Setup * Clone the repo -* Copy the `dev.secret.exs.sample` file to `dev.secret.ext` and add the appropriate values +* Copy the `dev.secret.exs.sample` file to `dev.secret.exs` and add the appropriate values * Install dependencies with `mix deps.get` * If you get errors here, open a new terminal window. Some commands don't yet have proper binding if you've just installed `elixir` from Homebrew. * Create and migrate your database with `mix ecto.create && mix ecto.migrate` From eda8213e9db341e817d6708548ff71e0dac3d87b Mon Sep 17 00:00:00 2001 From: Nico Durstewitz Date: Tue, 25 Jul 2017 15:11:07 +0200 Subject: [PATCH 2/2] Add Docker setup --- Dockerfile | 12 ++++++++++++ README.md | 32 ++++++++++++++++++++++---------- config/dev.exs | 6 ++++-- config/test.exs | 12 +++++++++++- docker-compose.yml | 22 ++++++++++++++++++++++ docker-entrypoint.sh | 10 ++++++++++ 6 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f08606 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM elixir:1.3 + +RUN curl -sL https://deb.nodesource.com/setup_5.x | bash - +RUN apt-get update && apt-get install -y \ + nodejs \ + inotify-tools + +RUN mkdir /app +WORKDIR /app + +ENTRYPOINT ["sh", "docker-entrypoint.sh"] +CMD ["mix", "phoenix.server"] diff --git a/README.md b/README.md index e59ecac..67b8636 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,21 @@ The user flow is as follows: ## Development Setup -### Prerequisites +There are two ways to set up this application – using Docker or install everything natively on macOS. +In either case you will have to: + +* Clone this repository and +* Copy the `dev.secret.exs.sample` file to `dev.secret.exs` and add the appropriate values + +### Option 1: Use Docker + +* Get [Docker Community Edition for your platform](https://store.docker.com/search?type=edition&offering=community) +* Run `docker-compose up web`. +* Open http://localhost:4000 in your browser + +### Option 2: Native Installation on macOS + +#### Prerequisites The app is built using: @@ -36,7 +50,7 @@ The app is built using: * PostgreSQL `9.4` * Redis `3.2` -#### Homebrew +##### Homebrew Homebrew is a package manger for OSX, we'll use this install `node` and `elixir`. @@ -44,7 +58,7 @@ Homebrew is a package manger for OSX, we'll use this install `node` and `elixir` ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ``` -#### Elixir +##### Elixir Install Elixir via Homebrew @@ -52,11 +66,11 @@ Install Elixir via Homebrew brew install elixir ``` -#### Postgresql +##### Postgresql Install PostgreSQL using the [Postgres.app](http://postgresapp.com) -#### Node.js +##### Node.js Install noedejs via Homebrew @@ -64,7 +78,7 @@ Install noedejs via Homebrew brew install nodejs ``` -#### Redis +##### Redis Install redis via Homebrew @@ -72,16 +86,14 @@ Install redis via Homebrew brew install redis ``` -### Setup +#### Setup -* Clone the repo -* Copy the `dev.secret.exs.sample` file to `dev.secret.exs` and add the appropriate values * Install dependencies with `mix deps.get` * If you get errors here, open a new terminal window. Some commands don't yet have proper binding if you've just installed `elixir` from Homebrew. * Create and migrate your database with `mix ecto.create && mix ecto.migrate` * Install Node.js dependencies with `npm install` -### Running the App +#### Running the App To start the app locally: diff --git a/config/dev.exs b/config/dev.exs index 29de38f..d2a710c 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -36,7 +36,9 @@ config :phoenix, :stacktrace_depth, 20 config :espi_dni, EspiDni.Repo, adapter: Ecto.Adapters.Postgres, database: "espi_dni_dev", - hostname: "localhost", + hostname: System.get_env("DATABASE_HOST") || "localhost", + username: System.get_env("DATABASE_USER") || "postgres", + password: System.get_env("DATABASE_PASSWORD"), pool_size: 10 config :rollbax, @@ -48,7 +50,7 @@ config :rollbax, enabled: :log # configure exq for background jobs with redis config :exq, - host: "127.0.0.1", + host: System.get_env("REDIS_HOST") || "localhost", port: 6379, namespace: "exq", concurrency: 1000, diff --git a/config/test.exs b/config/test.exs index 66f289e..6d6417f 100644 --- a/config/test.exs +++ b/config/test.exs @@ -13,7 +13,9 @@ config :logger, level: :warn config :espi_dni, EspiDni.Repo, adapter: Ecto.Adapters.Postgres, database: "espi_dni_test", - hostname: "localhost", + hostname: System.get_env("DATABASE_HOST") || "localhost", + username: System.get_env("DATABASE_USER") || "postgres", + password: System.get_env("DATABASE_PASSWORD"), pool: Ecto.Adapters.SQL.Sandbox, ownership_timeout: 50_0000 @@ -24,6 +26,14 @@ config :rollbax, # Set rollbar erorrs to just log locally config :rollbax, enabled: :log +# configure exq for background jobs with redis +config :exq, + host: System.get_env("REDIS_HOST") || "localhost", + port: 6379, + namespace: "exq-test", + concurrency: 1000, + queues: ["default"] + config :espi_dni, EspiDni.Plugs.RequireSlackToken, slack_token: "test-slack-token" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..55f28a5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +web: + build: . + volumes: + - .:/app + ports: + - 4000:4000 + links: + - db + - redis + environment: + DATABASE_HOST: db + REDIS_HOST: redis + +db: + image: postgres + ports: + - 5432:5432 + +redis: + image: redis + ports: + - 6379:6379 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..58bee04 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +#set -e + +mix local.hex --force +mix deps.get +mix ecto.create && mix ecto.migrate +npm install + +exec "$@"