Mix release start inside docker contain works with 'rpc' but not with 'eval'

Hi all,

I’m trying to get a Phoenix app into a deployable state in a docker container. I can get it up and running no problem if I point it to an existing and migrated postgres DB.

When I tried to running migrations I ran into the following problem. When running via ‘eval’ I get the following errors.

./prod/rel/my_app/bin/my_app eval "MyApp.Release.ReleaseTasks.migrate(1)"

where is ‘ReleaseTask’ is a utility module to run the migrations, I get the following.

19:14:43.890 [error] GenServer #PID<0.227.0> terminating
** (RuntimeError) connect raised KeyError exception: key :database not found. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the details
    (elixir 1.10.4) lib/keyword.ex:399: Keyword.fetch!/2
    (postgrex 0.15.3) lib/postgrex/protocol.ex:92: Postgrex.Protocol.connect/1
    (db_connection 2.2.1) lib/db_connection/connection.ex:69: DBConnection.Connection.connect/2
    (connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.12.1) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

In the repo section of ‘releases.exs’ I set :show_sensitive_data_on_connection_error to true but that configuration is never picked up.

Now, here’s the confusing part. If I run in ‘rpc’ move rather than ‘eval’ mode. It works fine. That is:

./prod/rel/my_app/bin/my_app rpc "MyApp.Release.ReleaseTasks.migrate(1)"

It works totally fine. Even though I got the DB migrated, I’d still like to understand what’s going on. I’d like to know:

  1. why ‘eval’ mode did not work at all.
  2. why show_sensitive_data_on_connection_error: true had no effect? As in I’m not running the config I think I’m running.
  3. why ‘rpc’ mode did work.

Thanks,
Adam

Can you share your MyApp.Release.ReleaseTasks? In particular make sure that you are loading the application that configures the ecto repositories, as shown here: https://hexdocs.pm/phoenix/releases.html#ecto-migrations-and-custom-commands

From the looks of it, it seems your configuration is simply not being loaded. It works on “rpc” because that asks the existing node to migrate and that one loads all configs upfront for you.

Thanks Jose,

That was super helpful. I did not see that simplified MyApp.Release example and found a more complicated one elsewhere. That complicated one did not load the config properly when run via ‘eval’.

Simplified

I got this to work. I had a more complicated Release file found elsewhere on the web. When I used the one in the linked site, it worked perfectly.

Super helpful.

1 Like