I really enjoy programming in Ruby, and my preferred web framework has been Ruby on Rails for many years. But, setting up to work on a new project is one of my least favourite yaks to shave.

Over the years, web development has become more complicated, and a new Ruby on Rails project can involve:

  • Installing the appropriate version of ruby
  • Installing the rails gem
  • Generating a new rails project
  • Setting up a database server
  • Setting up a Redis server (for ActionCable)
  • Configuring javascript bundling (webpack/esbuild/whatever rails uses this week)
  • Setting up CSS bundling (bootstrap/tailwindcss/whatever your preferred CSS framework is)

This gets pretty tedious, and since there is usually a long gap between projects for me, it’s very different every time, and managing all of these dependencies on my laptop gets quite time-consuming.

Docker can help, and this blog post is a great approach to letting docker take care of all of the dependencies, so you can just get on with your rails development.

The one missing piece for a new project is that you still need to install ruby in the first place, and generate your rails application before you can dockerise it.

In an attempt to fix this, I’ve created my own rails-from-scratch project.

This builds a local docker image containing ruby and the pre-requisites you need to successfully generate a new rails project. It then generates the project and dockerises it using the Evil Martians approach.

I started off using esbuild and bootstrap, and that version of the project is available using this tag.

I’ve now converted it to use tailwindcss and javascript import maps, and also tried to make it completely non-interactive, so you can run:

PROJECT=whatever make create-rails-app

…and go do something else for a while. When you come back, you should have a new dockerised rails 7 app. ready to go.

Currently, this uses ruby 3.1.2, postgres 14 and redis 6.

I hope it’s useful to some folks. It definitey reduces the friction for me, and hopefully means I’ll create more projects rather than giving up at the thought of how much yak shaving I’d have to do to create and configure a new project before I can even start.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s