-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ReleaseRuntimeProvider for exs config at runtime #3705
Conversation
This lets the user define elixir code as config
👋 @kloenk I think this should be already possible by mounting a custom $ docker run --rm -t ghcr.io/ruslandoga/analytics:my-build ls releases/0.0.1
consolidated iex runtime.exs start_clean.boot vm.args
elixir plausible.rel start.boot start_clean.script
env.sh remote.vm.args start.script sys.config
$ docker run --rm -t ghcr.io/ruslandoga/analytics:my-build head releases/0.0.1/runtime.exs
import Config
import Plausible.ConfigHelpers
require Logger
if config_env() in [:dev, :test] do
Envy.load(["config/.env.#{config_env()}"])
end
if config_env() == :small_dev do
Envy.load(["config/.env.dev"])
$ docker run --rm -t -v ./config.exs:/app/releases/0.0.1/runtime.exs ghcr.io/ruslandoga/analytics:my-build head releases/0.0.1/runtime.exs
import Config
raise "oops"
$ docker run --rm -t -v ./config.exs:/app/releases/0.0.1/runtime.exs ghcr.io/ruslandoga/analytics:my-build
ERROR! Config provider Config.Reader failed with:
** (RuntimeError) oops
/app/releases/0.0.1/runtime.exs:3: (file)
(elixir 1.16.0) src/elixir.erl:405: :elixir.eval_external_handler/3
(stdlib 5.2) erl_eval.erl:750: :erl_eval.do_apply/7
(elixir 1.16.0) src/elixir.erl:378: :elixir.eval_forms/4
(elixir 1.16.0) lib/module/parallel_checker.ex:112: Module.ParallelChecker.verify/1
(elixir 1.16.0) lib/code.ex:568: Code.validated_eval_string/3
(elixir 1.16.0) lib/config.ex:290: Config.__eval__!/3
(elixir 1.16.0) lib/config/reader.ex:92: Config.Reader.read!/2 |
As I don't use docker and my package gets installed into a immutable place (nix) this is less convenient. So the approach in this PR would be favorable for me, but I could work around it as well. |
Right, I think allowing extra config might be a useful escape hatch for the configurations not covered by the current env vars (like #3799). I explored a bit and it seems like it isn't necessary to implement a custom config reader. The default one could be reused and there are multiple ways to do it, here's the approach I like:
mix.exs defp releases do
[
plausible: [
config_providers: [
{Config.Reader, path: {:system, "RELEASE_ROOT", "/import_config.exs"}, imports: []}
]
]
]
end
rel/overlays/import_config.exs import Conifg
if extra_config_path = System.get_env("EXTRA_CONFIG_PATH") do
import_config extra_config_path
end PR: #3906 |
I'm going to close this as #3906 has been merged. |
@kloenk thank you! |
Changes
This lets the user define elixir code as config.
I plane to use this in my approach for OIDC as with this the config can easily define functions to apply roles base on claims in the token.
Tests
Changelog
At this time the config is just an extra way to configure, so the user does not yet have to be aware of it.
Documentation
Dark mode