config_tuples v0.4.2 ConfigTuples.Provider View Source

This module provides an implementation of Distilery’s configuration provider behavior that changes runtime config tuples for the value.

Usage

Add the following to your rel/config.exs

release :myapp do

# ...snip...
set config_providers: [
  ConfigTuples.Provider
]

end

This will result in ConfigTuples.Provider being invoked during boot, at which point it will evaluate the current configuration for all the apps and replace the config tuples when needed, persisting it in the configuration.

Config tuples

The config tuple always start with :system, and can have some options as keyword, the syntax are like this:

  • {:system, env_name}
  • {:system, env_name, opts}

The available options are:

  • type: Type to cast the value, one of :string, :integer, :float, :atom, :boolean. Default to :string
  • default: Default value if the environment variable is not setted. Default no nil
  • transform: Function to transform the final value, the syntax is {Module, :function}
  • required: Set to true if this environment variable needs to be setted, if not setted it will raise an error. Default no false

For example:

  • {:system, "MYSQL_PORT", type: :integer, default: 3306}
  • {:system, "ENABLE_LOG", type: :boolean, default: false}
  • {:system, "HOST", transform: {MyApp.UrlParser, :parse}}

If you need to store the literal values {:system, term()}, {:system, term(), Keyword.t()}, you can use {:system, :literal, term()} to disable ConfigTuples config interpolation. For example:

  • {:system, :literal, {:system, "HOST}}

Link to this section Summary

Functions

Called when the provider is initialized

Link to this section Functions

Called when the provider is initialized.

Providers are invoked pre-boot, in a dedicated VM, with all application code loaded, and kernel, stdlib, compiler, and elixir applications started. Providers must use this callback to push configuration into the application environment, which will be persisted to a final sys.config for the release itself.

The arguments given to init/1 are the same as given in the config_providers setting in your release configuration file.

Callback implementation for Distillery.Releases.Config.Provider.init/1.