Add Mise Tasks For Common Workflow Commands

I have a Rails project I work on that uses dokku on remote staging and production servers. The best way for me to connect to a rails console session for each of those environments is to SSH into the box (with authorized keys already configured) and then use dokku to run rails console.

I've taken a couple steps to make that process smoother:

  • set up SSH aliases in ~/.ssh/config for each environment
  • run the dokku command directly with ssh -t

With the staging environment, for instance, that then looks like this:

$ ssh -t my-app-staging dokku run my-app rails console

We are already using mise to manage env vars, at least one PATH entry, and the versions of various tools (like Ruby and Node). So, I can take these command improvements a step further on the DX spectrum by wrapping up each as a mise task:

[tasks."console:staging"]
description = "Open a Rails console on staging"
run = "ssh -t my-app-staging dokku run my-app rails console"

[tasks."console:prod"]
description = "Open a Rails console on production"
run = "ssh -t my-app-prod dokku run my-app rails console"

This not only reduces what I have to type down to mise run console:staging, for instance, but I can even invoke mise run with no arguments to get an interactive picker interface:

 mise run
Tasks
Select a task to run
 console:prod     Open a Rails console on production
  console:staging  Open a Rails console on staging
/
esc clear filter enter confirm

From that two-word command, I can find and select the environment I want to connect to.

For these kinds of essential project commands, mise's task feature can be a great fit and better documentation than lines in a README.md.

Tell us about your project

We build good software through good partnerships. Reach out and we can discuss your business, your goals, and how VisualMode can help.