Profile picture Schedule a Meeting
c a n d l a n d . n e t

Install Directus on Dokku

Dusty Candland | | directus, dokku, postgresql, docker

It's time to create a database for Route285. Up until now, I've been using Markdown and JSON files to manage the data for the site.

After looking at a few options, I settled on Directus. In thier words:

Directus is an Open Data Platform built to democratize the database.

This platform provides everyone on your team, regardless of technical skill, equal access to data and digital file asset management, for any data model or project. First, link Directus to your desired SQL database and file storage adapter. After that, Directus enables you to perform CRUD operations, create users, assign roles with fully configurable permissions, build complex and granular queries, configure event-driven webhooks and task automation... the list goes on!

I already have a Dokku server setup, so I'll use that.

Install / setup

Setup a Dokku instance and configure for use locally. All these commands are done locally, unless marked otherwise with a comment.

Set your DOKKU_HOST env variable. I use Direnv.

Create a new directory. Create a README.md file to keep track of the setup. Init a new Git repo. Dokku expects this.

Now you should be able set up a new dokku app. We'll add the domain and some environment variables for Directus.

dk apps:create route285-cms
dk domains:add cms.route285.com

dk config:set --no-restart \
	DB_CLIENT=pg \
	KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
	SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
	ADMIN_EMAIL='admin@route285.com' \
	ADMIN_PASSWORD='22222222222222222222' \
	STORAGE_LOCATIONS=local \
	STORAGE_LOCAL_ROOT=uploads \
	DOKKU_LETSENCRYPT_EMAIL=admin@route285.com

I used DuckDuckGo to create UUIDs for the KEY & SECRET.

Next install Directus using the Docker image and set the ports.

dk git:from-image directus/directus:latest
dk proxy:ports-add http:80:8055
dk proxy:ports-remove http:8055:8055

That will fail because we need a database. Create and link that. Linking is important to allow the docker image to find the database.

dk postgres:create route285-db
dk postgres:link route285-db

Get the DSN for the newly created DB and set the DB_CONNECTION_STRING environment variable so Directus knows how to conntect.

dk postgres:info route285-db
dk config:set DB_CONNECTION_STRING=postgres://postgres:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@dokku-postgres-route285-db:5432/route285_db

Next we'll setup LetsEncrypt for TLS.

dk letsencrypt
dk config:set url=https://cms.route285.com

Lastly, we'll setup the uploads directory to mount to the local file system so we can backup uploads and restart the application without loosing files.

dk storage:ensure-directory
dk storage:mount /var/lib/dokku/data/storage/route285-cms/uploads:/directus/uploads

# On Dokku server
chown -R dokku /var/lib/dokku/data/storage/route285-cms/

dk ps:rebuild

Everything should now be ready to setup and configure!

References

TODO

  • [ ] Setup database backups
  • [ ] Backup storage directory

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: