Deploying Rails apps with Dokku

Update your local apt cache

$ sudo apt-get update

Update dokku and its dependencies

$ sudo apt-get install -qq -y dokku herokuish sshcommand plugn

Confirm SSH Details – In your browser head to your IP address or domain and hit Finish Setup

Rebuild all of your applications

$ dokku ps:rebuildall

Create the App on the Dokku host

$ dokku apps:create your-app-name

Install Postgres – on the Dokku host install the postgres plugin (requires root)

$ sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git

Create a postgres service with the name rails-database

$ dokku postgres:create your-app-database

$ dokku postgres:link your-app-database your-app-name

Deploy the app to dokku – execute below from your local machine 

— the remote username must be dokku or pushes will fail
— (xxx.xxx.xxx.x – replace with ip address of instance)

$ cd your-app-name

$ git remote add dokku dokku@dxxx.xxx.xxx.x:your-app-name

Deploy to Dokku

$ git push dokku master

Setting up the app – execute below from dokku container

Migrate Database

$ dokku run your-app-name rails db:migrate

Installing SSL encryption

$ sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git

$ dokku config:set –no-restart your-app-name DOKKU_LETSENCRYPT_EMAIL=your@emailaddress.com

$ dokku letsencrypt your-app-name dokku letsencrypt:auto-renew your-app-name

If your domain is example.com and SSL is set on example.example.com run:

$ dokku domains:add your-app-name example.com
$ dokku domains:remove your-app-name example.example.com

If you want Auto Renewing SSL

$ dokku letsencrypt your-app-name
$  dokku letsencrypt:auto-renew your-app-name

Setting environment variables

$ dokku config:set –no-restart your-app-name KEY1=VALUE1

View web logs in real time

$ dokku logs your-app-name -t -p web