如何在 IDE(如 Eclipse)中开发和调试 Chef 食谱和食谱?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7800562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I develop and debug Chef cookbooks and recipes in an IDE (like Eclipse)?
提问by gene_wood
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.
我是 ruby 和 Chef 的新手。我一直在开发食谱,提交它们,将它们上传到 Chef 服务器,然后将它们部署到 Chef 客户端,并更改角色,然后在客户端上运行“厨师客户端”。这个过程很慢。
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?
我如何使用 IDE(在我的情况下为 Eclipse)开发食谱并能够调试(设置断点、观察变量等)并运行它们,而无需将它们上传到 Chef 服务器,然后使用厨师客户端将它们拉回跑?
- 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)
- 我将 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 Server(开源)
回答by Autodidact
I was also searching for this kind of tool.
我也在寻找这种工具。
Found this one that shows the shef to do it.
找到了这个显示 Shef 这样做的。
http://stevendanna.github.com/blog/2012/01/28/shef-debugging-tips-1/
http://stevendanna.github.com/blog/2012/01/28/shef-debugging-tips-1/
回答by Giorgio
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.
您可以将 Eclipse 用作 Chef Cookbooks 的简单编辑器。你不会有任何 IDE 支持和调试,但像我这样的人可能更喜欢它。
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.
如果您将在 Eclipse 上使用 Ruby 编辑器,您可能会获得 .rb Ruby 文件的语法高亮显示,但我还没有尝试过。
You can make any folder an Eclipse Project (for example the chef-repo OR a specific cookcook) by adding a .project file with inside:
您可以通过在里面添加一个 .project 文件,将任何文件夹设为 Eclipse 项目(例如,chef-repo 或特定的厨师):
<?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.
然后在 Eclipse 中选择 File -> Import -> General -> Existing Projects into Workspace 并选择添加 .project 文件的文件夹。
回答by Joel Handwell
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.
对于 Eclipse Ruby 开发工具,截至 2015 年 5 月 13 日,不支持厨师食谱,但如果您愿意,可以使用专有替代方案。
RubyMine 7 IDEsupports Chefwith Auto complete and definition navigation for standard Chef resources and their attributes. Ruby Mine is based on Intellij IDEA.
RubyMine 7 IDE支持 Chef与标准 Chef 资源及其属性的自动完成和定义导航。Ruby Mine 基于 Intellij IDEA。
Instead of RubyMine, this feature works with Intellij IDEA if you install the Chef integration pluginon top of ruby plugin
如果您在ruby 插件之上安装Chef 集成插件,则此功能可与 Intellij IDEA 一起使用,而不是 RubyMine
If you are student or teachers, or is for education or training, or for open source projects, you can apply for free license.
回答by KronnorK
May be it is already known but currently we can use ATOM with additional packages language-chef, linter-foodcritic, linter-ruby
可能已经知道了,但目前我们可以将 ATOM 与附加包 language-chef、linter-foodcritic、linter-ruby 一起使用
回答by rleibman
The answer is not so simple, as of today Opscode doesn't have an "an official plugin".
答案并没有那么简单,直到今天 Opscode 还没有“官方插件”。
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)
在过去的几个晚上,我为 Eclipse 创建了一个厨师插件。现在它非常简单,如果其他人对它表现出兴趣,我也可能会添加更多......现在它完成了我需要的大部分工作(创建新食谱、添加食谱、属性、lwrps 等),大多数情况下,我会在厨师工具(厨师、伯克斯、厨房、美食评论家等)周围放置一个 Eclipse 包装器
https://github.com/rleibman/chef-eclipse-plugin
https://github.com/rleibman/chef-eclipse-plugin
I have no intention of removing this plugin, unless opscode comes up with their own.
我无意删除这个插件,除非 opscode 有自己的。
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/.
我在本教程的巨大帮助下开始创建这个插件:https: //cvalcarcel.wordpress.com/2009/07/08/writing-an-eclipse-plug-in-part-1-what-im-going-to -做/。
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:
现在,说了这么多......如果你对命令行感到满意,你可以用已经存在的东西做你需要的大部分事情:用berks或chef创建一本食谱,例如:
chef generate cookbook my_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.
然后在eclipse中创建一个新的ruby项目,打开你刚刚创建的cookbook。创建后,您可以编辑 ruby 文件等。您还可以使用所有其他厨师功能(例如厨师生成食谱)来帮助您入门。
回答by user2002289
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.
- 将 Chef 作为 ruby 项目导入通常会失败,因为导入器似乎无法将 Chef 特定的结构(如“食谱”等)识别为源位置。你所看到的只是 ruby 解释器库
- 强制 ruby 导入手动查看文件夹作为源(声明源文件夹)也失败,因为文件夹和任何子文件夹中的代码不可见
- 作为通用项目导入,可以显示所有基于Chef的结构体及其代码,但是代码不被识别为ruby代码,并且没有语法相关的能力
- 作为一般项目导入,然后添加 ruby buildspec 和 ruby nature确实有效。所有文件都是可见的,并且可以使用 ruby 编辑器进行编辑并突出显示语法。
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!
我怀疑是否有任何调试等——这不是我的目标,因为我在 Linux 上运行,但至少我们有一个不错的编辑器和 git 集成!
For safety, also copied the .buildpath file to the project location ... not sure its necessary. The generic contents are:
为了安全起见,还将 .buildpath 文件复制到项目位置......不确定是否有必要。通用内容是:
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path=""/>
<buildpathentry kind="con" path="org.eclipse.dltk.launching.INTERPRETER_CONTAINER"/>
</buildpath>
回答by jodell
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:
我倾向于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']
Setting log_level
to debug helps quite a bit when cycling with the runner.
log_level
与跑步者一起骑自行车时,设置调试很有帮助。