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, likedeferred_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 thevaluecan be another config tuple, so for example you can read an integer from the environment system
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
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: :booleananddefault: false, it was being set tonil
0.2.3:
- Support for
:literaloption 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
requiredparameter, 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 ![]()
josevalim
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
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 ![]()
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









