Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker development environment #4

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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