PhoenixHeroku

HomePage | RecentChanges | Preferences

Phoenix on Heroku

Note: page superseded by blog post

http://wsmoak.net/2015/07/05/phoenix-on-heroku.html

and the official guide

http://www.phoenixframework.org/docs/heroku

Having (finally) gotten the Phoenix Framework for Elixir installed (*stares accusingly at Norton Firewall*) and played with the Hello Phoenix app a bit locally, I decided to deploy it to Heroku.

I started with...

... but apparently that blog post is outdated. Let's start over with:

So now with a sample app created with mix phoenix.new (see [Up And Running]) we'll execute the commands shown in the [Usage] instructions for the Phoenix Static Buildpack:

$ heroku buildpacks:set https://github.com/gjaldon/phoenix-static-buildpack

$ heroku buildpacks:add --index 1 https://github.com/HashNuke/heroku-buildpack-elixir

This puts the Elixir buildpack in the first position, and pushes the Phoenix Static build pack down to second. See this article on [using multiple buildpacks for an app] for more info.

Let's try to deploy and see what happens:

$ git push heroku master
[...]
remote: -----> Fetching app dependencies with mix
remote: ** (Mix.Config.LoadError) could not load config config/prod.secret.exs

The file is present, but it is listed in .gitignore and so isn't pushed to Heroku. Let's comment out the import in config/prod.exs (last line). (git add && commit)

Trying again, we get a new and improved error message:

$ git push heroku master
[...]
remote: == Compilation error on file lib/phoenix_heroku_wsmoak/repo.ex ==
remote: ** (ArgumentError) missing :adapter configuration in config :phoenix_heroku_wsmoak, PhoenixHerokuWsmoak.Repo

And *that's* because the things in that file we didn't import *are* actually needed. But they aren't things you want to commit to your repository, for security reasons they need to be set in the environment.

So, copy the contents of config/prod.secret.exs into config/prod.exs, and then replace the sensitive values with (for example) System.get_env("DATABASE_PASSWORD")

Next, set the corresponding environment variables in Heroku, for example: heroku config:set DATABASE_PASSWORD=longsecretpassword

Finally, edit (create if necessary) phoenix_static_buildpack.config in the root of your app and specify the environment variables to be exported.

Note that this *overrides* the one from https://github.com/gjaldon/heroku-buildpack-phoenix-static so make sure to include any values in that one, such as DATABASE_URL

My phoenix_static_buildpack.config file now includes:

config_vars_to_export=(DATABASE_URL SECRET_KEY_BASE DATABASE_USERNAME DATABASE_PASSWORD)

git add && commit these changes, and then `git push heroku master` again...

... and success! With stylesheets this time! https://evening-beach-7791.herokuapp.com

Thanks to ericmj, HashNuke, and chrismccord in #elixir-lang on freenode as well as gjaldon for the build pack.

Questions or comments? http://wsmoak.net | http://twitter.com/wsmoak

Future Topics


HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited August 10, 2015 4:19 pm by 198.98.94.133 (diff)
Search: