Skip to content

Instantly share code, notes, and snippets.

@col
Last active September 29, 2024 05:11
Show Gist options
  • Save col/a509ee4b73cecb347c97 to your computer and use it in GitHub Desktop.
Save col/a509ee4b73cecb347c97 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