GIt部署+配置文件+ Heroku [英] GIt Deployment + Configuration Files + Heroku

查看:224
本文介绍了GIt部署+配置文件+ Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Heroku托管Rails应用程序,这意味着使用Git部署到Heroku。由于Heroku上的纯Git工作流,任何需要上游到服务器的东西都必须在我的本地框上配置相同。

I'm using Heroku to host a Rails app, which means using Git to deploy to Heroku. Because of the "pure Git workflow" on Heroku, anything that needs to go upstream to the server has to be configured identically on my local box.

但是我需要某些配置文件会有所不同,具体取决于我是在本地设置还是在Heroku上部署。再次,因为部署方法Heroku使用我不能使用.gitignore和一个模板(如我已经看到的建议很多次,并已用于其他项目)。

However I need to have certain configuration files be different depending on whether I'm in the local setup or deployed on Heroku. Again, because of the deployment method Heroku uses I can't use .gitignore and a template (as I have seen suggested many times, and have used in other projects).

我需要的是Git以某种方式跟踪文件上的更改,但选择性地告诉Git不要覆盖某些文件,当从一个特定的回购 - 基本上只进行某些更改单向。

What I need is for git to somehow track changes on a file, but selectively tell git not to override certain files when pulling from a particular repo -- basically to make certain changes one-way only.

这样做可以吗?

推荐答案

您可以在每个heroku应用程序的本地设置中永久存储配置vars,在你的代码在所有!所以相同的代码可以运行在多个heroku网站,但具有不同的配置。它非常简单,容易,优雅...

You can have config vars persistently stored ON each heroku app's local setup so they do not have to be in your code at all! so the same code can run on multiple heroku sites but with different configuration. It very simple, easy, elegant...

这是我们使用的方法。 (我们使用它的同样的东西...我们在Heroku有相同的应用程序的多个克隆,但我们只需要一个源在github,在我们的dev本地目录我们做push到ORIGIN(github),然后当我们它的方式我们喜欢它,我们CD到prod本地目录,它去了SAME github存储库,我们只有 PULL 从GITHUB到这个目录,从不推(例如,所有推送到github来从我们的dev目录,prod目录只是其他heroku应用程序的暂存区域。)

It's the approach we used. (We used it for the SAME thing... we have multiple clones of the SAME app at Heroku, but we want only ONE source at github, in our dev local directory we do the PUSH to ORIGIN (github), then when we have it the way we like it, we CD to the prod local directory, which goes to the SAME github repository, and we ONLY PULL from GITHUB into this directory, never push (eg, all pushes to github come from our dev directory, the prod directory is just a staging area for the other heroku app.)

在不同的HEROKU站点上具有不同的配置(如下所述),EXACT SAME CODE 在BOTH heroku网站上工作。

By having the different configs ON the different HEROKU sites (as explained below), the EXACT SAME CODE works on BOTH heroku sites.

因此,我们的工作流程是:键是BOTH目录指向SAME github repo)

So our workflow is: (the key is that BOTH directories point to SAME github repo)

cd myDEVdir
*....develop away....*
git add .
git commit -am "another day, another push"
git push origin  *(to our SINGLE github repo)*
git push heroku  *(test it out on heroku #1)*

cd ../myPRODdir
git pull         *(grabs SAME code as used on other site *)
git push heroku  *(now the SAME code runs on Heroku #2)*

就是这样!

现在,您可以在heroku网站上保存网站特定的配置变量:

Now here's how you keep your site-specific config vars ON the heroku site:

http://docs.heroku.com/config-vars

在您的本地命令行上,对于您的两个本地目录的每一个,执行:

on your local command line, for EACH of your two local directories, do:

$ heroku config:add FIRST_CONFIGVAR=fooheroku1
Adding config vars:
  FIRST_CONFIGVAR => fooheroku1

$ heroku config:add SECOND_CONFIGVAR=barheroku1
Adding config vars:
  SECOND_CONFIGVAR => barheroku1

查看您定义的项目:

$ heroku config
FIRST_CONFIGVAR => fooheroku1
SECOND_CONFIGVAR => barheroku1

然后cd到你的另一个目录myPRODdir并做同样的事情,只设置相同的远程heroku vars到fooheroku2和barheroku2。

then cd to your other directory myPRODdir and do the SAME thing, only set the same remote heroku vars to fooheroku2 and barheroku2.

那么在你的rails应用程序中,你简单地引用他们,像这样:

then in your rails app you simple refer to them like so:

a = ENV['FIRST_CONFIGVAR']

一个应用程式会读取'fooheroku1 '其他应用程序将读取'fooheroku2'

One app will read 'fooheroku1' the other app will read 'fooheroku2'

最后,在您的LOCAL目录myDEVdir,您在DEV模式下运行,将相同的配置命令放在您的 config / environment / development.rb 文件你的'dev'版本的配置vars将被设置为任何他们应该是:

And finally, on your LOCAL directory myDEVdir, where you run in DEV mode, put the same config commands in your config/environment/development.rb file your 'dev' version of the config vars will be set to whatever they should be:

ENV['FIRST_CONFIGVAR'] = "foodev"
ENV['SECOND_CONFIGVAR'] = "bardev"

轻松,优雅。谢谢,Heroku!

Easy, elegant. Thanks, Heroku!

这篇关于GIt部署+配置文件+ Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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