Hatchbox.io + Digital Ocean
How to host a Rails app on DigitalOcean managed by Hatchbox.io
Last updated
How to host a Rails app on DigitalOcean managed by Hatchbox.io
Last updated
Chris Oliver's video walkthrough is helpful:
Name it projectname-staging
or projectname-production
Connect to my Digital Ocean account (or the client's)
Name it (the server) projectname-staging
or projectname-production
Always 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:
postgres database
(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.
Name it projectname-staging
or projectname-production
Add environment variable: RAILS_MASTER_KEY
and input my staging or production key.
If using solid queue, then also add ENV variable: SOLID_QUEUE_IN_PUMA
and set it to true
If this is the staging app, then set environment to staging
(not production
)
Connect it to my GitHub repository
If it's staging, connect it to the staging
branch. If production then use main
branch.
Create the database via Hatchbox and name it projectname_staging
or projectname_production
This is what worked:
Don't add any ENV variable for DATABASE_URL
database.yml
should have this:
I can use Hatchbox's web interface, or I can enable auto deploy on git push to the branch.
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.
(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 User
value in the SSH setting should be deploy
Click "Continue" if you see this: https://share.cleanshot.com/ydjVGHfP
Click "Test" and it should all be green and good to go.