Skip to content

Instantly share code, notes, and snippets.

@zph
Forked from nhu313/deploy_dokku.md
Created May 31, 2016 05:46
Show Gist options
  • Save zph/47bd48d908c9b9b5d039816d05d97e20 to your computer and use it in GitHub Desktop.
Save zph/47bd48d908c9b9b5d039816d05d97e20 to your computer and use it in GitHub Desktop.
Deploying phoenix on Dokku through Digital ocean

This write up was based on Henrik's gist

Create server

  1. Create a droplet on digital ocean. Use my referal link for $10 credit. I also credit if you spend money, so thanks in advance ;)
    1. Select "Create Droplet"
    2. Under "Choose an image", click on "One-click Apps"
    3. Select Dokku for your app
    4. Under "Choose a size" select at least 1GB of RAM
    5. Add your ssh public key
    6. Click "Create"
  2. Once your server is created, go to the IP address in your browser
  3. Verify the ssh key is correct.
  4. Click "Finish setup"

Setup your server

  1. ssh into your server (ex: ssh root@104.236.34.69)
  2. Run these commands in the terminal. 1. Change the app_name to your application name or something like prod or qa. 1. Change app_db to your database name 1. Change SECRET_KEY_BASE="" to actual key from your prod.secret.exs file 1. Optional: You can copy this into a setup.sh file and run it with ./setup.sh. (Remember to change the file permission chmod u+x ./setup.sh)
#commands to run on your server
dokku apps:create app_name
dokku config:set app_name BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
dokku config:set app_name LC_ALL=en_US.utf8

sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
dokku postgres:create app_db
dokku postgres:link app_db app_name
dokku config:set app_name SECRET_KEY_BASE="key"

Setup your project

Create the following file in your project root folder

  1. Create a file named.buildpacks with the following content
https://github.com/HashNuke/heroku-buildpack-elixir.git
https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
  1. Create a file named elixir_buildpack.config with the following content (change it to your setting)
erlang_version=18.2.1
elixir_version=1.2.0
always_rebuild=false
post_compile="pwd"
  1. Create a file named phoenix_static_buildpack.config with the following content (change it to your setting)
node_version=5.5.0
npm_version=3.3.12
  1. Open up config/prod.exs
  2. Remove this line import_config "prod.secret.exs" (at the end of the file) to prevent it from importing prod.secret
  3. Add secret_key_base: System.get_env("SECRET_KEY_BASE") underneath the main config. Ex:
```
config :blog, Blog.Endpoint,
  http: [port: {:system, "PORT"}],
  url: [host: "example.com", port: 80],
  cache_static_manifest: "priv/static/manifest.json",
  secret_key_base: System.get_env("SECRET_KEY_BASE")
```
  
Remember to add the **comma** before adding `secret_key_base`
  1. Optional: Add database setting to the end of the file, change blog to your app name and db_name to your database name 1. Note you must get url from DATABASE_URL because that's where Dokku set your database url
config :blog, Blog.Repo,
  adapter: Ecto.Adapters.Postgres,
  database: "db_name",
  url: System.get_env("DATABASE_URL"),
  pool_size: 20

Deploy

  1. Add a git remote git remote add ocean dokku@ip_address:app_name
  2. Note you have to log in using dokku as the user
  3. Ex: `git remote add ocean dokku@104.236.34.69:app_name
  4. Deploy git push ocean master
  5. Optional: Setup your database
  6. ssh into your server
  7. Migrate database dokku run app_name mix ecto.migrate

For future deployment, all you have to do is git push ocean master

You can see all the dokku commands with dokku help.

Sources

  1. https://gist.github.com/henrik/c70e32544e09c1a79841
  2. http://www.phoenixframework.org/docs/heroku
  3. http://hady.svbtle.com/setting-up-elixir-on-digitalocean
  4. http://wsmoak.net/2015/07/05/phoenix-on-heroku.html
  5. http://snltranscripts.jt.org/99/99adillon.phtml
  6. https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-dokku-application
  7. http://dokku.viewdocs.io/dokku/application-deployment/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment