Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sescobb27/5e51815577698d7aa810794928741a44 to your computer and use it in GitHub Desktop.
Save sescobb27/5e51815577698d7aa810794928741a44 to your computer and use it in GitHub Desktop.
Deploying Elixir's Phoenix Framework on Dokku.

Deploying Phoenix on Dokku

Worked 2015-09-08 for Phoenix 1.0.1 on Dokku 0.3.25.

These instructions assume you've set up Dokku. If not, go find a tutorial for that part. My notes for setting it up on Digital Ocean.

On your local machine, in the app's repo

Create a Dokku app:

$ ssh dokku apps:create my_app_name

Make it support multiple buildpacks:

$ ssh dokku config:set my_app_name BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git

List the two buildpacks you need:

$ echo "https://github.com/HashNuke/heroku-buildpack-elixir.git" >> .buildpacks
$ echo "https://github.com/gjaldon/heroku-buildpack-phoenix-static.git" >> .buildpacks
$ cat .buildpacks
https://github.com/HashNuke/heroku-buildpack-elixir.git
https://github.com/gjaldon/heroku-buildpack-phoenix-static.git

For Phoenix 1.1, you may need to configure the static buildpack to use node 5+:

echo node_version=5.3.0 > phoenix_static_buildpack.config

If you want to lock down the versions or Erlang and/or Elixir, you can configure the Elixir buildpack.

Get rid of a locale-related warning ("warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell)"):

$ ssh dokku config:set my_app_name LC_ALL=en_US.utf8

Put your SECRET_KEY_BASE in Dokku config:

# Change these values as appropriate…
$ ssh dokku config:set my_app_name SECRET_KEY_BASE=the_value_in_my_prod_secret_file

In config/prod.secret.exs, read from that config (replacing the old hard-coded value):

secret_key_base: System.get_env("SECRET_KEY_BASE")

Set the domain/host of your site in the same way:

# Change these values as appropriate…
$ ssh dokku config:set my_app_name HOSTNAME=my_hostname.example.com

In prod.exs, read from that config (replacing "example.com"):

url: [host: System.get_env("HOSTNAME"), port: 80]

If you're using a database, read that from config as well, like you did above.

# This varies depending on what you use for DBs in Dokku.
$ ssh dokku psql:create my_app_name

config :hello_phoenix, HelloPhoenix.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: System.get_env("DATABASE_URL"),
  pool_size: 20

In .gitignore, comment this out:

#/config/prod.secret.exs

Now your secret-less prod.secret.exs can be committed and deployed.

So, commit! Push to Dokku! Done:

git commit -am "All done"
git remote add dokku dokku@example.com:my_app_name
git push dokku

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment