Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflecting Heroku push version within the app

Tags:

Every time I push my app to heroku I see the line

-----> Launching... done, v43 

Is there a way to make that version number apear within the app so other people can see that number?

like image 427
Nick Ginanto Avatar asked Jan 09 '12 17:01

Nick Ginanto


2 Answers

Why would you want to depend on running a command after every push? The accepted answer is worse than setting the config yourself.

Instead add to your Gemfile:

gem 'heroku-api' 

Add your App name and API key to the Heroku config:

$ heroku config:add HEROKU_APP_NAME=myapp HEROKU_API_KEY=bp6ef3a9... 

Then put something like this in config/initializers/heroku.rb:

unless (app_name = ENV["HEROKU_APP_NAME"]).nil?   require 'heroku-api'    heroku  = Heroku::API.new(:api_key => ENV["HEROKU_API_KEY"])   release = heroku.get_releases(app_name).body.last    ENV["HEROKU_RELEASE_NAME"] = release["name"] end 

Finally:

puts ENV["HEROKU_RELEASE_NAME"] => v42 

Now it's fully automated. You can forget about it and continue to work on your app.

like image 56
jassa Avatar answered Oct 10 '22 21:10

jassa


It's now possible to try the Heroku feature Roberto wrote about in his answer, without contacting Heroku. It's called Heroku Labs: Dyno Metadata and you can enable it by

heroku labs:enable runtime-dyno-metadata -a <app name> 

and then the information is available (on the next deploy) as environment variables:

~ $ env HEROKU_APP_ID:                   <some-hash-appId> HEROKU_APP_NAME:                 example-app HEROKU_DYNO_ID:                  <some-hash-dynoId> HEROKU_RELEASE_VERSION:          v42 HEROKU_SLUG_COMMIT:              <some-hash-slugCommit> HEROKU_SLUG_DESCRIPTION:         Deploy 2c3a0b2 ... 

We don't have to setup any config file or else.

like image 43
Ashish Ratan Avatar answered Oct 10 '22 19:10

Ashish Ratan