How to get into the Rails console, or other tasks in a buildpack-based deploy

To whom it may concern:

When you deploy an app based on a Buildpack (such as a Ruby on Rails application, but also e.g. a NodeJS or Go application), you might be wondering how to run the tasks which one would normally manage using e.g. heroku run taskname.

In our case, we were deploying a Rails application, and wanted to enter the Rails console.
Just trying /ap/bin/bundle exec rails console did not work, because the Ruby version which is installed globally in the container was Ruby 2.7.0, while the app was running on Ruby 2.6.6.

It turns out that the tasks you are looking for live in the /cnb/process/ directory. (‘cnb’ stands for ‘Cloud Native Buildpacks’).
In our case, /cnb/process/console would open up the Rails console.

It was impossible to find any information about this elsewhere and it was only by trial and error that we found out how it works. I hope that by writing this post some other people might be helped in the future if they are searching for the same thing :slight_smile: .

1 Like

Oh this is a good note. We’ve talked about building in a default console option so fly ssh console does what you’d expect, too.

Could we also get a way to run a long running process in detached mode?

If you have bash in your image, you should be able to do something like this:

fly ssh console -C "bash nohup ./process &"

You should also check out the fly machine run command. This will let you run one off VMs until they exit successfully (among other things).

1 Like