2. Who I am
DevOps/SRE for a long time, now turning to
developing
Learning and writing Elixir - it’s been great!
Released and deployed Elixir application as side
project
3. Why make Elixir releases?
Self-contained release artefacts (everything included)
Good for delivery pipeline to production
Good tracking of production version
Hot Deploy
5. Distillery
https://github.com/bitwalker/distillery
Pure Elixir tool to make Elixir releases easy to do
Generate the release config with “mix release:init”
Modify if necessary (most likely only minor changes)
Compile: “MIX_ENV=prod mix compile"
Release: “MIX_ENV=prod mix release --env prod”
Tarball is generated with Erlang Run Time System (ERTS), application and run
scripts
Profit!
6. Gotchas
MUST build on the same OS as the target host (use
Docker)
Mix tasks do not work in release artefact e.g. “ecto
migrate”
Using environment variables as configuration can be
tricky - “REPLACE_OS_VARS=true” helps a bit
8. Ecto Migrations
“mix ecto:migrate” will not work
Workaround:
Define a migrator task which calls `Ecto.Migrator.run`
Execute it after deploy with “bin/test_app command release_tasks migrate”, or
Call it as part of a release hook
12. Drawbacks/Gotchas
Must keep a copy of the previous build version to build next version (Distillery drawback)
Phoenix is not fully compatible with hot deploys e.g https://github.com/phoenixframework/
phoenix/issues/2432
The release directory MUST be writable by the `daemon` user (or whatever user is running
the application). Even if you execute the command as root, it will change to the user and
throw nonsense errors. https://github.com/bitwalker/distillery/issues/173
Must use the same environment variables when calling “upgrade”, or upgraded version
may die
If one application breaks, it can take down the whole thing
Must remember to update the app version and release version
Can only upgrade/downgrade sequentially
13. Summary
Releases are good
Distillery makes releases much much easier
Hot deploys are pretty neat!
But…only if you really need it
It is much easier to just do rolling deployments the ye
olde fashioned way
14. References
Distillery documentation - https://hexdocs.pm/distillery
Great walkthrough of Phoenix and Distillery - https://hexdocs.pm/distillery/phoenix-
walkthrough.html
Another good guide for Distillery - https://hackernoon.com/mastering-elixir-releases-with-
distillery-a-pretty-complete-guide-497546f298bc
Great resource on Erlang release process - http://learnyousomeerlang.com/release-is-the-
word
Great resource on Hot deploys - http://learnyousomeerlang.com/relups
Erlang Release Handler documentation - http://erlang.org/doc/design_principles/
release_handling.html
Erlang Appup documentation - http://erlang.org/doc/man/appup.html
15. Questions?
Full working demo project at: https://github.com/
jgmchan/elixir-hot-deploy-demo
Twitter: @jgmchan
Email: jgmchan@gmail.com