Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions lib/plausible/config/release_runtime_provider.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule Plausible.Config.ReleaseRuntimeProvider do
@moduledoc false
@behaviour Config.Provider

@impl Config.Provider
def init(opts), do: opts

@impl Config.Provider
def load(config, opts) do
config_path =
opts[:config_path] || System.get_env("PLAUSIBLE_CONFIG_PATH") ||
"/etc/plausible/config.exs"

with_runtime_config =
if File.exists?(config_path) do
runtime_config = Config.Reader.read!(config_path)

config
|> Config.Reader.merge(
plausible: [
config_path: config_path
]
)
|> Config.Reader.merge(runtime_config)
else
# enable to warn should the runtime.exs environment config should get deprecated
# warning = [
# IO.ANSI.red(),
# IO.ANSI.bright(),
# "!!! Config path is not declared! Please ensure it exists and that PLAUSIBLE_CONFIG_PATH is unset or points to an existing file",
# IO.ANSI.reset()
# ]

# IO.puts(warning)
config
end

with_runtime_config
end
end
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule Plausible.MixProject do
plausible: [
include_executables_for: [:unix],
applications: [plausible: :permanent],
config_providers: [{Plausible.Config.ReleaseRuntimeProvider, []}],
steps: [:assemble, :tar]
]
],
Expand Down