All Articles

Simple Deployment of Phoenix / Elixir

7th January 2016

Exrm releases seem extremely stable, but have some caveats:

  • Require build environment to be very similar to deployment
  • Require extra maintenance to ensure the correct application components are loaded by Erlang
  • Requires a custom script to scp the release to the server

With these points in mind I decided to experiment with using a familiar Capistrano based workflow. Something along the lines of:

Capistrano deploys code -> Builds on server -> Upstart handles launch and keep-alive

Sadly however this didn't seem practical when it comes to Exrm's upgrade and downgrade. Instead I ended up creating a custom shell script.

It handles:

  • Uploading all code to the remote server
  • Compiling an Exrm release, the current version is detected from mix.exs
  • Move release to app directory
  • Run hot upgrade with Exrm
  • Runs migrations on server

The script below is targeted to a project which uses Webpack in an app directory. If your project uses Brunch some minor modification may be necessary.

Create a file called exdeploy in the root of your project containing the code from the Gist at the end of this article.

Dont forget to chmod +x ./exdeploy to make it executable.

# Upload and compile current version onto the server ./exdeploy deploy # Run migrations ./exdeploy migrate # Restart (could be used after overwriting a version to relaunch) ./exdeploy restart # Upgrade to the latest version ./exdeploy upgrade

You will need to customize the first few variables to include your app's name and server details etc.

<script src="https://gist.github.com/dyerc/b9d167ca353a40d347e7.js"></script>