Hidden Features of the Heroku CLI
Heroku’s CLI interface, the Heroku Toolbelt, has a lot of features which aren’t obvious, or are hidden away. Here are some of the useful ones I’ve found.
Most people who use Heroku for Rails know about
heroku run. For Rails apps,
it’s used to run
rake all the time. But did you know you can run
explore your app?
$ heroku run bash Running `bash` attached to terminal... up, run.1563 $ ls -1 bin build config config.rb ....etc.... $ rm Gemfile # you can even delete files
heroku run bash to debug filesystem problems and detect files that
should be on Heroku, but were somehow missing in the compiled slug.
heroku open is simple: it will open your Heroku site in your web browser. If
you have a
staging Heroku remote, you could do
heroku open --remote staging.
Or you can use the
--app option and do
heroku open --app sushi.
Are your processes running smoothly after that last deploy? Check with
$ watch heroku ps Every 2.0s: heroku ps -r staging Tue Dec 24 10:46:07 2013 === web (1X): `bundle exec unicorn -p $PORT -c ./config/unicorn.rb` web.1: starting 2013/12/20 17:21:48
I’ll let that run for a minute to ensure nothing crashes after a deploy.
heroku git:remote can add a git remote to your app:
# Add a git remote named foobar that points to the app-staging application heroku git:remote --app app-staging --remote foobar
This command would be a good addition to a
I’m sure you’ve used
heroku addons:add newrelic to add an addon, but how about
heroku addons:open newrelicwill open the New Relic dashboard in your browser
heroku addons:docs newrelicwill open up Heroku’s documentation page for New Relic.
Sometimes I need to run SQL against a Heroku database. I could do
pg:psql to get a psql prompt and type in my SQL, but what if I need to
run the same command a few times in a row? Then I use shell here strings, like
heroku run pg:psql <<<"SELECT COUNT(*) FROM users WHERE email = 'email@example.com'"
This prints out the results immediately, and I can re-run it easily since the whole command is in my shell history.
Any suggestions? I’m available on Twitter: @gabebw.