DEV Community

Jonathan Yeong
Jonathan Yeong

Posted on

Deploying an Elixir app

I'm amazed by all the ways we can deploy an Elixir app. It's a little overwhelming (see: analysis paralysis). But it's a good problem to have. Especially now that Elixir has native support for deployment. Here are some notes that I wrote up while learning about deploying an Elixir app. Note, I didn't dive into where you should put your app. Just the deployment methods:

  • With Mix. You host the source code on the production server and you run a mix command to start the app, e.g. mix run --no-halt (with the corresponding flags).
  • Using Elixir Releases. This is a built in feature since Elixir 1.9. There's a command, mix release that will compile your elixir code and packages it into an artifact. This artifact will then be uploaded to a production server.
  • Using Distillery. Distillery is a library that is used to produce an Erlang/OTP release. It works with Elixir 1.6+, presumably solving release problems before 1.9 was released.

There are various features of each of these ways to release as well. When we deploy with Mix, we can run mix commands, e.g. mix phx.server. But there are some trade-offs. The source code is visible to anyone with access to the production server. And we don't have access to the Remote Observer.

Alternatively, to start our app with Elixir releases we can use a command similar to this: _build/prod/rel/my_app/bin/my_app start. With Elixir releases (and Distillery) we have access to the Remote Observer and our source code is hidden. Because we're compiling our app it also results in smaller slug sizes which means faster startup times 1. However, we don't have access to Mix. Since Elixir 1.11, we have access to runtime.exs which is executed after the code is compiled. In a Phoenix app, this means renaming config/prod.secret.exs to config/runtime.exs and replacing use Mix.config with import Config.

Finally, a feature that Distillery has that Elixir releases doesn't is hot upgrades. With hot upgrades we can release a new version of our app without bringing the old app down. There is a lot of overlap between Distillery and Elixir releases. Distillery brings its own configuration so you shouldn't mix deployment methods. Choose one or the other. One reason you'd use Distillery over Elixir releases is if you need to deploy an Elixir app pre 1.9.

Further reading


Top comments (0)