slogger

slogger

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!

Showing Posts 1 to 2

LostKobrakai

LostKobrakai

I’m not sure Distillery even supports runtime.exs. At least the error you showed doesn’t match the code. String.to_integer can never return nil. I’d suggest using mix release unless you actually need hot code updates, which is imo the only reason one would be using distillery for today.

slogger

slogger OP

I will look at using mix release
I dont need hot code updates.
Thank you!

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews