diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..2c6769f --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,14 @@ +# Used by docker-compose.yml +FROM hexpm/elixir:1.12.0-erlang-24.0.1-debian-bullseye-20210902-slim + +RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential dialog apt-utils gpg-agent \ + apt-transport-https software-properties-common git curl postgresql-client inotify-tools && \ + mix local.hex --force && \ + mix archive.install hex phx_new 1.6.7 --force && \ + mix local.rebar --force && \ + apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +WORKDIR /app +COPY . . +EXPOSE 4000 +CMD /bin/sh -c "while sleep 1000; do :; done" \ No newline at end of file diff --git a/config/runtime.exs b/config/runtime.exs index ce760a4..bef422a 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -11,6 +11,30 @@ if System.get_env("PHX_SERVER") && System.get_env("RELEASE_NAME") do config :live_beats, LiveBeatsWeb.Endpoint, server: true end +# Used by Dockerfile.dev. +if System.get_env("DEV_CONTAINER") do + database_url = + System.get_env("DATABASE_URL") || + raise """ + environment variable DATABASE_URL is missing. + For example: ecto://USER:PASS@HOST/DATABASE + """ + + replica_database_url = + System.get_env("REPLICA_DATABASE_URL") || database_url + + config :live_beats, LiveBeats.Repo, + url: database_url, + show_sensitive_data_on_connection_error: true, + pool_size: 10 + + config :live_beats, LiveBeats.ReplicaRepo, + url: replica_database_url, + show_sensitive_data_on_connection_error: true, + pool_size: 10, + priv: "priv/repo" +end + if config_env() == :prod do database_url = System.get_env("DATABASE_URL") || diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3bad75c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: "3" +services: + web: + container_name: "live_beats_dev" + build: + context: . + dockerfile: Dockerfile.dev + environment: + # Review the readme on how to register a github oauth app. + LIVE_BEATS_GITHUB_CLIENT_ID: "FIX_ME" + LIVE_BEATS_GITHUB_CLIENT_SECRET: "FIX_ME" + DEV_CONTAINER: "true" + DATABASE_URL: "ecto://postgres:postgres@db/live_beats_dev" + depends_on: + - db + ports: + - "4000:4000" + db: + container_name: "live_beats_data" + image: "postgres:14.2" + command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.max=10000 -c pg_stat_statements.track=all + environment: + POSTGRES_DB: "live_beats_dev" + POSTGRES_HOST_AUTH_METHOD: "trust" + ports: + - "5432:5432" + volumes: + - data:/var/lib/postgresql/data +volumes: + data: + driver: local