我正在创建一堆不同的 Chef 提供程序来部署不同类型的应用程序。厨师的文档扩展轻量级提供程序表明这是可能的,但实际上并没有说明要做什么。该页面表明也许可以调用mixin
是需要的,但我不知道我的代码在下面的文件中应该有什么结构/libraries
或者如何将该代码实际包含在下面的内容中/providers
.
以下是我想做的事情的示例。
在我的基类下/libraries
:
repository "http://my.svn.server/#{deployment[:project]}/branches/#{node[:chef_environment]}/"
user "deploy"
scm_provider Chef::Provider::Subversion
svn_username "svn_user"
svn_password "password"
在我的 Torquebox Rails 应用程序部署提供程序中:
deploy_revision "/my/deployment/directory/#{deployment[:project]}" do
# Magically mixin the code from libraries
environment "RAILS_ENV" => node[:chef_environment]
restart_command "rake torquebox:deploy"
end
当然还有针对不同类型应用程序的其他类型的提供商。
谁能指出我在这方面的正确方向?我缺少什么文档吗?
厨师会自动将 LWRP DSL 转换为成熟的 Ruby 类在运行时。这是由说明书的名称和文件名决定的(这与创建实际资源名称的方式相同)。
所以如果你有一本名为bacon
和一个 LWRPbacon/resources/eat.rb
,相关的 LWRP 为bacon_eat
。相关的class是驼峰式的、恒定的版本 -Chef::Resource::BaconEat
and Chef::Provider::BaconEat
在这种情况下。
这种模式有一个例外 -default
。 “默认”在厨师领域很特别,因为它doesn't获得前缀。所以如果你有一本名为bacon
和一个 LWRPbacon/resources/default.rb
,相关的 LWRP 为bacon
(not bacon_default
)。相关的class是驼峰式的、恒定的版本 -Chef::Resource::Bacon
and Chef::Provider::Bacon
(不是“BaconDefault”)在这种情况下。
好吧,那为什么要讲背景故事呢?为了扩展 LWRP,您需要继承 LWRP 的类(Rubyism)。所以在你的libraries/
目录,您想要扩展您的自定义资源:
class Chef
class Resource::MyResource < Resource::Bacon # <- this
end
end
所以,在你的例子中:
class Chef
class Resource::MyDeployRevision < Resource::DeployRevision
def initialize(name, run_context = nil)
super
# This is what you'll use in the recipe DSL
@resource_name = :my_deploy_revision
# Things like default action and parameters are inherited from the parent
# Set your default options here
@repository = "http://my.svn.server/#{node['deployment']['project']}/branches/#{node.chef_environment}/"
@user = 'deploy'
@scm_provider = Chef::Provider::Subversion
@svn_username = 'svn_user'
@svn_password = 'password'
end
end
end
然后使用my_deploy_revision
在你的食谱中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)