Deploy Rails App to Dokku with autorenewal SSL

Dokku is an Open Source analog of Heroku. This is simple and powerful solution for the developer who wants to concentrate on development instead of endless customization of their deployment process.
First of all you should have VPS with installed Dokku. If yours doesn’t have it use the official installation guide.
Connect to your VPS via ssh.
ssh root@my-dokku-server.com
Create new app.
dokku apps:create my_app
Install Postgres plugin.
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
Create new instance of Postgres for your application.
dokku postgres:create my_app_db
Link database and app containers, forward environment variable DATABASE_URL to your application container.
dokku postgres:link my_app_db my_app
Many Rails apps use WebPacker for building assets. This gem requires 8.15.0 version of node. If you want Dokku to use the version from the package.json you need to add .buildpacks file to a root directory:
https://github.com/heroku/heroku-buildpack-nodejs.githttps://github.com/heroku/heroku-buildpack-ruby.git
To specify node version add it to packages.json:
"engines": { "node": "8.15.0"},
Also don’t forget to specify the Ruby version in Gemfile:
ruby "2.6.3"
Add the file app.json to your project for enable auto migrations:
{
"name": "MyApp",
"scripts": {
"dokku": {
"postdeploy": "bundle exec rake db:migrate"
}
}
}
Run this command from the root folder of your Rails project:
git push dokku@my-dokku-server.com:my-app master
Connect the new domain to your application.
dokku domains:add my_app my-app-domain.com
Notice my-app-domain.com should have the IP of your Dokku server. You can edit “A Record” in the admin panel of hostnames provider.
After that you can open your app by the link http://my-app-domain.com.
Let’s go to add Let’s Encrypt autorenewal SSL cert.
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
Let’s Encrypt requires your emails address. Provide it via config variable.
dokku config:set --no-restart my_app DOKKU_LETSENCRYPT_EMAIL=your@email.com
Generate new SSL cert.
dokku letsencrypt:enable my_app
Add cron job for autorenewal SSL cert.
dokku letsencrypt:cron-job --add my_app
That’s cool! You can open your app securely at this link https://my-app-domain.com.
If you keep the repo on GitHub you can run deploy process on every commit to master branch via GitHub Actions. Use Dokku Github Action for it.
My Instagram:
https://www.instagram.com/vitalyliber
My Courses:
Deploy apps with Dokku (Russian)