-
-
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
Conversation
@@ -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 comment
The 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_dir = System.get_env("CONFIG_DIR", "/run/secrets") | ||
|
||
if extra_config_path = get_var_from_path_or_env(config_dir, "EXTRA_CONIFG_PATH") do | ||
import_config extra_config_path |
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 intermediate config file is needed as runtime.exs
is forbidden from importing other configs
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.
From https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-runtime-configuration
It MUST NOT import any other configuration file via import_config
@@ -19,8 +19,10 @@ defmodule Plausible.MixProject do | |||
releases: [ | |||
plausible: [ | |||
include_executables_for: [:unix], | |||
applications: [plausible: :permanent], |
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
{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 comment
The 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=https://localhost:8000 \
-e SECRET_KEY_BASE=FQ9iAQSkUx4peZfjRT9AIcX2iUupTYIPH90GbRS42NDUYQUcVzaTEARzK8NBRpVO \
-e TOTP_VAULT_KEY=ykRRyEnKQX8jJ0zrE3rn91U0jluSsnevOGnQO2fTYUg= \
-e DATABASE_URL=ecto:https://postgres:[email protected]:5432/plausible_dev \
-e CLICKHOUSE_DATABASE_URL=https://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:https://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 comment
The 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.
Changes
This PR allows importing extra config as suggested in #3705 (comment)
It can serve as an easy escape hatch for specifying configurations not covered by env vars. Like #3823
Example:
my_config.exs
docker-compose.yml
plausible-conf.env
+ EXTRA_CONFIG_PATH=/app/my_config.exs
Tests
Changelog
Documentation
Dark mode