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 nicbet/a8d68d39e77d8a09458946b3443ed9cf to your computer and use it in GitHub Desktop.
Save nicbet/a8d68d39e77d8a09458946b3443ed9cf to your computer and use it in GitHub Desktop.
Deploy a Phoenix app with Dokku

Deploy a Phoenix app with Dokku

Pre-requisits

  1. Setup Dokku instance on Digital Ocean
  2. Config Phoenix App For Dokku Deploy

Step 1 - Create app

$ ssh <mydomain.com>
$ dokku apps:create <app_name>
$ logout

Step 2 - Setup Dokku as a git remote

  1. Add a new git remote called 'dokku' to your phoenix project $ git remote add dokku dokku@<mydomain.com>:<app_name>
  2. Add your ssh key to the dokku user to allow you to push cat ~/.ssh/id_rsa.pub | ssh root@<mydomain.com> "sudo sshcommand acl-add dokku ssh-key-for-dokku-push"

Step 3 - Setup buildpacks

$ 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

Step 4 - Configure dokku for Elixir deployment

$ ssh <mydomain.com>
$ dokku config:set <app_name> HOSTNAME=<app_name>.<mydomain.com>
$ dokku config:set <app_name> LC_ALL=en_US.utf8
$ dokku config:set <app_name> SECRET_KEY_BASE=<random 64 character string>
$ logout

Step 5 - Configure elixir buildpack

Create a file called elixir_buildpack.config in the root of your project with the following content:

# Erlang version
erlang_version=18.2.1

# Elixir version
elixir_version=1.3.1

# Always rebuild from scratch on every deploy?
always_rebuild=true

# Export heroku config vars
config_vars_to_export=(DATABASE_URL)

Step 5 - Initial push

$ git push dokku master

Step 6 - Setup Postgres

$ ssh <mydomain.com>
$ sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
$ dokku postgres:create <db_name - a.k.a app_name>
$ dokku postgres:link <db_name> <app_name>
$ dokku run <app_name> mix ecto.migrate
$ logout

Step 7 - Add domain (if required subdomain doesn't match app name)

$ ssh <mydomain.com>
$ dokku domains:add <app_name> <custom_domain>
$ logout

Step 8 - SSL

$ ssh <mydomain.com>
$ sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
$ dokku config:set --no-restart <app_name> DOKKU_LETSENCRYPT_EMAIL=<e-mail>
$ dokku letsencrypt <app_name>
$ dokku letsencrypt:auto-renew river_place
$ logout

Done!

http://<app_name>.<mydomain.com> or http://<custom_domain>

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