What we really want is for the deploy LWRP to be able to specify the branch to the GIT. Ideally this is pulled off of an environment attirbute.
我们真正想要的是部署LWRP能够指定GIT的分支。理想情况下,这是从环境中获得的。
we are calling it like this :
我们这样称呼它:
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
The branch above is not working..
上面的分支不起作用..
LWRP Resource
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 provider
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
1 个解决方案
#1
0
Problem here is you are using an LWRP (that you must already have available in your Chef environment) and then hoping to run it as one or more other GIT branches (that are possibly not loaded in the Chef environment.)
这里的问题是您正在使用LWRP(您必须已在Chef环境中使用),然后希望将其作为一个或多个其他GIT分支(可能未在Chef环境中加载)运行。
If you set up your branches right, you could include each branch as a different cookbook (see docs for Berkshelf or Librarian for details on spec'ing a branch.) For example, you might have berkshelf lines like this:
如果你正确设置了分支,你可以将每个分支包含在不同的食谱中(有关指定分支的详细信息,请参阅Berkshelf或Librarian的文档。)例如,您可能有这样的berkshelf行:
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
I think the branch cookbooks would have to have these unique names internally (e.g. "mycookbook_branch1".) It's messy but if you make each branch accessible in your Chef environment, you might have a fighting chance to select the desired (branched) resource.
我认为分支烹饪书必须在内部具有这些独特的名称(例如“mycookbook_branch1”。)它很麻烦但是如果你在Chef环境中使每个分支都可访问,那么你可能有机会选择所需的(分支的)资源。
Obviously I don't know the details, but on the surface it seems simpler to just create each of the possible resources (with different names) in the master branch and select the right one in your recipe. If that becomes really un-DRY, you can always extract a module, etc.
显然我不知道细节,但从表面上看,在主分支中创建每个可能的资源(具有不同的名称)并在您的食谱中选择正确的资源似乎更简单。如果真的变得非干,你可以随时提取模块等。
#1
0
Problem here is you are using an LWRP (that you must already have available in your Chef environment) and then hoping to run it as one or more other GIT branches (that are possibly not loaded in the Chef environment.)
这里的问题是您正在使用LWRP(您必须已在Chef环境中使用),然后希望将其作为一个或多个其他GIT分支(可能未在Chef环境中加载)运行。
If you set up your branches right, you could include each branch as a different cookbook (see docs for Berkshelf or Librarian for details on spec'ing a branch.) For example, you might have berkshelf lines like this:
如果你正确设置了分支,你可以将每个分支包含在不同的食谱中(有关指定分支的详细信息,请参阅Berkshelf或Librarian的文档。)例如,您可能有这样的berkshelf行:
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
I think the branch cookbooks would have to have these unique names internally (e.g. "mycookbook_branch1".) It's messy but if you make each branch accessible in your Chef environment, you might have a fighting chance to select the desired (branched) resource.
我认为分支烹饪书必须在内部具有这些独特的名称(例如“mycookbook_branch1”。)它很麻烦但是如果你在Chef环境中使每个分支都可访问,那么你可能有机会选择所需的(分支的)资源。
Obviously I don't know the details, but on the surface it seems simpler to just create each of the possible resources (with different names) in the master branch and select the right one in your recipe. If that becomes really un-DRY, you can always extract a module, etc.
显然我不知道细节,但从表面上看,在主分支中创建每个可能的资源(具有不同的名称)并在您的食谱中选择正确的资源似乎更简单。如果真的变得非干,你可以随时提取模块等。