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

kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New
woutdp
Hi! I wanted to introduce my latest project LiveSvelte. It allows you to render Svelte inside LiveView with end-to-end reactivity. It’s ...
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_or...
New
Azolo
Hey everyone, I just released WebSockex which is a Elixir WebSocket client. WebSockex strives to work as a OTP special process, be RFC6...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
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
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

Sub Categories:

We're in Beta

About us Mission Statement