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-staging
orprojectname-production
Connect to my Digital Ocean account (or the client's)
Add these to the server:
Name it (the server)
projectname-staging
orprojectname-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:
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-staging
orprojectname-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 totrue
If 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
staging
branch. If production then usemain
branch.
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_staging
orprojectname_production
database.yml for SQLite
This is what worked:
Don't add any ENV variable for DATABASE_URL
database.yml
should have this:
# SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem "sqlite3"
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: storage/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: storage/test.sqlite3
# Store production database in the storage/ directory, which by default
# is mounted as a persistent Docker volume in config/deploy.yml.
production:
primary:
<<: *default
database: storage/production.sqlite3
cache:
<<: *default
database: storage/production_cache.sqlite3
migrations_paths: db/cache_migrate
queue:
<<: *default
database: storage/production_queue.sqlite3
migrations_paths: db/queue_migrate
cable:
<<: *default
database: storage/production_cable.sqlite3
migrations_paths: db/cable_migrate
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
User
value in the SSH setting should bedeploy
Click "Continue" if you see this: https://share.cleanshot.com/ydjVGHfP
Click "Test" and it should all be green and good to go.
Last updated