如何在 IDE(如 Eclipse)中开发和调试 Chef 食谱和菜谱?

发布于 2024-12-11 00:46:26 字数 481 浏览 0 评论 0 原文

我是 ruby​​ 和 Chef 的新手。我一直在开发食谱,提交它们,将它们上传到 Chef 服务器,然后将它们部署到 Chef 客户端,并进行角色更改,然后在客户端上运行“厨师客户端”。这个过程很慢。

我如何使用 IDE(在我的例子中为 Eclipse)开发食谱并能够调试(设置断点、监视变量等)并运行它们,而无需将它们上传到 Chef 服务器,然后使用厨师客户端将它们拉回跑步?

  • 我正在使用 Eclipse 3.7 Indigo 和“Dynamic Languages Toolkit - Ruby Development Tools 3.0.0.v20110424-7Z--E_EkMYXO4k101442”插件
  • 我正在使用 10.x Chef 代码线开发 Opscode Chef 食谱
  • 我正在 Ubuntu 上工作10.10 系统开发在 RHEL/Centos 5 上运行的食谱服务器
  • 我们运行自己的 Chef 服务器(开源)

I'm new to ruby and Chef. I've been developing cookbooks, committing them, uploading them to the Chef Server then deploying them to a Chef client with a role change followed by a "chef-client" run on the client. This process is slow.

How can I, using an IDE (Eclipse in my case), develop cookbooks and be able to debug (set breakpoints, watch variables etc) and run them without uploading them to the Chef Server and then pulling them back down with a chef-client run?

  • I'm using Eclipse 3.7 Indigo with the "Dynamic Languages Toolkit - Ruby Development Tools 3.0.0.v20110424-7Z--E_EkMYXO4k101442" plugin
  • I'm developing Opscode Chef cookbooks with the 10.x Chef codeline
  • I'm working on an Ubuntu 10.10 system developing cookbooks to be run on RHEL/Centos 5 servers
  • We run our own Chef Server (open source)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

醉态萌生 2024-12-18 00:46:26

我也在寻找这样的工具。

找到了这个展示架子如何做的东西。

http://stevendanna.github.com/blog/ 2012/01/28/shef-debugging-tips-1/

I was also searching for this kind of tool.

Found this one that shows the shef to do it.

http://stevendanna.github.com/blog/2012/01/28/shef-debugging-tips-1/

江挽川 2024-12-18 00:46:26

您可以使用 Eclipse 作为 Chef Cookbooks 的简单编辑器。您不会有任何 IDE 支持和调试,但像我这样的人可能更喜欢它。

如果您在 Eclipse 上使用 Ruby 编辑器,您可能会获得 .rb Ruby 文件的语法高亮显示,但我还没有尝试过。

您可以通过添加包含以下内容的 .project 文件将任何文件夹设为 Eclipse 项目(例如 Chef-repo 或特定的 Cookcook):

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>PROJECT_NAME</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
    </buildSpec>
    <natures>
    </natures>
</projectDescription>

然后在 Eclipse 中选择 File ->导入->一般->将现有项目放入工作区并选择添加 .project 文件的文件夹。

You can use Eclipse as a simple editor for Chef Cookbooks. You won't have any IDE support and debug but some people like me might prefer it anyway.

If you would use a Ruby Editor on Eclipse you might get syntax highlighting for .rb Ruby files but I didn't try this yet.

You can make any folder an Eclipse Project (for example the chef-repo OR a specific cookcook) by adding a .project file with inside:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>PROJECT_NAME</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
    </buildSpec>
    <natures>
    </natures>
</projectDescription>

Then in Eclipse choose File -> Import -> General -> Existing Projects into Workspace and choose the folder where you added the .project file.

温柔嚣张 2024-12-18 00:46:26

对于 Eclipse Ruby 开发工具,截至 2015 年 5 月 13 日,不支持厨师食谱,但是如果您需要,可以使用专有的替代方案。

RubyMine 7 IDE 支持 Chef,对标准 Chef 资源及其属性进行自动完成和定义导航。 Ruby Mine 基于 Intellij IDEA。

如果您安装 Chef 集成插件,则此功能可与 Intellij IDEA 配合使用,而不是 RubyMine在 ruby 插件

如果您是学生或教师,或者是 用于教育或培训,或 用于开源项目,您可以申请免费许可证。

For Eclipse Ruby Development Tools, there is no support for chef cookbooks as of 2015 May 13th, however there is proprietary alternative if you want.

RubyMine 7 IDE supports Chef with Auto complete and definition navigation for standard Chef resources and their attributes. Ruby Mine is based on Intellij IDEA.

Instead of RubyMine, this feature works with Intellij IDEA if you install the Chef integration plugin on top of ruby plugin

If you are student or teachers, or is for education or training, or for open source projects, you can apply for free license.

愿得七秒忆 2024-12-18 00:46:26

可能已经众所周知,但目前我们可以将 ATOM 与附加包 language-chef、linter-foodcritic、linter-ruby

https://原子.io/

May be it is already known but currently we can use ATOM with additional packages language-chef, linter-foodcritic, linter-ruby

https://atom.io/

最好是你 2024-12-18 00:46:26

答案并不那么简单,截至目前 Opscode 还没有“官方插件”。

过去几个晚上我为 Eclipse 创建了一个 Chef 插件。现在它非常简单,如果其他人表现出兴趣,我也可能会添加更多...现在它完成了我需要的大部分工作(创建新的食谱,添加食谱,属性,lwrps 等),大多数情况下,我在厨师工具(chef、berks、kitchen、foodcritic 等)周围放置了一个 eclipse 包装器

https://github.com/rleibman/chef-eclipse-plugin

我无意删除这个插件,除非 opscode 推出自己的插件。

我在本教程的大力帮助下开始创建这个插件: https://cvalcarcel.wordpress.com/2009/07/08/writing-an-eclipse-plug-in-part-1-what-im-going-to-do/

现在,说了这么多......如果您熟悉命令行,您可以使用已有的东西来完成您需要的大部分操作:使用 berks 或 Chef 创建一本食谱,例如:

chefgeneratecookbookmy_cookbook

然后在 eclipse 中创建一个新的 ruby​​ 项目,打开您刚刚创建的食谱。创建后,您可以编辑 ruby​​ 文件等。您还可以使用所有其他厨师功能(例如厨师生成食谱)来帮助您入门。

The answer is not so simple, as of today Opscode doesn't have an "an official plugin".

I spent the past few evenings creating a chef plugin for eclipse. It's very bare bones right now, if other people show interest in working on it I might add more as well... For now it does most of what I need (creating new cookbooks, adding recipes, attributes, lwrps, etc.), mostly I'm putting an eclipse wrapper around the chef tools (chef, berks, kitchen, foodcritic, etc)

https://github.com/rleibman/chef-eclipse-plugin

I have no intention of removing this plugin, unless opscode comes up with their own.

I got started creating this plugin with great help from this tutorial: https://cvalcarcel.wordpress.com/2009/07/08/writing-an-eclipse-plug-in-part-1-what-im-going-to-do/.

Now, having said all of this... if you're comfortable with the command line, you can do most of what you need with things that are already there: create a cookbook with either berks or chef, e.g:

chef generate cookbook my_cookbook

And then create a new ruby project in eclipse opened to the cookbook you just created. Once it's created, you can edit ruby files, etc. You can also use all the other chef features (e.g. chef generate recipe) as well to help you get started.

淡紫姑娘! 2024-12-18 00:46:26

我倾向于在目标虚拟机上使用 chef-solo。我将查看我的食谱存储库,并使用模板化的 solo.rb 在本地进行迭代:

path File.expand_path(File.dirname(__FILE__))
cookbook_path "#{File.expand_path(File.dirname(__FILE__))}/cookbooks"
log_level ENV['CHEF_LOG_LEVEL'] && ENV['CHEF_LOG_LEVEL'].downcase.to_sym || :info
log_location ENV['CHEF_LOG_LOCATION'] || STDOUT
verbose_logging ENV['CHEF_VERBOSE_LOGGING']

设置 log_level 进行调试在与跑步者一起骑行时有很大帮助。

I tend to use chef-solo on a target virtual machine. I'll check out my cookbooks repo and iterate locally with a templated solo.rb:

path File.expand_path(File.dirname(__FILE__))
cookbook_path "#{File.expand_path(File.dirname(__FILE__))}/cookbooks"
log_level ENV['CHEF_LOG_LEVEL'] && ENV['CHEF_LOG_LEVEL'].downcase.to_sym || :info
log_location ENV['CHEF_LOG_LOCATION'] || STDOUT
verbose_logging ENV['CHEF_VERBOSE_LOGGING']

Setting log_level to debug helps quite a bit when cycling with the runner.

是伱的 2024-12-18 00:46:26

在 Kepler 上做了一些工作,发现:

  • 将 Chef 作为 ruby​​ 项目导入通常会失败,因为导入器似乎无法识别厨师特定的结构(如“食谱”等)作为源位置。您看到的只是 ruby​​ 解释器库
  • 强制 ruby​​ 导入以手动将文件夹视为源(声明源文件夹)也会失败,因为文件夹和任何子文件夹中的代码都不可见
  • 作为一般项目导入会显示所有内容基于 Chef 的结构及其代码,但代码不被识别为 ruby​​ 代码,并且没有与语法相关的功能
  • 作为一般项目导入,然后随后添加 ruby​​ buildspec 和 ruby​​ nature 确实有效。 所有文件是可见的,并且可以使用 ruby​​ 编辑器进行编辑并突出显示语法。

简而言之,添加这一点:

<buildSpec>
    <buildCommand>
        <name>org.eclipse.dltk.core.scriptbuilder</name>
        <arguments></arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.dltk.ruby.core.nature</nature>
</natures>

我怀疑是否有任何调试等——这不是我的目标,因为我在 Linux 上运行,但至少我们有一个像样的编辑器和 git 集成!

为了安全起见,还将 .buildpath 文件复制到项目位置...不确定是否有必要。通用内容是:

<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
  <buildpathentry kind="src" path=""/>
  <buildpathentry kind="con" path="org.eclipse.dltk.launching.INTERPRETER_CONTAINER"/>
</buildpath>

Did some work on Kepler and found that:

  • Importing Chef as a ruby project typically fails because the importer seems unable to recognize the chef-specific structures like "cookbooks", etc. as locations for source. All you see is the ruby interpreter library
  • Forcing a ruby import to see the folders as source by hand (declare source folder) also fails because the code in the folder and any subfolders are not visible
  • Importing as a general project works in terms of displaying all the Chef-based structures and their code, but the code is not recognized as ruby code, and there is no syntax related capabilities
  • Importing as a general project, then subsequently adding a ruby buildspec and ruby nature does work. All files are visible, and editing with ruby editor is available with syntax highlighting.

In short, add this:

<buildSpec>
    <buildCommand>
        <name>org.eclipse.dltk.core.scriptbuilder</name>
        <arguments></arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.dltk.ruby.core.nature</nature>
</natures>

I doubt there's any debugging, etc -- not my goal, as I run on Linux, but at least we have a decent editor and git integration!

For safety, also copied the .buildpath file to the project location ... not sure its necessary. The generic contents are:

<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
  <buildpathentry kind="src" path=""/>
  <buildpathentry kind="con" path="org.eclipse.dltk.launching.INTERPRETER_CONTAINER"/>
</buildpath>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文