How to display RoR app code version on heroku?

微笑、不失礼 提交于 2019-12-24 11:08:24

问题


For my Rails apps I normally deploy to production from a tagged version, and then display the tag in the user interface assigning the output of git describe --always to a variable in config/application.rb.

Now I'm moving an app over to Heroku, and deployment to heroku only happens using the master branch, so this trick won't work any more.

Are there any other ways to assign a version number to my code and display it on the UI when I've deployed to heroku?

Thanks, Stewart


回答1:


You can add a variable to the Heroku configuration by running this command locally whenever you push new changes to Heroku:

heroku config:add GIT_TAG=`git describe --always`

Then you can access this in your app's configuration:

version = ENV['GIT_TAG'] || `git describe --always`

When the app is running on Heroku, it will pick up the config variable (ENV['GIT_TAG']) and when it's running locally in development it will fall back to running git describe --always.

You will need to update the Heroku config variable each time you deploy, but I generally add this kind of thing to a deploy script or rake task (along with useful things like creating a new tag marking the deploy and running any new database migrations on Heroku).




回答2:


Doesn't git tag fit your needs?

And why wouldn't the old trick work anymore?




回答3:


If you want to display it on the UI then a git SHA output probably isn't particularly useful - you have two options, set a Heroku config variable with a user friendly version number in or a set a version number in your code that you increment when you deploy from master. You could probably wrap the deploy up in a rake task that incremented the version number either a file (and then readded it to git and commits it) or simply increments a value in a config variable.

Also, don't forget Heroku release management http://blog.heroku.com/archives/2010/11/17/releases/ which you may also be able to employ here to get the version number from that perhaps.



来源:https://stackoverflow.com/questions/10777881/how-to-display-ror-app-code-version-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!