Mastering Elixir Releases with Distillery — A (Pretty) Complete Guide

How to create Elixir Releases. And some tips for Phoenix, Ecto, and umbrella applications.

Philipp
Philipp
Sep 12, 2017 · 10 min read
Image for post
Image for post

A Quick Refresher and a Bit of History

Step-by-step guide

git clone https://github.com/wmnnd/distillery-demo.git
cd distillery-demo

Installing Distillery & Creating the First Release

==> Assembling release..
==> Building release clock:0.1.0 using environment dev
==> You have set dev_mode to true, skipping archival phase
==> Release successfully built!
You can run it in one of the following ways:
Interactive: _build/dev/rel/clock/bin/clock console
Foreground: _build/dev/rel/clock/bin/clock foreground
Daemon: _build/dev/rel/clock/bin/clock start

Release Profiles and Environments

use Mix.Releases.Config,
default_release: :default,
default_environment: Mix.env()
mix release
#Mix environment and Distillery environment are both dev
MIX_ENV=prod mix release
#Mix environment and Distillery environment are both prod
MIX_ENV=prod mix release --env=dev
#Mix environment is prod, Distillery environment is dev

Release Build Configuration

environment :dev do
set dev_mode: true
set include_erts: false
set cookie: :"W?cN_`G<>ayUI&ku{<$3w7J<^nUBRBu[F[…]"
end
environment :prod do
set include_erts: true
set include_src: false
set cookie: "^_`fz{dk|`w.n3Z%T,n=F>ezazFk.1ci5}[…]"
end
release :clock do
set version: current_version(:clock)
set applications: [
:runtime_tools
]
end

Lifecycle Scripts aka Hooks

environment :prod do
set pre_start_hook: "rel/hooks/pre_start.sh"
end

Umbrella Apps

Runtime Configuration With Releases

The Problem with Mix Configuration

A Simple Solution: REPLACE_OS_VARS

config :my_app,
foo: "${BAR_VAR}"

Ecto

Phoenix

./node_modules/brunch/bin/brunch b -p
MIX_ENV=prod mix phx.digest
The init/2 callback for Phoenix.Endpoint behaves exactly like in Ecto.

Upgrading Releases

Creating an Upgrade Release

Creating a Production Release

#In Terminal 1
MIX_ENV=prod mix deps.get
MIX_ENV=prod mix release
#In Terminal 2
cd distillery-clock-demo
_build/prod/rel/clock/bin/clock foreground.

Creating an Upgrade Release

#In Terminal 1
MIX_ENV=prod mix release --upgrade

We’ll Do It Live!

#In Terminal 1
_build/prod/rel/clock/bin/clock upgrade 0.2.0
Image for post
Image for post
Updating an application wile it’s running!

Are You a Master of Elixir Releases Yet?


HackerNoon.com

#BlackLivesMatter

Sign up for DONT SIGN UP FOR THIS NEWSLETTER

By HackerNoon.com

how hackers start their afternoon. the real shit is on hackernoon.com. Learn more

Create a free Medium account to get DONT SIGN UP FOR THIS NEWSLETTER in your inbox.

Philipp

Written by

Philipp

I make software. Passionate about Elixir. User of C++, Ruby & JavaScript. Current project: https://www.dblsqd.com

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Philipp

Written by

Philipp

I make software. Passionate about Elixir. User of C++, Ruby & JavaScript. Current project: https://www.dblsqd.com

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean