主厨配方将几个git存储库克隆到单独的文件夹 [英] Chef recipe to clone several git repos to separate folders

查看:70
本文介绍了主厨配方将几个git存储库克隆到单独的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将几个git仓库克隆到单独的文件夹中(即 / var / www / repo_name )。
在我看来,我可以这样:

I need to clone several git repositories into separate folders (i.e /var/www/repo_name). It seems to me, I can do that with:

git node['git_folder'] do 
  repository node['git_repository']
  reference "master"
  action :sync
  user "username"
end

但是如何为角色中的一个配方赋予多个属性?我可以以某种方式使用数据袋来满足我的需求吗?有什么不同的方法吗?

But how can I give several attributes to one recipe in the role?. Can I somehow use data bags for my needs? Is there any different way?

推荐答案

在这里,您将使用数据包来实现它:

Here is how you would accomplish it using data bags:

假定您具有以下数据包结构:

Assuming you have the following data bag structure:

data_bags
  git_repos
    repo_1.json
    repo_2.json

假设您具有以下数据包项目结构:

Assuming you have the following data bag item structure:

{
  "id": "repo_1",
  "destination": "/var/www/repo_1",
  "url": "https://repo.to/clone.git,
  "revision": "master",
  "user": "username",
  "action": "sync"
}

属性 id 目的地 url 是必需的。如果修订用户操作,将在配方中使用默认值:

The attributes id, destination, and url are required. If revision, user, or action are omitted, default values will be used in the recipe:

data_bag('git_repos').each do |name|
  repo = data_bag_item('git_repos', name)

  git repo['destination'] do 
    repository repo['url']
    reference  repo['revision'] || 'master'
    user       repo['user'] || 'username'
    action     repo['action'] ? repo['action'].to_sym : :sync
  end
end

如您所见,您可以在这种情况下 使用数据包,但是我不清楚您为什么要这样做。我认为,这种方法的直观性要差得多,并且在调试过程中很难推理。

As you can see, you could use data bags in this instance, but it's unclear to me why you would want to do so. In my opinion, this approach is far less intutive and much more difficult to reason about during debugging.

这篇关于主厨配方将几个git存储库克隆到单独的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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