我们真正想要的是让deploy LWRP能够指定GIT的分支。理想情况下,这是从环境属性中提取出来的。
我们这样命名它:
my_deploy 'install my-client-portal' do
repo 'https://hqdevgit01.my.lan/sites/my-client-portal.git'
destination '/var/sites/my-client-portal'
action :installNodeFromGit
branch node[:my_deploy][:branch_name]
end上面的分支不工作..
LWRP资源
actions :installNodeFromGit
default_action :installNodeFromGit if defined?(default_action)
attribute :repo, :kind_of => String, :required => true
attribute :destination, :kind_of => String, :required => true
attribute :branch, :kind_of => String, :required => false, :default => 'master'LWRP提供程序
use_inline_resources
action :installNodeFromGit do
converge_by("Installing.") do
resp = install
@new_resource.updated_by_last_action(resp)
end
end
def load_current_resource
@current_resource = Chef::Resource::MyDeploy.new(@new_resource.name)
@current_resource.repo(@new_resource.repo)
@current_resource.destination(@new_resource.destination)
@current_resource.branch(@new_resource.branch)
end
def install
ENV['GIT_SSL_NO_VERIFY']="true"
directory new_resource.destination do
owner 'root'
group 'root'
mode '0755'
action :create
recursive true
end
git new_resource.destination do
repository new_resource.repo
action :sync
revision new_resource.branch
end
if new_resource.destination
path = new_resource.destination
cmd = "npm install"
execute "npm install at #{path}" do
cwd path
command cmd
end
end
end发布于 2015-08-29 03:09:24
这里的问题是您正在使用LWRP (您必须在Chef环境中已经有),然后希望将其作为一个或多个其他GIT分支运行(这些分支可能没有加载到Chef环境中)。
如果您正确地设置了分支,则可以将每个分支作为不同的食谱包含在内(有关指定分支的详细信息,请参阅Berkshelf或Librarian的文档)。例如,您可能具有如下所示的this架线:
cookbook "mycookbook", git: "https://github.com/my_git/mycookbook.git", branch: "master"
cookbook "mycookbook_branch1", git: "https://github.com/my_git/mycookbook.git", branch: "branch1"
# etc我认为分支机构的食谱必须在内部使用这些唯一的名称(例如“mycookbook_branch1”)。这很混乱,但如果您在Chef环境中使每个分支都可以访问,那么您可能有机会选择所需的(分支的)资源。
显然我不知道细节,但从表面上看,在主分支中创建每个可能的资源(具有不同的名称)并在配方中选择正确的资源似乎更简单。如果它变得非常不干燥,你总是可以提取一个模块,等等。
https://stackoverflow.com/questions/32002328
复制相似问题