Commit Redux

A software development blog in commit-sized retrospectives

Prepping Mojave for a sqlite App

Friday May 09 2025 • 03:42 PM

Update I ended up discarding the sqlite idea for production since dokku has a hard time accessing the host filesystem and the database file is read-only.

First I’ll create a directory on the host for the database. Last night I read a bit about the Linux filesystem hierarchy standard1 and the /var/ directory, which is where I’ll be saving the sqlite file.

$ mkdir -p /var/lib/dokku/data/storage/commit-redux

Next I create the app

$ dokku apps:create commit-redux

That way I can mount the persistent storage from the host (Mojave) to the dokku container

$ dokku storage:mount commit-redux /var/lib/dokku/data/storage/commit-redux:/app/db

Update /config/environment.rb

Over in the app, I updated my code to connect to the production database when deployed to production.

db_path = if ENV['RACK_ENV'] == 'production'
  'db/production.sqlite3'
else
  'db/development.sqlite3'
end

set :database, { adapter: 'sqlite3', database: db_path }

Connecting Repo to Dokku Remote

I had the syntax wrong so this took me a bit to fix but the right command is:

$ git remote add dokku dokku@dokku-server:commit-redux

Add database files to .gitignore

I was just about to git push to dokku but that would’ve also pushed the database files itself, so I modified the .gitignore file and now we’re good.

Push to dokku

Now I’m pushing to dokku hoping it works out ✌️

Update: Ha, I had some issues with not specifying the ruby version in my Gemfile but after adding it it was good to go.

Porkbun

Now I’ll add the Porkbun A Records to point to the domain name. I’m actually gonna go a bit off script here and add it to my personal website’s domain as a subdomain at commit-redux.enocc.com

Configure domain in dokku

Since dokku was using my global domain host, I had to update it.

$ dokku domains:set commit-redux commit-redux.enocc.com

SSL

Then I set the SSL (email first) then enable LetsEncrypt.

Deployment

I deployed but visiting the website shows me an internal server error. I suspect it’s because I haven’t run database migrations on production, so I run $ dokku run commit-redux rake db:migrate and I’m shown this error:

SQLite3::CantOpenException: unable to open database file (SQLite3::CantOpenException)

Looks like I haven’t created the production database file. I’ll sync the development file to Mojave by syncing from Café Quito my user directory, since I do have write permissions there, and then over on the host I transfer the file to /var/lib/dokku/data/storage/commit-redux.

After updating permissions with

sudo chown -R dokku:dokku /var/lib/dokku/data/storage/commit-redux
sudo chmod -R u+rwX /var/lib/dokku/data/storage/commit-redux

I was now looking at a different error: ActiveRecord::StatementInvalid: SQLite3::ReadOnlyException: attempt to write a readonly database: (ActiveRecord::StatementInvalid)

  1. https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html