简体   繁体   English

如何在仍然可以推送到dotCloud的同时从git repo中排除database.yml?

[英]How can I exclude database.yml from a git repo while still being able to push to dotCloud?

I want to add a remote git collaborator on one of my projects, but I do not want to have him access my passwords in database.yml. 我想在我的一个项目中添加一个远程git协作者,但我不想让他访问database.yml中的密码。 I know how to .gitignore database.yml and purge the repo accordingly, but the trouble is I am deploying this particular project to DotCloud, which, as far as I know, requires the database.yml to be part of the git repo. 我知道如何.gitignore database.yml并相应地清除该存储库,但是麻烦是我正在将该特定项目部署到DotCloud,据我所知,该项目要求database.yml是git存储库的一部分。 The best solution I can think of now is using rsync to push to DotCloud, but I'd rather push directly from the git repo. 我现在能想到的最好的解决方案是使用rsync推送到DotCloud,但我宁愿直接从git repo推送。 Anyone know of a way I can do this? 有人知道我可以做到这一点吗?

You have a couple of different options depending on what you want to do. 根据您想做什么,您有几种不同的选择。

You can put the database.yml file in your .gitignore file , and then when using dotcloud push use rsync instead of git to push your code. 您可以将database.yml文件放在.gitignore file ,然后在使用dotcloud push时,使用rsync而不是git来推送代码。

$ dotcloud push --all ramen

Using the --all option will force the uploader to use the “rsync” method, and therefore push all your files. 使用--all选项将强制上载器使用“ rsync”方法,从而推送您的所有文件。 See this page for more info. 请参阅此页面以获取更多信息。 http://docs.dotcloud.com/guides/git-hg/#pushing-uncomitted-changes http://docs.dotcloud.com/guides/git-hg/#pushing-uncomitted-changes

If you need to ignore files then you can create a .dotcloudignore file, and add the files you want to ignore with the push there. 如果您需要忽略文件,则可以创建一个.dotcloudignore文件,并通过在其中推送添加要忽略的文件。

The second, better approach is to not put your passwords in your database.yml file at all. 第二种更好的方法是根本不将密码放在database.yml文件中。 Add your passwords as environment variables, and then your database.yml file can be safe and free of passwords. 将您的密码添加为环境变量,然后您的database.yml文件可以安全无密码。

$ dotcloud var set myapp MYVAR=MYVALUE

You can then reference the variables the same way as you do with environment.yml or environment.json . 然后,您可以像使用environment.ymlenvironment.json一样引用变量。 More info can be found here: http://docs.dotcloud.com/guides/environment/#adding-environment-variables 可以在这里找到更多信息: http : //docs.dotcloud.com/guides/environment/#adding-environment-variables

NOTE 1: Suppose the simpler way is to create alias in git that would automatically execute rsync: 注意1:假设更简单的方法是在git中创建别名,该别名将自动执行rsync:

git config alias.<yourcommand>; !<your script>

Example: 例:

git config alias.sendtocloud "! echo 'rsync' && rsync && echo pull && git pull"

and later try: 然后尝试:

git sendtocloud <continue parameters as after git pull >

If you want to have pure git solution and at least 3 repos: 如果您想拥有纯git解决方案和至少3个存储库:

  • [Y]our: (database.yml not important?) [Y]您的:(database.yml不重要吗?)
  • [C]ollaborator: (without database.yml) [C] ollaborator :(不带database.yml)
  • [D]otCloud (with original databse.yml) [D] otCloud(带有原始databse.yml)

So there are additional questions: 因此,还有其他问题:

  1. How do you share repository with your collaborator? 您如何与合作者共享资源库? (pull or push and by who?) (拉或推,由谁拉?)
  2. OR do you have some bare repository to exchange data (shared by [Y] and [C])? 还是您有一些裸仓库来交换数据(由[Y]和[C]共享)?
  3. Is that correct, that you don't need to have database.yml in your repo? 是正确的,您不需要在存储库中包含database.yml吗?

NOTE 2: you can use git hooks to do almost everything what you want. 注意2:您可以使用git hooks完成几乎所有您想做的事情。 For example you can even manage with some temporary branches before update etc. 例如,您甚至可以在更新等之前使用一些临时分支进行管理。

NOTE 3: If you don't need database.yml in your repo than you can create in-middle bare repo before [y] and [D] with "update" hook to forward changes to [D] 注意3:如果您的存储库中不需要database.yml,则可以在[y]和[D]之前创建中间的裸存储库,并使用“ update”钩子将更改转发到[D]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM