Skip to content

knightoftheoldcode/rails-mrsk-sqlite

Repository files navigation

README

This is a test project for MRSK.

I'll leave it up until I have better ones, then point it to those.

I'm just learning, hopefully this will help you learn MRSK too.

My favorite technique to learn something is to create a minimal testbed.

rails-mrsk-sqlite

This project was purpose-built to test the mrsk deployment process.

Rails New

rails new rails-mersk-sqlite --css=tailwind --database=sqlite

Add Dockerfile

We will use the new(ish) dockerfile-rails.

This should eventually be baked into rails itself (v7.1-ish timeframe) so it makes sense to use it here when you need a semi-intelligent Dockerfile generator.

Add to your project:

bin/bundle add dockerfile-rails --optimistic --group development

Then have it spin out a project-specific (this is the cool part) Dockerfile:

bin/rails generate dockerfile —compose

I like having it generate a full docker-compose.yml stack. It doesn't matter much in this case with sqlite, but in a more comprehensive project with postrgres and redis or such; it'll save some time.

It should auto-detect what you're using, but there are some command line flags you can tweak if it doesn't on the project page.

I'd test build that, if you have Docker installed on your workstation (if you don't, you probably should).

Add MRSK

gem install mrsk

Init:

mrsk init --bundle

I like installing it into my project Gemfile (the --bundle flag above should do so).

You'll need to tweak your build, as I've done here to gather all appropriate parameters into an .env file (which should have been created).

I also stage this part out a bit and override the default healthcheck (future versions of rails will come default with an /up healthcheck).

Commit Hash: ab3fe93

Simple Healthcheck: ab3fe93:config/deploy.yml

Add Healthcheck

By default, a valid deploy target will use Traefik to blue/green a deploy. It will only succeed in moving from the previous docker container to the new one if the healthcheck passes.

Above, I'd set it to something like / with a very simple root route:

Hello World

But a better option is to build and add a simple /up route mappting. Ultimately, this healthcheck should do more, including excercising DB access, etc to ensure all features of the new container are working before MRSK rolls it over.

This is still a pretty basic /up check for our purposes of testing and proving concepts:

app/controllers/healthcheck_controller.rb

MRSK Deploy

Once all of this is running:

  • Dockerfile / Compose Properly Builds
  • Healthcheck Endpoint is returning a 200 OK
  • Config stuff is in

You should now be ready for a bin/mrsk deploy.

It will take a while; but it should deploy to your target.

For me, I've been using a Digital Ocean $6/month Droplet to test it. (It might work with a smaller one; but while testing infrastructure I like to give it enough that I know I'm not bumping into hardware resource silliness issues. And you can tear down droplets as you please so you shouldn't incurr too many costs. One cool think about MRSK is that fits well into a strategy for quickly raising and tearing down infrastructure.)

My ulitmate demo will be incorporating a bunch more stuff into having an ultimate infrastructure tool that can work all the way from "rails new" to fairly comprehensive on-prem or cloud production deploy.

NOTES

The entire process above can be a bit more tricky your first few times working with Docker, for instance, on an Apple Silicon Mac. But you can use our friend Google to help troubleshoot anything you run into (feel free to open PRs and I'll try to respond here...but I'll do that more in future, better versions of these repos).

About

rails-mrsk-sqlite

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published