我们真正想要的是部署 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