Add ReleaseRuntimeProvider for exs config at runtime - #3705
Closed
kloenk wants to merge 1 commit into
Closed
Conversation
This lets the user define elixir code as config
Contributor
|
👋 @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 |
Author
|
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. |
Contributor
|
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
endPR: #3906 |
4 tasks
Contributor
|
I'm going to close this as #3906 has been merged. |
Contributor
|
@kloenk thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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