I want to deploy two phoenix apps

I want to deploy two phoenix apps on two different ports. it works perfectly in dev mode. but when I create a release with distillary it only serves one app on the given port. here is my configuration rel/config for these apps:

release :backend do
  set version: "0.1.0"
  set applications: [
    :runtime_tools,
    backend: :permanent
  ]
end

release :admin do
  set version: "0.1.0"
  set applications: [
    :runtime_tools,
    admin: :permanent,
    backend: :permanent
  ]
end

any help will be really appreciated

and in admin prod.exs I have

config :admin, AdminWeb.Endpoint,
  load_from_system_env: true,
  http: [port: "${ADMIN_PORT}"],
  url: [host: "localhost", port: "${ADMIN_PORT}"],
  code_reloader: false,
  server: true

similary in backend app

Can you try Map.fetch!(System.get_env(), "YOUR_ENV_VAR) and report back?
Here is an example of it: https://hexdocs.pm/phoenix/heroku.html#making-our-project-ready-for-heroku

Hope it helps(actual variable name is ADMIN_PORT)

iex(haitracker_admin@127.0.0.1)4> Map.fetch!(System.get_env(), "ADMIN_PORT")
"4005"
iex(haitracker_admin@127.0.0.1)5> Map.fetch!(System.get_env(), "BACKEND_PORT")      
"4004"
iex(haitracker_admin@127.0.0.1)6>

Thats how I am running release

REPLACE_OS_VARS=true _build/prod/rel/haitracker_admin/bin/haitracker_admin console
Erlang/OTP 21 [erts-10.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]

16:07:11.460 [info] Running Backend.Endpoint with Cowboy using http://0.0.0.0:4004
16:07:11.501 [info] Running AdminWeb.Endpoint with Cowboy using http://:::4004
Interactive Elixir (1.7.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(haitracker_admin@127.0.0.1)1>

You can also see the apps started in console(Admin app dont know on which host though)

You’re not overriding the settings on each app’s endpoint.ex init/2 by any chance?

4 Likes

I just commented init/2 and it worked like a charm, Thanks

2 Likes

Cool, deploy that, let’s see what happens?

2 Likes

I’ve been bitten by this before too, although with Ecto Repo configuration instead of a Phoenix Endpoint. One way that this would surface is by checking the actual live configuration with a command like:

Application.get_all_env(:admin)

Although of course that won’t tell you what changed the configuration.

1 Like