-
-
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
Allow importing extra config #3906
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,10 @@ defmodule Plausible.MixProject do | |
releases: [ | ||
plausible: [ | ||
include_executables_for: [:unix], | ||
applications: [plausible: :permanent], | ||
steps: [:assemble, :tar] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are copying all rel/ files directly, the tar archive ends up being unused. |
||
config_providers: [ | ||
{Config.Reader, | ||
path: {:system, "RELEASE_ROOT", "/import_extra_config.exs"}, imports: []} | ||
] | ||
] | ||
], | ||
dialyzer: [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Config | ||
import Plausible.ConfigHelpers | ||
|
||
config_dir = System.get_env("CONFIG_DIR", "/run/secrets") | ||
|
||
if extra_config_path = get_var_from_path_or_env(config_dir, "EXTRA_CONFIG_PATH") do | ||
import_config extra_config_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This intermediate config file is needed as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-runtime-configuration
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,6 +264,44 @@ defmodule Plausible.ConfigTest do | |
end | ||
end | ||
|
||
describe "extra config" do | ||
test "no-op when no extra path is set" do | ||
put_system_env_undo({"EXTRA_CONFIG_PATH", nil}) | ||
|
||
assert Config.Reader.read!("rel/overlays/import_extra_config.exs") == [] | ||
end | ||
|
||
test "raises if path is invalid" do | ||
put_system_env_undo({"EXTRA_CONFIG_PATH", "no-such-file"}) | ||
|
||
assert_raise File.Error, ~r/could not read file/, fn -> | ||
Config.Reader.read!("rel/overlays/import_extra_config.exs") | ||
end | ||
end | ||
|
||
@tag :tmp_dir | ||
test "reads extra config", %{tmp_dir: tmp_dir} do | ||
extra_config_path = Path.join(tmp_dir, "config.exs") | ||
|
||
File.write!(extra_config_path, """ | ||
import Config | ||
|
||
config :plausible, Plausible.Repo, | ||
after_connect: {Postgrex, :query!, ["SET search_path TO global_prefix", []]} | ||
""") | ||
|
||
put_system_env_undo({"EXTRA_CONFIG_PATH", extra_config_path}) | ||
|
||
assert Config.Reader.read!("rel/overlays/import_extra_config.exs") == [ | ||
{:plausible, | ||
[ | ||
{Plausible.Repo, | ||
[after_connect: {Postgrex, :query!, ["SET search_path TO global_prefix", []]}]} | ||
]} | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've also tried it out locally: docker run --rm -d \
-v ./my_config.exs:/app/my_config.exs \
-e EXTRA_CONFIG_PATH=my_config.exs \
-e BASE_URL=http://localhost:8000 \
-e SECRET_KEY_BASE=FQ9iAQSkUx4peZfjRT9AIcX2iUupTYIPH90GbRS42NDUYQUcVzaTEARzK8NBRpVO \
-e TOTP_VAULT_KEY=ykRRyEnKQX8jJ0zrE3rn91U0jluSsnevOGnQO2fTYUg= \
-e DATABASE_URL=ecto://postgres:[email protected]:5432/plausible_dev \
-e CLICKHOUSE_DATABASE_URL=http://172.17.0.3:8123/plausible_events_db \
plausible:local $ ls
bin erts-14.2.1 init-admin.sh migrate.sh pending-migrations.sh rollback.sh
createdb.sh import_extra_config.exs lib my_config.exs releases seed.sh
$ cat my_config.exs
import Config
config :plausible, Plausible.Repo,
after_connect: {Postgrex, :query!, ["SET search_path TO public", []]}
config :plausible, a: :b
$ bin/plausible remote
Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Interactive Elixir (1.16.0) - press Ctrl+C to exit (type h() ENTER for help) iex(plausible@7f241994598d)1> Application.get_env :plausible, Plausible.Repo
[
timeout: 300000,
connect_timeout: 300000,
handshake_timeout: 300000,
url: "ecto://postgres:[email protected]:5432/plausible_dev",
socket_options: [],
ssl_opts: [
cacertfile: "/app/lib/castore-1.0.5/priv/cacerts.pem",
verify: :verify_peer,
customize_hostname_check: [
match_fun: #Function<6.117093159/2 in :public_key.pkix_verify_hostname_match_fun/1>
]
],
after_connect: {Postgrex, :query!, ["SET search_path TO public", []]}
]
iex(plausible@7f241994598d)2> Application.get_env :plausible, :a
:b There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't come up with a simple test that would check that extra config overrides runtime.exs, but it does. |
||
end | ||
end | ||
|
||
defp runtime_config(env) do | ||
put_system_env_undo(env) | ||
Config.Reader.read!("config/runtime.exs", env: :prod) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of the default applications