Set Kafka envs on runtime instead of compile time

This commit is contained in:
2022-02-21 08:13:49 +01:00
parent a48a320691
commit 11140e3ecc
2 changed files with 13 additions and 21 deletions

View File

@@ -13,19 +13,7 @@ if System.get_env("PHX_SERVER") && System.get_env("RELEASE_NAME") do
end
if config_env() == :prod do
# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
# want to use a different value for prod and you most likely don't want
# to check this value into version control, so we use an environment
# variable instead.
secret_key_base =
System.get_env("SECRET_KEY_BASE") ||
raise """
environment variable SECRET_KEY_BASE is missing.
You can generate one by calling: mix phx.gen.secret
"""
host = System.get_env("PHX_HOST") || "example.com"
host = System.get_env("PHX_HOST") || "localhost"
port = String.to_integer(System.get_env("PORT") || "4000")
config :kafkaex_lag_exporter, KafkaexLagExporterWeb.Endpoint,
@@ -37,8 +25,7 @@ if config_env() == :prod do
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: port
],
secret_key_base: secret_key_base
]
# ## Using releases
#
@@ -50,3 +37,14 @@ if config_env() == :prod do
# Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information.
end
{port, _} = System.fetch_env!("KAFKA_BROKER_PORT")
|> Integer.parse
config :kafka_ex,
brokers: [
{System.fetch_env!("KAFKA_BROKER1_HOST"), port},
{System.fetch_env!("KAFKA_BROKER2_HOST"), port},
{System.fetch_env!("KAFKA_BROKER3_HOST"), port},
]