如何在厨师仓库中的厨师食谱之间共享代码?

编程入门 行业动态 更新时间:2024-10-25 02:23:21
本文介绍了如何在厨师仓库中的厨师食谱之间共享代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在厨师仓库中分享一些食谱中的少量方法。我知道在烹饪书级别上,我可以将代码放在库目录中的模块中(请参阅相关问题)。我正在寻找的是类似的东西,但是可以在我的厨师仓库中的所有食谱中找到。

I would like to share a small handful of methods across recipes in a chef repo. I know that on a cookbook level I can put code in modules in the libraries directory (see related question). What I'm looking for is something like that but available across all of the cookbooks in my Chef repo.

我可以想到一些解决方案:

I can think of a couple solutions:

  • 创建一个gem,并将其安装为厨师运行的一部分。
  • 将文件放在某个文件夹中,然后将该文件夹添加到配方文件中的 $ LOAD_PATH 中。我感觉无法在实际部署中使用,因为Chef服务器对存储库一无所知。
  • 将文件放在某个文件夹中,并将其符号链接到以下目录中每本食谱。
  • Create a gem, install the gem as part of the chef run. This seems like overkill.
  • Put the file in some folder and add that folder to the $LOAD_PATH in the recipe file. I have a feeling that won't work with actual deployment because the chef server doesn't know anything about the repo.
  • Put the file in some folder and symlink that into the libraries directory of each cookbook.

最后一个选项似乎是最可行的。有没有更好/更惯用的方式来做我想要的事情?

The last option seems like the most viable. Is there a better/more idiomatic way to do what I want?

推荐答案

您可以使用其他食谱中的库定义函数,但是您必须告诉厨师您的食谱取决于提供的食谱。

You can use a library defined function from another cookbook but you must teach Chef that your cookbook depends on the providing cookbook.

例如,如果在食谱中A,您有一个 libraries / default.rb 提供一些功能 f ,您可以从食谱B中访问它,因此只要B的 metadata.rb 文件包含以下行:

So, for example, if in cookbook A, you have a libraries/default.rb that provides some function f, you can access it from cookbook B so long as B's metadata.rb file includes the line:

depends "A"

请参阅元数据和库了解更多详细信息

See the Chef documentation on metadata and libraries for more details.

更多推荐

如何在厨师仓库中的厨师食谱之间共享代码?

本文发布于:2023-11-06 21:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564753.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:厨师   食谱   仓库   代码   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!