rockneurotiko

rockneurotiko

Config Tuples - Use config tuples on Distillery 2.0 releases

Hi!

I’ve just released the first version of ConfigTuples, a Distillery’s 2.0 config provider to read what I call configuration tuples.

  • What are configuration tuples?
    This is the way I call the tuples that some libraries accept (and some libraries transform to normal configuration, like deferred_config) and some people in the community likes, this are the {:system, name} tuples and their family.

  • Why?
    If the library don’t support this kind of tuples you can’t easily set them up . Because I think this way of configuration for dynamic variables that come from the system environment is the most elegant way.

  • What tuples are supported?
    In the version 0.1.0 the supported tuples are: {:system, env_name}, {:system, env_name, default}, {:integer, value}, {:atom, value}, {:boolean, value}, this last three the value can be another config tuple, so for example you can read an integer from the environment system :smile:

I’m open to all your comments and thoughts, and they are more than welcome!

I hope you find at least interesting!
Cheers!

Most Liked

rockneurotiko

rockneurotiko

Released version 0.2.5!

I forgot to post updates since 0.2.1, so I’ll write all the changes since then:

0.2.2:

  • Fix a bug when type: :boolean and default: false, it was being set to nil

0.2.3:

  • Support for :literal option to bypass the replacement: {:system, :literal, {:system, "HOST"}} this will save in the configuration {:system, "HOST"}.

0.2.4:

  • Support nesting maps and tuples.

0.2.5:

  • Add a required parameter, that will make it to raise an error if the environment variable is not setted: {:system, "HOST", required: true}. In this version the required it’s opt-in, but in the 0.3 maybe it will be required by default and opt-out of the requeriment.
  • Update README with trade offs section

Thanks @ericmj for the PRs for 0.2.3 and 0.2.4 :smile:

josevalim

josevalim

Creator of Elixir

May I ask what is the benefit of config tuples now that Distillery 2.0 supports runtime configuration?

Instead of:

config :foo, bar: {:system, "FOO_BAR"}

I can rather do:

config :foo, bar: System.get_env("FOO_BAR")

And the benefit of the latter is that it can be shared between compile and runtime. The config tuple only works inside a release.

rockneurotiko

rockneurotiko

Sure, thanks for asking!

One of the reasons that I had is that with the config provider Mix.Releases.Config.Providers.Elixir you needed one config file in rel/config/config.exs and then you would have config/prod.exs and that one. But I just tried copying config/prod.exs and it works, so that’s not really a reason. Basically I didn’t liked that you had two different files in different locations for production configuration.

So, the only reason left is the simplicity to do type casts, default values and transforming the value, which with the library it can be made with a simple interface.

It’s probably not a big reason, but I do really like to have the configuration files simple than with repeated code to transform the values (or having to create a helper module in all my projects to do that).

At last, when I want to test my app in a production-like environment (compile with MIX_ENV=prod), I want it to be as close as possible to the real production code, and that means using distillery to do the production release, so I don’t really face the problem of having a prod.exs file that don’t work without distillery.

But I admit that this are really personal preferences :smile:

josevalim

josevalim

Creator of Elixir

As you said though, config/prod.exs no longer works for mix run with config tuples so you don’t have two files, but you don’t have the same functionality. There is nothing stoping you from doing the same with distillery config and having a single file. :slight_smile:

Also, it is worth saying the reason distillery went with two config files (afaik) is to separate compile time from runtime config. But I don’t think this is a :+1: or a :-1: for any because you can run into issues in both approaches (and this is mostly on Elixir rather than those libs).

I can see however the convenience of the system API. :+1: Thanks for replying!

axelson

axelson

Scenic Core Team

With a {:system, env_name} type tuple is it possible to specify a function that would transform the environment variable into the format that you want? Say if the environment variable was a full url but you want to separate the configs into a hostname and a path config.

Where Next?

Popular in Libraries Top

versilov
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
New
deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
sabiwara
Dune is a sandbox for Elixir and aims to safely evaluate user-provided code. You can try it out using this basic Elixir playground made ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
Antrater
Hi everyone! I’m thrilled to announce a huge thing. We have been developing Elixir Moon Design System for quite a while. We are finally ...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

Sub Categories:

We're in Beta

About us Mission Statement