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 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews