diff --git a/Dockerfile b/Dockerfile index 5e6a3cd55..23f768d9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,6 @@ WORKDIR /app RUN mix local.hex --force RUN mix local.rebar --force -COPY config config COPY mix.* ./ COPY $PHOENIX_DIR/mix.* $PHOENIX_DIR/ @@ -27,6 +26,8 @@ COPY apps/system_engine/mix.* ./apps/system_engine/ RUN mix deps.get RUN mix deps.compile +COPY config config + # Build assets COPY $PHOENIX_DIR/assets $PHOENIX_DIR/assets COPY $PHOENIX_DIR/priv $PHOENIX_DIR/priv @@ -36,13 +37,15 @@ RUN mix phx.digest # Build project COPY $PHOENIX_DIR/lib $PHOENIX_DIR/lib -COPY apps/system_engine/lib ./apps/system_engine/ +COPY apps/system_engine/lib ./apps/system_engine/lib RUN mix compile # Build releases RUN mix release cf_phx RUN mix release system_engine +COPY bin bin + # The built application is now contained in _build/ @@ -58,7 +61,9 @@ ENV PORT=4000 \ RUN mkdir /app WORKDIR /app -COPY --from=builder /app/_build/prod/rel/cf_phx /app/_build/prod/rel/system_engine ./ +COPY --from=builder /app/_build/prod/rel/cf_phx ./cf_phx +COPY --from=builder /app/_build/prod/rel/system_engine ./system_engine +COPY --from=builder /app/bin ./bin RUN chown -R nobody: /app USER nobody diff --git a/bin/start_cf_phx.sh b/bin/start_cf_phx.sh new file mode 100755 index 000000000..34ede2c3c --- /dev/null +++ b/bin/start_cf_phx.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +# migrate DB +cf_phx/bin/cf_phx eval "CfPhx.Release.migrate" + +# start app +cf_phx/bin/cf_phx start diff --git a/config/releases.exs b/config/releases.exs index 1f0f777ea..218fc9c17 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -11,11 +11,6 @@ database_url = For example: ecto://USER:PASS@HOST/DATABASE """ -config :cf_phx, CfPhx.Repo, - # ssl: true, - url: database_url, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10") - secret_key_base = System.get_env("SECRET_KEY_BASE") || raise """ @@ -23,6 +18,11 @@ secret_key_base = You can generate one by calling: mix phx.gen.secret """ +config :cf_phx, CfPhx.Repo, + # ssl: true, + url: database_url, + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10") + config :cf_phx, CfPhxWeb.Endpoint, http: [ port: String.to_integer(System.get_env("PORT") || "4000"), diff --git a/docker-compose.yml b/docker-compose.yml index 185db1eec..9eeb87619 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,9 @@ version: "3.3" services: cf-phx: - command: /app/bin/cf_phx start + depends_on: + - db + command: ["bin/start_cf_phx.sh"] image: cloudfirellc/cloudfire:latest environment: DATABASE_URL: ecto://postgres:postgres@db/cloudfire @@ -11,14 +13,25 @@ services: # Change this for production systems! # !!!!!!!!!!!!! SECRET_KEY_BASE: vw5YEoG6Pb7mCQEC41DjJXIB6v1/tOxO+3YLN+5k+PILkcFMN54g22KXZr6o65Bn + ERL_COOKIE: bSHTSulle4fn4ZgH3CgT6gEEtLiH9leOh1Ykeo4JEEyG31aeDZnDwEWCIhEKM0kF ports: - 4000:4000 networks: - cloudfire system-engine: - command: /app/bin/system_engine start + depends_on: + - db + command: ["system_engine/bin/system_engine", "start"] image: cloudfirellc/cloudfire:latest + environment: + DATABASE_URL: ecto://postgres:postgres@db/cloudfire + + # !! WARNING !! + # Change these for production systems! + # !!!!!!!!!!!!! + SECRET_KEY_BASE: vw5YEoG6Pb7mCQEC41DjJXIB6v1/tOxO+3YLN+5k+PILkcFMN54g22KXZr6o65Bn + ERL_COOKIE: bSHTSulle4fn4ZgH3CgT6gEEtLiH9leOh1Ykeo4JEEyG31aeDZnDwEWCIhEKM0kF networks: - cloudfire diff --git a/mix.exs b/mix.exs index aa4601c09..4f7c834f5 100644 --- a/mix.exs +++ b/mix.exs @@ -9,10 +9,14 @@ defmodule CloudfireUmbrella.MixProject do deps: deps(), releases: [ cf_phx: [ - applications: [cf_phx: :permanent] + applications: [cf_phx: :permanent], + include_executables_for: [:unix], + cookie: System.get_env("ERL_COOKIE") ], system_engine: [ - applications: [system_engine: :permanent] + applications: [system_engine: :permanent], + include_executables_for: [:unix], + cookie: System.get_env("ERL_COOKIE") ] ] ]