From 32d7abe6b77df6fc0652d680326be19e60c4e6e5 Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Fri, 8 Sep 2023 08:45:09 -0700 Subject: [PATCH] wip compose --- Dockerfile.dev | 20 +++++++++++++++++ config/dev.exs | 4 ++-- config/test.exs | 4 ++-- dev.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 18 ++++++++++++++++ 5 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 Dockerfile.dev create mode 100755 dev.sh create mode 100644 docker-compose.yml diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..e997b70 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,20 @@ +# Elixir + Phoenix + +FROM elixir:1.9.4 + +# Install debian packages +RUN apt-get update +RUN apt-get install --yes build-essential inotify-tools postgresql-client + +# Install Phoenix packages +RUN mix local.hex --force +RUN mix local.rebar --force +RUN mix archive.install --force https://github.com/phoenixframework/archives/raw/master/phx_new.ez + +# Install node +RUN curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh +RUN bash nodesource_setup.sh +RUN apt-get install --yes nodejs npm + +WORKDIR /app +EXPOSE 4000 diff --git a/config/dev.exs b/config/dev.exs index d7aa06b..b172575 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -3,8 +3,8 @@ import Config # Configure your database config :emoji, Emoji.Repo, username: "postgres", - password: "postgres", - hostname: "localhost", + password: System.get_env("DB_PASS", "postgres"), + hostname: System.get_env("DB_HOST", "localhost"), database: "emoji_dev", stacktrace: true, show_sensitive_data_on_connection_error: true, diff --git a/config/test.exs b/config/test.exs index a3e541d..a72c267 100644 --- a/config/test.exs +++ b/config/test.exs @@ -7,8 +7,8 @@ import Config # Run `mix help test` for more information. config :emoji, Emoji.Repo, username: "postgres", - password: "postgres", - hostname: "localhost", + password: System.get_env("DB_PASS", "postgres"), + hostname: System.get_env("DB_HOST", "localhost"), database: "emoji_test#{System.get_env("MIX_TEST_PARTITION")}", pool: Ecto.Adapters.SQL.Sandbox, pool_size: 10 diff --git a/dev.sh b/dev.sh new file mode 100755 index 0000000..4a16fbd --- /dev/null +++ b/dev.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# Adapted from Alex Kleissner's post, Running a Phoenix 1.3 project with docker-compose +# https://medium.com/@hex337/running-a-phoenix-1-3-project-with-docker-compose-d82ab55e43cf + +set -e + + +# Ensure the app's dependencies are installed +mix deps.get + +# Prepare Dialyzer if the project has Dialyxer set up +if mix help dialyzer >/dev/null 2>&1 +then + echo "\nFound Dialyxer: Setting up PLT..." + mix do deps.compile, dialyzer --plt +else + echo "\nNo Dialyxer config: Skipping setup..." +fi + +# Install JS libraries +# echo "\nInstalling JS..." +# cd assets && npm install +# cd .. + +# Wait for Postgres to become available. +until psql -h db -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..." + +#Analysis style code +# Prepare Credo if the project has Credo start code analyze +if mix help credo >/dev/null 2>&1 +then + echo "\nFound Credo: analyzing..." + mix credo || true +else + echo "\nNo Credo config: Skipping code analyze..." +fi + +# Potentially Set up the database +mix ecto.create +mix ecto.migrate + +echo "\nTesting the installation..." +# "Prove" that install was successful by running the tests +mix test + +echo "\n Launching Phoenix web server..." +# Start the phoenix web server +mix phx.server diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..26de352 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.8' +services: + web: + build: . + command: "./dev.sh" + ports: + - "4000:4000" + volumes: + - .:/app + depends_on: + - db + environment: + - DB_PASS= + - DB_HOST=db + - MIX_ENV=dev + + db: + image: postgres