如何在heroku上显示RoR应用程序代码版本? [英] How to display RoR app code version on heroku?

查看:160
本文介绍了如何在heroku上显示RoR应用程序代码版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的Rails应用程序,我通常使用标记版本部署到生产环境,然后在用户界面中显示标记,将 git describe --always 的输出分配给变量位于 config / application.rb



现在我将应用程序移动到Heroku,然后部署到heroku只发生在主分支上,所以这个技巧将不再起作用。



是否有任何其他方式为我的代码分配版本号并将其显示当我部署到heroku时的UI?



谢谢,
Stewart

解决方案

 <$ c您可以通过在本地运行此命令来将变量添加到Heroku配置中$ c> heroku config:add GIT_TAG =`git describe --always` 

然后你可以访问这个在您的应用配置中:

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

当应用程序在Heroku上运行时,它会接受配置变量( ENV ['GIT_TAG'] ),当它在开发中在本地运行时,它将回退运行 git describe --always $ b 每次部署时都需要更新Heroku配置变量,但我通常将这种类型添加到部署脚本或rake任务中(沿有用的东西比如创建一个标记部署的新标签并在Heroku上运行任何新的数据库迁移)。


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

解决方案

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).

这篇关于如何在heroku上显示RoR应用程序代码版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆