Phoenix Umbrella Prod Release Doesn't Start

Hey everyone, I’m hoping you’ll be able to help me with an Elixir Releases issue. I searched the forums for a similar
post, but the one I found, doesn’t apply as the
issue there was a typo.

So, I’m building and following the instructions from here. I’m able to go through
all the steps it outlines without any issues, but since my app is an umbrella application I had to make
a few modifications. Here’s the make target I made to consolidate the steps:

.PHONY: release-build
## release-build: builds a local release version of the app
release-build:
	mix deps.get --only prod && \
	MIX_ENV=prod mix compile && \
	npm install --prefix apps/my_app_web/assets && \
	npm run deploy --prefix apps/my_app_web/assets && \
	mix phx.digest && \
	MIX_ENV=prod mix release --overwrite

My mix.exs file with the release configuration of the release looks like this (with the actual app’s name removed):

  defp releases do
    [
      my_app_web: [
        include_executables_for: [:unix],
        applications: [
          runtime_tools: :permanent
        ]
      ]
    ]
  end

The release is built and run on macOS Catalina 10.15.7. Now, the build works and the _build/prod directory gets
generated without any issues, but when I try starting it with _build/prod/rel/my_app_web/bin/my_app_web start the application
seems like it’s running, but I can’t navigate to the landing page in my browser.

Here’s how I have everything configured:
Elixir is version:

Erlang/OTP 23 [erts-11.1.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.11.1 (compiled with Erlang/OTP 23)

and Phoenix version is 1.5.4. I’m using Runtime Configuration which seems to be set properly when I start-up iex:

# config/runtime.exs file
import Config

if config_env() == :prod do
  config :my_app_web,
         MyAppWeb.Endpoint,
         server: true,
         http: [
           port: String.to_integer(System.fetch_env!("MA_PORT")),
           transport_options: [
             socket_opts: [:inet6]
           ]
         ],
         secret_key_base: System.fetch_env!("MA_SECRET_KEY_BASE"),
         basic_auth: [
           username: System.fetch_env!("MA_BASIC_AUTH_USERNAME"),
           password: System.fetch_env!("MA_BASIC_AUTH_PASSWORD")
         ]

  config :my_app,
         MyApp.Repo,
         url: System.fetch_env!("MA_DATABASE_URL")
end
# :my_app_web config
[
  {MyAppWeb.Endpoint,
   [
     render_errors: [
       view: MyAppWeb.ErrorView,
       accepts: ["html", "json"],
       layout: false
     ],
     pubsub_server: MyApp.PubSub,
     live_view: [signing_salt: "signing_salt"],
     url: [host: "MyApp.com", port: 80],
     cache_static_manifest: "priv/static/cache_manifest.json",
     server: true,
     http: [port: 8080, transport_options: [socket_opts: [:inet6]]],
     secret_key_base: "secret_key_base",
     basic_auth: [username: "admin", password: "admin"]
   ]}
]
# :my_app config
[
  {:generators, [context_app: false]},
  {MyApp.Repo,
   [url: "ecto://postgres:postgres@localhost/my_app_development"]},
  {:ecto_repos, [MyApp.Repo]}
]

What is interesting is that if I start the app with _build/prod/rel/my_app_web/bin/my_app_web start_iex and then
try to call a function on one of my modules, say MyApp.Marketing.LifeCoachingLeads.list_life_coaching_leads, then I get:

** (UndefinedFunctionError) function MyApp.Marketing.LifeCoachingLeads.list_life_coaching_leads/0 is undefined (module MyApp.Marketing.LifeCoachingLeads is not available)
    MyApp.Marketing.LifeCoachingLeads.list_life_coaching_leads()

Which makes me think my release isn’t finding the modules it needs to start up, but it’s not obvious to me why.
Any pointers in the right direction would be fantastic!

1 Like

Awesome job debugging things so far! Inside your release, you are going to find out a releases/VSN directory where VSN is the current version. Inside that directory, there is a start.script file with all steps the Erlang VM takes to boot the app. When you inspect this file, can you see your applications there?

Another way to debug is: try adding a IO.inspect :OMG to start/2 in your lib/my_app_web/application.ex and see if it is printed when you start the release.

1 Like

I see it on the second line of the file:

%% coding: utf-8
{script,
    {"my_app_web","0.1.0"},
# bunch of other stuff

The file contains a lot of built-in Elixir modules Elixir.Calendar.ISO, Elixir.Map, and a lot of other modules, but none of the ones I’ve implemented.

I didn’t event think of this! I gave it a shot but I don’t see :OMG on startup either. I thought maybe I had setup the config/runtime.exs file wrong too, so I created a config/releases.exs file and put the configs in there and ran the app, but it still doesn’t start even though I see the proper start up message:

Check your digested files at "priv/static"
* assembling fit_whitt_it_web-0.1.0 on MIX_ENV=prod
* using config/releases.exs to configure the release at runtime
other stuff ...

That’s only the script name. Go to the end of the file and see if your apps are being started.

One thing to keep in mind though is that in an umbrella you have to explicitly include your umbrella children in the list of applications given to the release.

1 Like

Thanks @josevalim! That was the root of the issue. I took this portion of the docs too literally:

[
        include_executables_for: [:unix],
        applications: [runtime_tools: :permanent]
      ],

I mistook runtime_tools for a config option instead of being the name of the app to include in the release. Once I replaced it with my apps actual name it worked. I really appreciate the help!