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

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

问题描述

我有一个 ruby​​ 项目,开发和生产的数据库主机和端口可能不同.我需要一种方法将这些值的不同值放入我的两个环境的脚本中.

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.

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

How do you solve this problem with git?

推荐答案

我建议使用:

  • 一个模板配置文件(一个用变量名代替主机和端口值的文件)
  • 一个能够根据环境(由脚本检测到)用适当的值替换这些变量名称的脚本

Git 解决方案是一个 git 属性过滤器驱动程序(另见 GitPro 书籍).

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

过滤器驱动程序由一个 clean 命令和一个 smudge 命令组成,其中任何一个都可以不指定.
checkout 时,当指定 smudge 命令时,该命令从其标准输入中获取 blob 对象,其标准输出用于更新工作树文件.
类似地,clean 命令用于在签入时转换工作树文件的内容.

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.

这样,smudge 引用的脚本(用 Git 管理)可以用特定于环境的值替换所有变量,而干净的脚本会将其内容恢复到未修改的配置文件中.

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.

当您在 prod 环境中检出您的 Git 存储库时,涂抹过程将在生成的工作树中生成一个类似 prod 的配置文件.

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天全站免登陆