D4no0

D4no0

I think it was discussed before not only a single time, however I was unable to find any relevant information using search on elixirforum.

Let’s say we talk about projects containing some kind of secret values, both present for deployed environments and dev. Here are a few ways I’ve usually seen them being set:

  1. Hardcoded for dev in form of a file that is gitignored, for example: dev.secrets.exs, for deployed environments just fetched as a env variable;
  2. Similar to 1st approach in terms of structure, but generated semi-automatically using a mix task or something similar;
  3. Everything set as a environment variable in runtime.exs and using something like direnv to manage them per-project.

I specifically would like to know more about third option, as it seems that overall it makes the configuration more homogeneous in theory. I’ve seen it being implemented in a few recent projects I had to work with and I didn’t like it very much, but once again this might be an issue of implementation.

Any thoughts on this, what is your personal preference?

Showing Posts 1 to 6

cevado

cevado

what I usually do is somewhat the third option but not exactly what you described.
in dev.exs I use the same envvars as runtime.exs but with sensible defaults(like defaulting postgres to localhost, etc). In runtime.exs i check if the apps is compiled for mix env dev or prod, if it’s prod we change to use the envvars but without the defaults, after all we want it to fail if the value is not set.

i’ve never used something like direnv in production settings, just for dev/local. in my last job we used hashicorp’s vault service, it’s quite handy and having versioning in envvars is great. :slight_smile:
but in general i’d go with the thing that fits better your deployment system.

dimitarvp

dimitarvp

While the project is small, env vars and System.get_env! in runtime.exs is quite enough. (And $MIX_ENV.secret.exs as you said, that complements this model nicely.)

The moment you find yourself juggling 15+ env vars and having to parse and validate their values is the moment you should drop all of it and just use Vapor. It’s easy to cringe at its “enterprise”-y offering but I used it in two projects and once you get over the initial learning curve (where you declare the exact location of all your configurable pieces) it just vanishes from view and does its job well. We used it to get data from env vars and YAML files. But I know it can do more than that.

D4no0

D4no0 OP

I think the question is more about dev environments, or better said about how to structure the configuration for both dev and prod in a way that they don’t fight each-other, as on prod the environment those variables are set by the deploy tool.

Do you use any additional tooling (for values that cannot have a default) for initially setting the config? I think usually you would do by having a .env.example file but who knows, maybe you have a better way?

I was thinking that this would be an overkill, however I know for a fact that I will need validation part like really bad very soon for a specific set of projects, so I think it might make sense to adopt it.

The big question is: does it support custom validation functions? We have some very adventurous developers, where they like sitting hours and debugging issues, where they set env variables to something like this: option-1:option-2:option-3, so a full string parse and validation is in order for such values.

dimitarvp

dimitarvp

Yes. I remember one colleague using several.

fuelen

fuelen

I use the 3rd option + confispex library. The idea is simple - you describe a schema for the ENV variables and then just use Confispex.get("MY_VAR") instead of System.get_env("MY_VAR") in runtime.exs. I’ve built this library when our configuration was really hard to manage. Currently, our the biggest project has a config schema with ~260 defined ENV variables. Works pretty well and totally manageable.

Vapor was created before runtime.exs was introduced in Elixir, thus it is more complex.

LostKobrakai

LostKobrakai

While I haven’t had to use a library like confispex I think this is the way to go. Instead of enforcing how env variables are passed – that might always be subject to change and inconsistency – expect the input to be there in any which way the surrounding context wants to do it.

E.g. with a new machine I’ve for now opted to use direnv + 1password cli. I might eventually switch to a more dedicated secrets store over 1password and it’s unlikely that I’ll ever run direnv in production. But I’m certain that I can somehow provide the necessary data as env vars anywhere.

That doesn’t mean one cannot additionally expect devs in development to use a shared tool to get access to secrets and provide them to the app the same way, but I favor making that an independent decision.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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 & 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
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews