- how exrm generates a release (with conform)
- why conform?
- how conform uses *.conf and schema
- exrm's
mix release
cycle (build on relx -> erlang release mgmt) - Terminology
- Sources
exrm adds a Mix task called mix release
to your project. To build a production
release, you just run MIX_ENV=prod mix release
(after the usual build cycle).
This step creates an Erlang release tarball, which contains everything needed to
run your app.
Inside the release is a sys.config
file (releases/<version>/sys.config
).
Application.get_env/3
will consult this file when your code is deployed.
sys.config comes from erlang and is standard OTP configuration for your apps.
Using mix release
out-of-the-box will convert your config/config.exs
into
a sys.config
file.
conform allows you to place .conf
files inside your release for configuration
management and automatically builds a new sys.config
each time you start your app
using bin/my_app start
. It uses an escript
execution to do this.
If not using conform and relying entirely off config.exs
, you cannot use dynamic
code relying on the runtime environment, e.g.
config :foo,
bar: System.get_env("FOOBAR")
The reason for this is that the Erlang VM uses sys.config
for configuration,
and sys.config
can only contain static terms, not function calls or other
dynamic code. When your config.exs
is evaluated and converted to sys.config
,
the dynamic code in config.exs
is executed, evaluated, and the result is
persisted in sys.config
. If you are relying on such things as environment
variables in config.exs
, the value stored in sys.config
will be the value
of those variables when the build was produced, not their values when the release
is booted, which is almost certainly not what you intended. 1
when running releases/rel_name/bin/rel_name console
, conform
is executed to transform
the .conf
file(s) into a config datastructure, which is then merged over the top of the
config in config.exs
.
The schema
is used to convert the .conf
values to a more useful form
(this is what the datatype option is for).
configuration is merged over config.exs settings, so they can co-exist
- Parse
.conf
- Perform mapping & validations on
.conf
using.schema.exs
2b. (execute any transforms on mapping) - Merges parsed config OVER config.exs/sys.config
- outputs sys.config containing final configuration
conform
also supports a custom vm.args
file. vm.args is the standard
erlang file that defines which args are passed when firing up the erlang VM, e.g.
setting otp app's node name: -name [email protected]
and cookie: -setcookie appfoo
).
exrm can override both vm.args
and sys.config
if desired. 1
- read configuration
- generate relx.config, sys.config, vm.args, etcs
- run before_release hooks
- (relx) perform discovery (apps, previous releases)
- (relx) resolve dependencies
- (relx) build release
- (relx) output release to
<project>/releases
- runs after_release hooks
- repackages release
- runs after_package hooks
- Release - a set of versioned OTP applications
- ERTS - Erlang Runtime System
- Release Metadata - app startup order, etc
- Explicit configuration - sys.config, vm.args