Avoiding setting env vars for remote_console with distillery when using config providers

I’m using the mix config provider with distillery

    overlays: [
      {:copy, "rel/etc/myapp.service", "etc/myapp.service"},
      {:copy, "rel/etc/config.exs", "etc/config.exs"}

    config_providers: [
      {Mix.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/config.exs"]}

and in it I’m reading some env vars from the system like this

use Mix.Config

env! = fn var, type ->
  val = System.get_env(var) || raise("need #{var} set")

  try do
    case type do
      :string -> val
      :integer -> String.to_integer(val)
    _error ->
      raise(ArgumentError, "couldn't parse #{val} as #{type}")

config :myapp,
  db_path: env!.("DB_PATH", :string)

config :web, Web.Endpoint,
  http: [:inet6, port: env!.("WEB_PORT", :integer)],
  secret_key_base: env!.("WEB_SECRET_KEY_BASE", :string)

This makes bin/myapp remote_console fail, since none of the env vars (DB_PATH, WEB_PORT, WEB_SECRET_KEY_BASE) are provided (DB_PATH="" WEB_PORT=0 WEB_SECRET_KEY_BASE="" bin/myapp remote_console works). Is there a way around this?

That is, is there a way to only run the config for start, console, foreground, and not for remote_console?

One way would be to create a custom command my_remote_console which would execute DB_PATH="" WEB_PORT=0 WEB_SECRET_KEY_BASE="" bin/myapp remote_console.

1 Like