Allow importing extra config (#3906)

* allow importing extra config

* changelog

* fix typo

* add test
pull/3901/merge
ruslandoga 3 years ago committed by GitHub
parent dfcc8d794a
commit 4242b52be4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -31,6 +31,7 @@ All notable changes to this project will be documented in this file.
- Add 'browser_versions.csv' to CSV export - Add 'browser_versions.csv' to CSV export
- Add `CLICKHOUSE_MAX_BUFFER_SIZE_BYTES` env var which defaults to `100000` (100KB) - Add `CLICKHOUSE_MAX_BUFFER_SIZE_BYTES` env var which defaults to `100000` (100KB)
- Add alternative SMTP adapter plausible/analytics#3654 - Add alternative SMTP adapter plausible/analytics#3654
- Add `EXTRA_CONFIG_PATH` env var to specify extra Elixir config plausible/analytics#3906
### Removed ### Removed
- Removed the nested custom event property breakdown UI when filtering by a goal in Goal Conversions - Removed the nested custom event property breakdown UI when filtering by a goal in Goal Conversions

@ -19,8 +19,10 @@ defmodule Plausible.MixProject do
releases: [ releases: [
plausible: [ plausible: [
include_executables_for: [:unix], include_executables_for: [:unix],
applications: [plausible: :permanent], config_providers: [
steps: [:assemble, :tar] {Config.Reader,
path: {:system, "RELEASE_ROOT", "/import_extra_config.exs"}, imports: []}
]
] ]
], ],
dialyzer: [ dialyzer: [

@ -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
end

@ -272,6 +272,44 @@ defmodule Plausible.ConfigTest do
end end
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", []]}]}
]}
]
end
end
defp runtime_config(env) do defp runtime_config(env) do
put_system_env_undo(env) put_system_env_undo(env)
Config.Reader.read!("config/runtime.exs", env: :prod) Config.Reader.read!("config/runtime.exs", env: :prod)

Loading…
Cancel
Save