Hatchbox.io + Digital Ocean
How to host a Rails app on DigitalOcean managed by Hatchbox.io
Chris Oliver's video walkthrough is helpful:
Start in Hatchbox.io and create a new "Server"
Name it
projectname-stagingorprojectname-productionConnect to my Digital Ocean account (or the client's)
Add these to the server:
Name it (the server)
projectname-stagingorprojectname-productionAlways add:
web server
cron -- this is required in order for Hatchbox to run db:migrate when deployments happen.
If your database is postgres, then you also need:
PostgreSQL (this checkbox)
(If your database is SQlite, then no database needs to be added.)
If you plan to use Sidekiq for background jobs, then you also need:
Redis
Background Worker
(or if using solid cache/queue/cable, then you don't need redis, nor a background worker)
This will create the Droplet in the DigitalOcean account.
Note: In my DO account, I have multiple "projects", but Hatchbox always creates the droplet in my first project (which is briancasel.com). After creation, in DO, I can "move" the droplet into the "project" that I want. Syncing with Hatchbox will continue normally after moving it to a new project.
Add the app
Name it
projectname-stagingorprojectname-productionAdd environment variable:
RAILS_MASTER_KEYand input my staging or production key.If using solid queue, then also add ENV variable:
SOLID_QUEUE_IN_PUMAand set it totrueIf this is the staging app, then set environment to
staging(notproduction)Connect it to my GitHub repository
If it's staging, connect it to the
stagingbranch. If production then usemainbranch.
If using Postgres database
Create the Postgres Database via Hatchbox this way:
Go to the App (not "Databases") > "Databases" > New PostgreSQL database (this button)
name it
projectname_stagingorprojectname_production
database.yml for SQLite
This is what worked:
Don't add any ENV variable for DATABASE_URL
database.ymlshould have this:
Using Solid queue / cache / cable?
Follow these instructions to set up the app:
Deploy the app.
I can use Hatchbox's web interface, or I can enable auto deploy on git push to the branch.
Add SSH keys to Hatchbox
In my personal Hatchbox.io account, I have already done this for my Macs. If I get a new computer, then I'll need to do this again.
My SSH credentials should be saved in my 1Password.
Connect TablePlus for database viewing — Only if using Postgres!
(if using SQLite: TablePlus doesn't currently support SSH to SQLite, see issue here)
Hatchbox requires SSH tunnelling. Set it up as follows:
This won't work unless you've already added your Mac's SSH key to Hatchbox.
See my settings: https://share.cleanshot.com/8pv5Lkqg
Get database name, username, password, and IP address in the database info provided in Hatchbox.
In TablePlus, check the box for "Use SSH Key"
Then click the button to upload the SSH key
Get this from my 1password record for my Mac's SSH:
Hover over "Private key" and click "Export".
Download unecrypted key to my desktop.
Upload that file to Tableplus.
The
Uservalue in the SSH setting should bedeployClick "Continue" if you see this: https://share.cleanshot.com/ydjVGHfP
Click "Test" and it should all be green and good to go.
Last updated