Elixir 1.9 will ship with support for releases. In this post, we show you how to use them with Phoenix and deploy to Gigalixir.
First, make sure you are running Elixir 1.9 locally. We like asdf-vm so that’s what we’ll use here.
asdf install elixir 1.9 asdf local elixir 1.9 asdf install erlang 21.3 asdf local erlang 21.3 asdf install nodejs 12.4.0 asdf local nodejs 12.4.0
Now we’re ready to create a new phoenix app. To keep things simple, we’re generating an app without a database, only because that isn’t the focus of this post. You’ll most likely want a database so for more information, see the Phoenix Up and Running Guide.
mix archive.install hex phx_new 1.4.6 mix phx.new my_app --no-ecto cd my_app
And let’s make sure it worked.
mix phx.server curl http://localhost:4000/
Great, that was easy! Our app has been created and we’re now ready to set up Elixir releases.
First, let’s create an empty config/releases.exs, which is where our runtime configuration goes.
echo "import Config" > config/releases.exs
The only configuration we really absolutely need to do is make sure the web server is started by setting server: true
echo “config :my_app, MyAppWeb.Endpoint, server: true” » config/releases.exs
Now we can build a release locally and make sure it works.
export SECRET_KEY_BASE=$(mix phx.gen.secret) MIX_ENV=prod mix release
And let’s make sure it runs
_build/prod/rel/my_app/bin/my_app start curl http://localhost:4000/
Awesome, not too bad! There’s a lot more you can do with releases, but that’s for another post. Our app is now using Elixir Releases and is ready to deploy. Gigalixir
First, let’s make sure we’re configured to use the right Elixir, Erlang, and Node versions.
echo "elixir_version=1.9" > elixir_buildpack.config echo "erlang_version=21.3" >> elixir_buildpack.config echo "node_version=12.4.0" > phoenix_static_buildpack.config
And now the code is good to go. Let’s check in what we have.
git init git add . git commit -m 'Phoenix + Elixir Releases + Gigalixir'
If you haven’t already, install the CLI and sign up for an account.
sudo pip install gigalixir --ignore-installed six gigalixir signup gigalixir login
Create a Gigalixir app and deploy
APP_NAME=$(gigalixir create) git push gigalixir main
Gigalixir auto-detects that you want to use Elixir Releases because you have a
Wait a minute or two and see if it worked
Boom! For more detailed instructions, see the Getting Started Guide.
Remote Console, clustering, observer, migrations, etc should all work as normal with the exception of hot upgrades since they aren’t yet supported by Elixir Releases. For example
gigalixir ps:remote_console gigalixir ps:observer gigalixir migrate