如何跟踪回购/项目中的系统特定配置文件? [英] How can I track system-specific config files in a repo/project?

查看:89
本文介绍了如何跟踪回购/项目中的系统特定配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ruby项目,数据库主机和端口在开发和生产上可能会有所不同。我需要一种方法为这两种环境的脚本获取不同的值。

项目应该是完整的 - 所以应该有一些方法来指定默认值。我不希望克隆错过配置文件。所以完全忽略它们是行不通的。



你如何用git解决这个问题?

将推荐使用:


  • 模板配置文件(具有变量名称代替主机和端口值的文件)
  • $


    一个脚本能够用取决于环境的适当值替换这些变量名(由脚本检测到) >然后,Git解决方案是 git属性过滤器驱动程序(另请参阅 GitPro book )。


    过滤器驱动程序包含一个 clean 命令和一个 smudge 命令,其中任一个都可以不指定。

    checkout ,当 smudge 命令被指定,该命令被送入blob对象它的标准输入,它的标准输出用于更新工作树文件。

    同样, clean 命令用于转换工作树文件的内容

    这样,由污迹引用的脚本(由Git管理)可以通过environement-具体值,而干净的脚本将恢复其内容到一个未触及的配置文件。




    I have a ruby project, and the database host and port might be different on dev and production. I need a way to get different values for those into my scripts for the two environments.

    The project should be complete - so there should be some way to specify default values. I don't want a clone to be missing the config files. So ignoring them completely won't work.

    How do you solve this problem with git?

    解决方案

    I would recommend using:

    • a template config file (a file with variable name in place of the host and port value)
    • a script able to replace those variable names with the appropriate values depending on the environment (detected by the script)

    The Git solution is then a git attribute filter driver (see also GitPro book).

    A filter driver consists of a clean command and a smudge command, either of which can be left unspecified.
    Upon checkout, when the smudge command is specified, the command is fed the blob object from its standard input, and its standard output is used to update the worktree file.
    Similarly, the clean command is used to convert the contents of worktree file upon check-in.

    That way, the script (managed with Git) referenced by the smudge can replace all the variables by environement-specific values, while the clean script will restore its content to an untouched config file.

    When you checkout your Git repo on a prod environment, the smudge process will produce a prod-like config file in the resulting working tree.

    这篇关于如何跟踪回购/项目中的系统特定配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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