Release management
with ExRM and Conform
Paul Schoenfelder, ElixirConf 2015
Goals
- Understand releases (how they are structured, etc.)
- Be able to leave here knowing how to create and deploy releases
- Understand release configuration and how Conform can help provide richer, more flexible configuration
OVERview
- OTP Review
- How do we deploy Elixir apps?
- What are releases?
- How do I use releases?
- Configuration Management
- Configuration with Conform
OTP Applications
- Well defined structure and lifecycle
- Explicit dependencies
- Useful metadata (name, version, exports, included apps..)
OTP Application visualized
Release management
- Install Elixir/Erlang + dependencies (OpenSSL, etc)
- Push app to target system (tar+scp, git clone, etc.)
- Configure if necessary
- Build with MIX_ENV=<target env>
- Start application with mix run
- Can be automated (Docker, Heroku buildpack..)
um, without releases.
less than ideal
- Requires dev dependencies in production
- Difficult to manage multiple apps with varying Elixir/Erlang version dependencies.
- No out of the box way to handle application crashes, automatic restarts
- No option for hot upgrades/downgrades
- Doesn't work well on some platforms, RaspPi (slow builds), embedded systems (read-only file system)
define better
- Self-contained applications, with all dependencies
- No need for production to have tooling installed
- Application lifecycle management out of the box
- Path for hot upgrades/downgrades
- Easy cross-compilation
- Easy deployment
- Easily reproduced
Better = OTP Releases
- Self-contained
- Lifecycle management (start/stop/restart/up/down)
- Application health monitoring (heart)
- Hot upgrades/downgrades
- Easy cross-compilation
- Easy deployment
- Easily reproduced
SO what is a release?
- Set of versioned OTP applications
- ERTS (Erlang Runtime System)
- Release metadata (app startup order, etc.)
- Explicit configuration (sys.config, vm.args)
- Scripts for managing the release
- Packaged as a tarball
RELEASE STRUCTURE
my_app
├── bin
│ ├── my_app/my_app.bat
│ ├── ...
├── erts-7.0.3/
├── lib
│ ├── my_app-0.0.1/
│ ├── ...
├── releases
│ ├── 0.0.1/
│ ├── RELEASES
│ └── start_erl.data
what is exrm?
- A tool for building releases
- Extends Relx, the equivalent tool for Erlang
- Easy to integrate into your existing build process
- Provides: Mix tasks
- Provides: Automatic appup generation
- Provides: Plugin system
- Provides: Intelligent defaults, but you can still provide your own custom relx.config, vm.args, etc.
MIX RELEASE
- Read configuration
- Generates relx.config, sys.config, vm.args
- Runs before_release hooks
- Relx: Perform discovery (apps, previous releases)
- Relx: Resolve dependencies
- Relx: Build release
- Relx: Output release to <project>/rel
- Runs after_release hooks
- Repackages release
- Runs after_package hooks
lets take a look
Configuration
- config.exs + config.<env>.exs
- Sufficient, but less than ideal for non-programmers
- Converted to static config (sys.config) in a release
- Because of this, dynamic configuration, i.e. System.get_env, do not work as expected
ENTER CONFORM
- Developers define configuration schema
- Users configure application via init-style config
- Schema provides config mappings, transforms, validators
- Extend schemas provided by dependencies
- Expose important config settings, hide advanced settings, provide documentation, sane defaults
- Configuration is merged over config.exs settings, so they can co-exist
CONFORM Schema - mappings
- Define how to map user-facing configuration to system configuration
- Defines datatype of the setting
- Defines default values
- Defines validation rules for the setting
- Exposes other options (hidden, commented, etc.)
- Provides documentation
CONFORM Schema - Transforms
- Functions which receive a reference to the configuration state, and return a value to be used for the given setting
- Can execute any Elixir/Erlang code (including your own modules)
- Can be defined in the schema itself, or in a module, by extending a behaviour (Conform.Schema.Transform)
CONFORM Schema - VALIDATORS
- Functions which receive a mapped value + args, and validate some rule
- Return :ok, {:warn, msg}, or {:error, msg}
- Like transforms, can be defined in their own module, by extending a behaviour (Conform.Schema.Validator)
- Conform provides RangeValidator
HOW CONFORM WORKS
- Parses .conf
- Performs mapping + validation
- Executes transforms
- Merges parsed config over config.exs/sys.config
- Outputs sys.config containing final configuration
LETS TAKE A LOOK
Questions?
Release Management with ExRM and Conform
By Paul Schoenfelder
Release Management with ExRM and Conform
ElixirConf 2015
- 2,542