From 707e6025c87189a6be03997b409e5b8f9f8adc97 Mon Sep 17 00:00:00 2001 From: Tomasz Setkowski Date: Thu, 10 Dec 2015 23:02:37 +0000 Subject: [PATCH] #58 gocd_plugin resource --- .kitchen.openstack.yml | 3 ++- README.md | 12 ++++++++++++ libraries/matchers.rb | 3 +++ providers/plugin.rb | 16 +++++++++++++++ resources/plugin.rb | 7 +++++++ spec/plugin_lwrp_spec.rb | 24 +++++++++++++++++++++++ test/test_cookbook/recipes/plugin_lwrp.rb | 5 +++++ 7 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 providers/plugin.rb create mode 100644 resources/plugin.rb create mode 100644 spec/plugin_lwrp_spec.rb create mode 100644 test/test_cookbook/recipes/plugin_lwrp.rb diff --git a/.kitchen.openstack.yml b/.kitchen.openstack.yml index da8919c..5283b77 100644 --- a/.kitchen.openstack.yml +++ b/.kitchen.openstack.yml @@ -11,7 +11,7 @@ platforms: box: 'debian-7.8-bpk-chef-12.4.1' customize: server_name: 'kt-go' - flavor: 'v.c1.m1536.d5.e0' + flavor: 'v.c1.m2048.d5.e0' server_create_timeout: 540 server_active_timeout: 540 @@ -19,6 +19,7 @@ suites: - name: default run_list: - recipe[gocd] + - recipe[gocd_test::plugin_lwrp] attributes: java: jdk_version: 7 diff --git a/README.md b/README.md index c169aeb..82c7798 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,18 @@ gocd_agent 'my-go-agent' do end ``` +# GoCD plugin LWRP + +You can install Go server plugins with `gocd_plugin` LWRP like this + +```ruby +include_recipe 'gocd::server' + +gocd_plugin 'github-pr-status' do + plugin_uri 'https://github.com/gocd-contrib/gocd-build-status-notifier/releases/download/1.1/github-pr-status-1.1.jar' +end +``` + # License Apache License, Version 2.0 diff --git a/libraries/matchers.rb b/libraries/matchers.rb index 3cdbd83..ff9fdad 100644 --- a/libraries/matchers.rb +++ b/libraries/matchers.rb @@ -5,4 +5,7 @@ def create_gocd_agent(resource_name) def delete_gocd_agent(resource_name) ChefSpec::Matchers::ResourceMatcher.new(:gocd_agent, :delete, resource_name) end + def create_gocd_plugin(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:gocd_plugin, :create, resource_name) + end end diff --git a/providers/plugin.rb b/providers/plugin.rb new file mode 100644 index 0000000..1f7c18d --- /dev/null +++ b/providers/plugin.rb @@ -0,0 +1,16 @@ +use_inline_resources + +action :create do + run_context.include_recipe 'gocd::server_linux_install' + + plugin_name = new_resource.plugin_name + server_work_dir = new_resource.server_work_dir + plugin_uri = new_resource.plugin_uri + remote_file "#{server_work_dir}/plugins/external/#{plugin_name}.jar" do + source plugin_uri + owner 'go' + group 'go' + mode 0770 + retries 5 + end +end diff --git a/resources/plugin.rb b/resources/plugin.rb new file mode 100644 index 0000000..be41163 --- /dev/null +++ b/resources/plugin.rb @@ -0,0 +1,7 @@ +actions :create, :delete + +default_action :create if defined?(default_action) + +attribute :plugin_name, :name_attribute => true, :kind_of => String, :required => true +attribute :plugin_uri, :kind_of => String, :required => true +attribute :server_work_dir, :kind_of => String, :required => false, :default => node['gocd']['server']['work_dir'] diff --git a/spec/plugin_lwrp_spec.rb b/spec/plugin_lwrp_spec.rb new file mode 100644 index 0000000..a579192 --- /dev/null +++ b/spec/plugin_lwrp_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe 'gocd_test::plugin_lwrp' do + let(:chef_run) do + run = ChefSpec::SoloRunner.new(step_into: 'gocd_plugin') do |node| + node.automatic['lsb']['id'] = 'Debian' + node.automatic['platform_family'] = 'debian' + node.automatic['platform'] = 'debian' + node.automatic['os'] = 'linux' + end + run.converge(described_recipe) + end + + it 'creates gocd_plugin chef resource' do + expect(chef_run).to create_gocd_plugin('github-pr-status') + end + it 'downloads github-pr-status plugin as a remote_file' do + expect(chef_run).to create_remote_file('/var/lib/go-server/plugins/external/github-pr-status.jar') + .with( + source: 'https://github.com/gocd-contrib/gocd-build-status-notifier/releases/download/1.1/github-pr-status-1.1.jar', + owner: 'go' + ) + end +end diff --git a/test/test_cookbook/recipes/plugin_lwrp.rb b/test/test_cookbook/recipes/plugin_lwrp.rb new file mode 100644 index 0000000..9f1059c --- /dev/null +++ b/test/test_cookbook/recipes/plugin_lwrp.rb @@ -0,0 +1,5 @@ +include_recipe 'gocd::server' + +gocd_plugin 'github-pr-status' do + plugin_uri 'https://github.com/gocd-contrib/gocd-build-status-notifier/releases/download/1.1/github-pr-status-1.1.jar' +end