Deploy Your Rails Applications with Dokku and Linode.

Aws4 request&x amz signedheaders=host&x amz signature=92a6abb05025db5cfa5d381dc4e820b75ca94ae64fd468628a93065443c9ff2e
Denys Kurets
14 January 2017

Dokku version:  v0.7.2

There are a lot of articles on how to deploy Rails with Dokku on DigitalOcean, but not so many about Linode. So the following article is another article on how to deploy Rails with Dokku to Linode server, based on docs,  and own experience.

Domain Settings

In case you want to connect domain to your application and you want to avoid possible problems in the future,  it is better to change domain NS servers before deploying.

Linode NS servers:

ns1.linode.com

ns2.linode.com

ns3.linode.com

ns4.linode.com

ns5.linode.com

Registration

Before the start you should create an account on Linode. You could do it here:  signup . You could use my ref link (I don’t know how it works but signup referral link)

Then you should add your billing information. And probably Linode will ask you what amount of money you want to transfer to your account, 5$ is a minimum. Also, you could search in google promocodes. I found a promocode for 20$ here: retailmenot.

Creating “Linode”

Go to Linodes, and choose a plan and location

 

According to the tutorial, take the following steps:

Open your server's dashboard in the Linode Manager. Make sure your Linode is using KVM, not Xen, for virtualization.

In the "Rebuild" tab, select "Ubuntu 16.04 LTS", set a root password, choose SWAP size(I chose 256MB), setup Deployment Disk Size(I choose all available space) and press Rebuild.

Once your Linode has been created, click "Boot" and wait for it to complete.  SSH into your Linode as a root and run the following commands:

apt-get update
apt-get -qq upgrade
apt-get install linux-image-virtual linux-image-extra-virtual

When prompted, install Grub onto the first hard drive. Back in your server's dashboard, click "Edit" on its Configuration Profile, change the "Kernel" option to "GRUB 2" and save your changes and reboot the Linode.

Connecting Domain to Linode

Go to DNS manager zone, fill in the fields and save. In the section “Insert Default Records” choose the first option and select linode where you will deploy the application.

Go to Remote Process, click “Reverse DNS”.

 

And look up your domain.

Installing Dokku

ssh root@ip_address #ssh to server

wget https://raw.githubusercontent.com/dokku/dokku/v0.7.2/bootstrap.sh

DOKKU_TAG=v0.7.2 bash bootstrap.sh

 

After the installation go to the browser http://<your_server_ip>

Enter your ssh key. In case before the installation you copied ssh key to the server, this field will be prefilled with it.

Type hostname(your domain). In case you don’t have a domain, you could enter your server ip address.   

Dokku Configuration

First of all you need to create a dokku application. SSH to your server and make:

dokku apps:create app_name

Then we should create a database. Dokku has a lot of plugins. In our case we will use Postgres.

Install plugins, create a database service, link the database with your application.

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

dokku postgres:create db_name

dokku postgres:link db_name app_name

It is possible that you need to set “config vars”. In case you have in gitignore the configs that you don’t share in your repository, set config vars, it is easy.

dokku config:set app_name PASSWORD='password'

I also recommend you to change timeout configs. At least I had a problem with it during deployment.

dokku config:set --global CURL_TIMEOUT=600
dokku config:set --global CURL_CONNECT_TIMEOUT=30

Deploying Application

Deploying to dokku is pretty similar to heroku. You could check the instruction Getting Started with Rails 4.x on Heroku.

git remote add dokku dokku@ip_addres:app_name

git push dokku master

Troubleshooting

In case of any troubles, please look at the special page on dokku site troubleshooting

I had one problem related to permissions while connecting database with app.

Fixed it*:

cd /home/dokku/app_name

chown  dokku: DOCKER_OPTIONS_DEPLOY

https://github.com/dokku/dokku-postgres/issues/79

Thank you for attention!