bitwalker / distillery

Simplify deployments in Elixir with OTP releases!
MIT License
2.96k stars 398 forks source link

include_erts: true (on master as well) causes configuration not to be loaded in a custom command #570

Closed bjuretic closed 5 years ago

bjuretic commented 5 years ago

Release config is pretty typical:

release :auth_service do
  set version: current_version(:auth_service)
  set config_providers: [
        {Mix.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/config.exs"]}
      ]
  set overlays: [
        {:copy, "rel/config/config.exs", "etc/config.exs"}
      ]
  set applications: [
        :runtime_tools,
        :auth_service
      ]
  set commands: [
        migrate: "rel/commands/migrate.sh",
        seed: "rel/commands/seed.sh"
      ]
end

and environment :prod has include_erts: false (also tried with :dev environment - same issue).

When include_erts is :true, configuration is available in custom command:

#!/usr/bin/env bash

release_ctl eval "IO.inspect(Application.get_all_env(:auth_service))"

When I run a custom command:

$ _build/dev/rel/auth_service/bin/auth_service migrate
  {:environment, :dev},
  {:ecto_repos, [Auth.Repo]},
  {Auth.Repo,
   [
     adapter: Ecto.Adapters.Postgres,
     types: Db.PostgresTypes,
     database: "xxxxx",
     username: "xxx",
     password: "xxx",
     hostname: "localhost",
     port: "5432"
   ]}
]

But when ERTS is not included (and the release is run locally - so the same ERTS version used to compile it), this happens:

$ _build/dev/rel/auth_service/bin/auth_service migrate
[]
Starting dependencies..
Starting repos..
** (EXIT from #PID<0.90.0>) an exception was raised:
    ** (ArgumentError) configuration for Auth.Repo not specified in :auth_service environment

... so no config is loaded.

I've checked, the config.exs is indeed present in etc/config.exs and all seems to be in order on that level.

BTW I have to say you are doing a heroic work on the whole release story for Elixir. The problem is Erlang VM was never made for what we are using it. It requires a big overhaul internally, then you wouldn't need to solve a million of small problems.

imranismail commented 5 years ago

@bjuretic this might be related to #568

bugant commented 5 years ago

I'm also having the same issue. Notice that configuration are correctly loaded if I run, for example, the remote_console command or when starting the app (for example, with the foreground command).

imranismail commented 5 years ago

@bugant have you ever had issues with the start command?

bugant commented 5 years ago

@imranismail never tried start, I always start the app with foreground, will give it a try as soon as I can.

bitwalker commented 5 years ago

Just to be clear, configuration is only loaded in custom commands if the release has already been started (or at least run) and the sys.config file has been generated. If you need to generate the configs without starting the release for your custom command, then you will want to invoke the configure_release function from your command before doing anything else, this will ensure those configs are generated and that the env vars are set so that any subsequent commands will pick up those configs.

bugant commented 5 years ago

@bitwalker this is not clear to me. I'm following this guide https://hexdocs.pm/distillery/guides/running_migrations.html but still have the same error:

Starting repos..
** (EXIT from #PID<0.92.0>) an exception was raised:
    ** (ArgumentError) configuration for MyApp.Repo not specified in :my_app environment
        (ecto) lib/ecto/repo/supervisor.ex:32: Ecto.Repo.Supervisor.runtime_config/4
        (ecto) lib/ecto/repo/supervisor.ex:153: Ecto.Repo.Supervisor.init/1
        (stdlib) supervisor.erl:295: :supervisor.init/1
        (stdlib) gen_server.erl:374: :gen_server.init_it/2
        (stdlib) gen_server.erl:342: :gen_server.init_it/6
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
oladipo commented 5 years ago

@bitwalker this is not clear to me. I'm following this guide https://hexdocs.pm/distillery/guides/running_migrations.html but still have the same error:

Starting repos..
** (EXIT from #PID<0.92.0>) an exception was raised:
    ** (ArgumentError) configuration for MyApp.Repo not specified in :my_app environment
        (ecto) lib/ecto/repo/supervisor.ex:32: Ecto.Repo.Supervisor.runtime_config/4
        (ecto) lib/ecto/repo/supervisor.ex:153: Ecto.Repo.Supervisor.init/1
        (stdlib) supervisor.erl:295: :supervisor.init/1
        (stdlib) gen_server.erl:374: :gen_server.init_it/2
        (stdlib) gen_server.erl:342: :gen_server.init_it/6
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Did you find a way around this issue?