Just released - The Imposter's Roadmap! Go Get It

Preflight Check

Buy or Subscribe

You can access this course in just a minute, and support my efforts to rid the world of crappy online courses!

Buy Standalone  Subscribe

Before we deploy, we need to setup the domain and make sure the IP address is pointed at our server. I use Cloudflare, but whatever you use, make sure it's directing traffic.
Next, we need to setup Letsencrypt on our Dokku box so we can use SSL:
dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
We then need to make sure our application has the correct domain:
dokku domains:set railz rails.bigmachine.io
Letencrypt requires an email address, and setting it is a bit crazy-making (as you'll see in the video), but here are the steps:
dokku letsencrypt:set railz email you@you.com
dokku letsencrypt:enable railz
Important: you need to have your domain pointing to your new machine before you run this command. Letsencrypt will try to verify your domain to the local IP address, and if it can't, you'll get an error.
Finally, let's be sure the certificate is renewed before it expires!
dokku letsencrypt:cron-job --add 

Housekeeping

We have a bit of housekeeping before we push our code. The first thing we need to do is to make sure our migrations are run when we push our site. They have the Spina and Devise tables, so they need to be there!
For this, we set up a Procfile, which is just a text file without an extension. The contents will be:
web: bundle exec puma -C config/puma.rb
release: bundle exec rails db:migrate
The next thing we need to do is to remove or rename the Dockerfile in the root of the application. This will cause Dokku to use it instead of its internal build pack. This will result in our data being erased in our database (see video for details), which is unbelievably dumb.
mv Dockerfile Dockerfilexxx

Setting Configuration

We need all of our environment variables that are in our .env file to be up on Dokku. The simplest thing, I have found, is to do some copy/paste magic with the settings in this file. For instance, our .env file might have a setting like this:
DATABASE_URL="postgres://..."
To set things with Dokku, we need to run this command on our Dokku server:
dokku config:set railz DATABASE_URL="postgres://..."
The copy/paste part comes in by copying "dokku config:set railz" in front of every setting, then running the commands in bulk on the server. That's what I do, anyway.
The last thing you need to do, configuration-wise, is to ensure your mail configuration is set. Make sure your domain is correctly set, and that delivery errors are off:
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { host: 'rails.bigmachine.io'}
config.action_mailer.perform_caching = false
config.action_mailer.smtp_settings = { 
  address: ENV['AWS_SES_HOST'], 
  user_name: ENV['AWS_SES_USER'], 
  password: ENV['AWS_SES_PASS'],
}

Setting Up Git

We have a bare Git repository on our server which we can now access. There are two considerations here: 
  1. We need to push to our server's IP address
  2. Dokku uses the term master instead of main, so we need to accommodate for that.
Let's add a remote:
git remote add dokku dokku@[SERVER IP]/railz
git push dokku main:master