Hello Community!
My team has recently started using Elixir and Phoenix.
Im responsible for deploying our applications.
My main experience so far is with Javascript and Golang. I only have started working with Elixir in the last few weeks.
Im struggling to understand how environment variables are supposed to work in Elixir.
Im using Distillery to create my releases and am deploying them with Docker.
After much research (Googling!) it seems that config/runtime.exs is the place to put my environment variables.
Here is my runtime.exs
import Config
config :wb_iot,
ecto_repos: [WB.IOT.Persistence.Repo]
config :wb_iot, WB.IOT.Persistence.Repo,
database: System.get_env("DATABASE_NAME", "wb_iot"),
username: System.get_env("DATABASE_USERNAME", "postgres"),
password: System.get_env("DATABASE_PASSWORD", "postgres"),
hostname: System.get_env("DATABASE_HOST_NAME", "localhost"),
port: String.to_integer(System.get_env("DATABASE_PORT", "5432")),
pool_size: 10,
migration_timestamps: [type: :utc_datetime_usec]
config :broadway_kafka,
hosts: System.get_env("KAFKA_HOSTS", "localhost:9092"),
group_id: System.get_env("KAFKA_GROUP_ID", "wb_iot"),
topics: [System.get_env("KAFKA_TOPICS", "message")]
config :redix,
host: System.get_env("REDIS_HOST", "localhost"),
port: String.to_integer(System.get_env("REDIS_PORT", "6379"))
I am accessing them in the modules as follows:
Application.get_env(:broadway_kafka, :hosts)
I then build my Docker image which completes successfully.
It doesnt seem like my environment variables are being picked up - even the defaults! - as the app crashes with the values being nil.
application_start_failure,wb_iot,{{shutdown,{failed_to_start_child,âElixir.Redixâ,{âEXITâ,{#{âexceptionâ => true,âstructâ => âElixir.ArgumentErrorâ,message => <<"expected an integer as the value of the :port option, got: nil">>}
Ive tried multiple variations, but I cant seem to get this to work.
Does Elixir manage this âper environmentâ config differently?
Thank you!