From 27adeed972a75cb19cca61b519abcef870388e51 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 22 Feb 2016 07:46:35 -0500 Subject: [PATCH 01/18] Add the consul_installation set of resources. These custom resources move the logic of managing the system's Consul installation separate from the custom resource for managing the service. --- libraries/consul_installation_binary.rb | 77 +++++++++++++++ libraries/consul_installation_git.rb | 68 ++++++++++++++ libraries/consul_installation_package.rb | 50 ++++++++++ libraries/consul_installation_web_ui.rb | 66 +++++++++++++ libraries/helpers_installation_binary.rb | 115 +++++++++++++++++++++++ libraries/helpers_installation_web_ui.rb | 31 ++++++ 6 files changed, 407 insertions(+) create mode 100644 libraries/consul_installation_binary.rb create mode 100644 libraries/consul_installation_git.rb create mode 100644 libraries/consul_installation_package.rb create mode 100644 libraries/consul_installation_web_ui.rb create mode 100644 libraries/helpers_installation_binary.rb create mode 100644 libraries/helpers_installation_web_ui.rb diff --git a/libraries/consul_installation_binary.rb b/libraries/consul_installation_binary.rb new file mode 100644 index 00000000..4564d71a --- /dev/null +++ b/libraries/consul_installation_binary.rb @@ -0,0 +1,77 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# +require 'poise' + +module ConsulCookbook + module Resource + # A `consul_installation` resource which manages the Consul installation + # from an binary. + # @action create + # @action remove + # @provides consul_installation + # @provides consul_installation_binary + # @since 1.5 + class ConsulInstallationBinary < Chef::Resource + include Poise(fused: true) + include Helpers::InstallationBinary + provides(:consul_installation) + provides(:consul_installation_binary) + + # @!attribute version + # @return [String] + attribute(:version, kind_of: String, default: lazy { default_version }) + # @!attribute binary_url + # @return [String] + attribute(:binary_url, kind_of: String, required: true) + # @!attribute binary_path + # @return [String, NilClass] + attribute(:binary_path, kind_of: [String, NilClass], default: nil) + # @!attribute binary_checksum + # @return [String] + attribute(:binary_checksum, kind_of: String, default: lazy { default_checksum }) + + action(:create) do + notifying_block do + basename = ::File.basename(new_resource.url) + remote_file ::File.join(Chef::Config[:file_cache_path], basename) do + not_if { new_resource.binary_path } + end + + artifact = libartifact_file "consul-#{new_resource.version}" do + artifact_name 'consul' + artifact_version new_resource.version + install_path new_resource.target_path + remote_url binary_url + remote_checksum new_resource.binary_checksum + end + + link '/usr/local/bin/consul' do + to ::File.join(artifact.current_path, 'consul') + end + end + end + + action(:remove) do + notifying_block do + artifact = libartifact_file "consul-#{new_resource.version}" do + artifact_name 'consul' + artifact_version new_resource.version + install_path new_resource.target_path + remote_url binary_url + remote_checksum new_resource.binary_checksum + action :delete + end + + link '/usr/local/bin/consul' do + to ::File.join(binary.current_path, 'consul') + action :delete + end + end + end + end + end +end diff --git a/libraries/consul_installation_git.rb b/libraries/consul_installation_git.rb new file mode 100644 index 00000000..b6c97421 --- /dev/null +++ b/libraries/consul_installation_git.rb @@ -0,0 +1,68 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# +require 'poise' + +module ConsulCookbook + module Resource + # A `consul_installation` resource which manages the Consul installation + # from the main git repository. + # @action create + # @action remove + # @provides consul_installation + # @provides consul_installation_git + # @since 1.5 + class ConsulInstallationGit < Chef::Resource + include Poise(fused: true) + provides(:consul_installation_git) + + # @!attribute git_url + # @return [String] + attribute(:git_url, kind_of: String, required: true) + # @!attribute git_ref + # @return [String] + attribute(:git_ref, kind_of: String, default: 'master') + # @!attribute git_path + # @return [String] + attribute(:git_path, kind_of: String, default: '/usr/local/src/consul') + + action(:create) do + notifying_block do + include_recipe 'golang::default' + + git new_resource.git_path do + repository new_resource.git_url + reference new_resource.git_ref + action :checkout + end + + golang_package 'github.com/hashicorp/consul' do + action :install + end + + link '/usr/local/bin/consul' do + to ::File.join(new_resource.git_path, 'bin', 'consul') + end + end + end + + action(:remove) do + notifying_block do + directory new_resource.git_path do + recursive true + action :delete + end + + link ::File.join(new_resource.git_path, 'bin', 'consul') do + to new_resource.target_path + only_if { new_resource.target_path } + action :delete + end + end + end + end + end +end diff --git a/libraries/consul_installation_package.rb b/libraries/consul_installation_package.rb new file mode 100644 index 00000000..3ad65d06 --- /dev/null +++ b/libraries/consul_installation_package.rb @@ -0,0 +1,50 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +require 'poise' + +module ConsulCookbook + module Resource + # A `consul_installation_package` resource. + # @action create + # @action remove + # @provides consul_installation + # @provides consul_installation_package + # @since 1.5 + class ConsulInstallationPackage < Chef::Resource + include Poise(fused: true) + provides(:consul_installation_package) + + # @!attribute package_version + # @return [String] + attribute(:package_version, kind_of: String, name_attribute: true) + # @!attribute package_name + # @return [String] + attribute(:package_name, kind_of: String, default: 'consul') + # @!attribute package_source + # @return [String] + attribute(:package_source, kind_of: String) + + action(:create) do + notifying_block do + package new_resource.package_name do + version new_resource.package_version if new_resource.package_version + source new_resource.package_source if new_resource.package_source + action :upgrade + end + end + end + + action(:remove) do + notifying_block do + package new_resource.package_name do + version new_resource.package_version if new_resource.package_version + action :remove + end + end + end + end + end +end diff --git a/libraries/consul_installation_web_ui.rb b/libraries/consul_installation_web_ui.rb new file mode 100644 index 00000000..54f8a07d --- /dev/null +++ b/libraries/consul_installation_web_ui.rb @@ -0,0 +1,66 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# +require 'poise' + +module ConsulCookbook + module Resource + # A `consul_installation` resource which manages the Consul Web UI + # installation from an binary. + # @action create + # @action remove + # @provides consul_installation_web_ui + # @since 1.5 + class ConsulInstallationWebUi < Chef::Resource + include Poise(fused: true) + include Helpers::InstallationWebUi + provides(:consul_installation_web_ui) + + # @!attribute version + # @return [String] + attribute(:version, kind_of: String, default: lazy { default_version }) + # @!attribute binary_url + # @return [String] + attribute(:binary_url, kind_of: String, required: true) + # @!attribute binary_path + # @return [String, NilClass] + attribute(:binary_path, kind_of: [String, NilClass], default: nil) + # @!attribute binary_checksum + # @return [String] + attribute(:binary_checksum, kind_of: String, lazy { default_checksum }) + + action(:create) do + notifying_block do + basename = ::File.basename(new_resource.url) + remote_file ::File.join(Chef::Config[:file_cache_path], basename) do + not_if { new_resource.binary_path } + end + + artifact = libartifact_file "consul-webui-#{new_resource.version}" do + artifact_name 'consul-webui' + artifact_version new_resource.version + install_path new_resource.target_path + remote_url binary_url + remote_checksum new_resource.binary_checksum + end + end + end + + action(:remove) do + notifying_block do + artifact = libartifact_file "consul-webui-#{new_resource.version}" do + artifact_name 'consul-webui' + artifact_version new_resource.version + install_path new_resource.target_path + remote_url binary_url + remote_checksum new_resource.binary_checksum + action :delete + end + end + end + end + end +end diff --git a/libraries/helpers_installation_binary.rb b/libraries/helpers_installation_binary.rb new file mode 100644 index 00000000..c4d76685 --- /dev/null +++ b/libraries/helpers_installation_binary.rb @@ -0,0 +1,115 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# + +module ConsulCookbook + module Helpers + # @since 1.5 + module InstallationBinary # rubocop:disable Metrics/ModuleLength + extend self + + def fancy_filename + case node['kernel']['arch'] + when 'x86_64' then ['consul', version, node['os'], 'amd64'].join('_') + when 'x86' then ['consul', version, node['os'], '386'].join('_') + when 'arm' then ['consul', version, node['os'], 'arm'].join('_') + end + end + + def default_checksum + case [node['os'], node['kernel']['arch']].join('-') + when 'darwin-x86_64' + case version + when '0.5.0' then '24d9758c873e9124e0ce266f118078f87ba8d8363ab16c2e59a3cd197b77e964' + when '0.5.1' then '161f2a8803e31550bd92a00e95a3a517aa949714c19d3124c46e56cfdc97b088' + when '0.5.2' then '87be515d7dbab760a61a359626a734f738d46ece367f68422b7dec9197d9eeea' + when '0.6.0' then '29ddff01368458048731afa586cec5426c8033a914b43fc83d6442e0a522c114' + when '0.6.1' then '358654900772b3477497f4a5b5a841f2763dc3062bf29212606a97f5a7a675f3' + when '0.6.2' then '3089f77fcdb922894456ea6d0bc78a2fb60984d1d3687fa9d8f604b266c83446' + when '0.6.3' then '6dff4ffc61d66aacd627a176737b8725624718a9e68cc81460a3df9b241c7932' + end + when 'darwin-x86' + case version + when '0.6.0' then '95d57bfcc287bc344ec3ae8372cf735651af1158c5b1345e6f30cd9a9c811815' + when '0.6.1' then '41dfcc0aefe0a60bdde413eaa8a4a0c98e396d6b438494f1cf29b32d07759b8e' + when '0.6.2' then '973105816261c8001fcfa76c9fb707fa56325460476fb0daa97b9ece0602a918' + when '0.6.3' then '7fb30756504cd9559c9b23e5d0d8d73a847ee62ed85d39955b5906c2f59a5bc1' + end + when 'solaris-x86_64' + case version + when '0.6.2' then 'f5655f0b173e5d51c5b92327d1fc7f24ac0939897a1966da09146e4eb75af9d1' + when '0.6.3' then 'e6a286ff17a2345b8800732850eadb858b3dba9486355e1164a774ccec2f0e98' + end + when 'windows-x86_64' + case version + when '0.6.0' then '182beea0d8d346a9bfd70679621a5542aeeeea1f35be81fa3d3aeec2479bac3d' + when '0.6.1' then '2be6b0f0fdebff00aea202e9846131af570676f52e2936728cbf29ffbb02f57f' + when '0.6.2' then 'df3234fb7def7138b7cb8c73fe7c05942ec1e485925701a7b38fc7e2396a212f' + when '0.6.3' then '04cd1fdc9cd3a27ffc64e312e40142db7af0d240608f8080ec6d238294b20652' + end + when 'windows-x86' + case version + when '0.5.0' then '7fd760ee8a5c2756391cacc1e924ae602b16cdad838db068e564f798383ad714' + when '0.5.1' then 'bb9e1753cf793ad6f9db34bd6e18fb0fa5b0696a8a51a7f1c61484386dfe6682' + when '0.5.2' then '2e866812de16f1a6138a0fd1eebc76143f1314826e3b52597a55ac510ae94be6' + when '0.6.0' then '8379afd07668933c120880bba8228277e380abb14e07a6c45b94562ac19b37bd' + when '0.6.1' then '10197d1f7be0d0087414c9965008ddd88e9fcd9ac9d5bd02d72d65eda36f5834' + when '0.6.2' then 'f072d89c098dde143897e653d5adaf23125b58062344ef4be4029d635f959654' + when '0.6.3' then '55733a730c5055d0ed1dc2656b2b6a27b21c7c361a907919cfae90aab2dff870' + end + when 'linux-x86_64' + case version + when '0.5.0' then '161f2a8803e31550bd92a00e95a3a517aa949714c19d3124c46e56cfdc97b088' + when '0.5.1' then '967ad75865b950698833eaf26415ba48d8a22befb5d4e8c77630ad70f251b100' + when '0.5.2' then '171cf4074bfca3b1e46112105738985783f19c47f4408377241b868affa9d445' + when '0.6.0' then '307fa26ae32cb8732aed2b3320ed8daf02c28b50d952cbaae8faf67c79f78847' + when '0.6.1' then 'dbb3c348fdb7cdfc03e5617956b243c594a399733afee323e69ef664cdadb1ac' + when '0.6.2' then '7234eba9a6d1ce169ff8d7af91733e63d8fc82193d52d1b10979d8be5c959095' + when '0.6.3' then 'b0532c61fec4a4f6d130c893fd8954ec007a6ad93effbe283a39224ed237e250' + end + when 'linux-x86' + case version + when '0.5.0' then '4b6147c30596a30361d4753d409f8a1af9518f54f5ed473a4c4ac973738ac0fd' + when '0.5.1' then 'dad93a02c01de885daee191bcc5a05ca2bf106200da61db33694a658432d8399' + when '0.5.2' then '29306ce398109f954ceeea3af79878be4fb0d949f8af3a27c95ccef2101e8f60' + when '0.6.0' then 'f58f3f03a8b48d89bb8be94a6d1767393ad2a410c920b064066e01c7fa24f06c' + when '0.6.1' then '34b8d4a2a9ec85082b6e93c6785ba9c54663fec414062e45dd4386db46a533c4' + when '0.6.2' then '500ac8c75768b7f2d63521d2501ff8cc5fb7f9ddf6c550e9449364810c96f419' + when '0.6.3' then '2afb65383ab913344daaa9af827c1e8576c7cae16e93798048122929b6e4cc92' + end + when 'linux-arm' + case version + when '0.6.0' then '425e7332789deb446a486ac25f7143aba5f16453ac46ede39b71ab6a361d8726' + when '0.6.1' then '5b61e9ed10e02990aa8a2a0116c398c61608bc7f5051cb5a13750ffd47a54d51' + when '0.6.2' then 'b6b4f66f6dd8b1d4ebbd0339f4ed78c4853c7bd0d42fd15af70179b5bc65482e' + when '0.6.3' then 'c5fd5278be2757d2468bc7e263af15bc9a9e80fc5108fec658755804ea9bca56' + end + when 'freebsd-x86_64' + case version + when '0.6.0' then 'd7be5c95b971f48ccbd2c53c342dced9a3d0a5bc58f57b4f2e75672d96929923' + when '0.6.1' then '04688dfabedf6ded7f3d548110c7d9ffc8d6d3a091062593e421702bc42b465d' + when '0.6.2' then '1ccf96cb58c6fa927ee21c24d9be368ebe91559ed32626a89a715a3781659e3f' + when '0.6.3' then '8bdf2da41e6118af18af9aba0a127d4abb3453a20a9064e1bd1206f5c11ac2c8' + end + when 'freebsd-x86' + case version + when '0.6.0' then 'c5eb9f5c211612148e1e1cd101670fd08fd1abf9b2e541ac2936ab9637626249' + when '0.6.1' then '87d8c56c0c02e2fcde5192614dff9c491af93f7186fd55caae3fbe2c4d6ca80c' + when '0.6.2' then 'fc87f2ddd2090031e79136954d9e3f85db480d5ed9eba6ae627bf460e4c95e6e' + when '0.6.3' then '4a1aa8f570852eb238b7406172c097f5b32f41a3f01186111e576faa7506248c' + end + when 'freebsd-arm' + case version + when '0.6.0' then '92f29ad00f8f44d3be43b3b038a904c332757eb2a6848a7d6754583c2791e18b' + when '0.6.1' then '7b907fbd4377671de1be2dc0c19f955e1b37cd862c1af8251e9bf6d668b0d3a8' + when '0.6.2' then '30d8d09dd88cdd8d5256cea445fd0fed787d73cc6585e2eef7212161f29c8053' + when '0.6.3' then '5452d29f1cf0720c4ae0e0ec1cc5e44b0068a0340a6b61ab5ec245fa0f3447ad' + end + end + end + end + end +end diff --git a/libraries/helpers_installation_web_ui.rb b/libraries/helpers_installation_web_ui.rb new file mode 100644 index 00000000..b728e5fc --- /dev/null +++ b/libraries/helpers_installation_web_ui.rb @@ -0,0 +1,31 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# + +module ConsulCookbook + module Helpers + # @since 1.5 + module InstallationWebUi # rubocop:disable Metrics/ModuleLength + extend self + + def fancy_filename + ['consul', version, 'web_ui'].join('_') + end + + def default_checksum + case version + when '0.5.0' then '0081d08be9c0b1172939e92af5a7cf9ba4f90e54fae24a353299503b24bb8be9' + when '0.5.1' then 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1' + when '0.5.2' then 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1' + when '0.6.0' then '73c5e7ee50bb4a2efe56331d330e6d7dbf46335599c028344ccc4031c0c32eb0' + when '0.6.1' then 'afccdd540b166b778c7c0483becc5e282bbbb1ee52335bfe94bf757df8c55efc' + when '0.6.2' then 'f144377b8078df5a3f05918d167a52123089fc47b12fc978e6fb375ae93afc90' + when '0.6.3' then '93bbb300cacfe8de90fb3bd5ede7d37ae6ce014898edc520b9c96a676b2bbb72' + end + end + end + end +end From b2a932c92a85c512c36f6cbd17f71fda6fa38d34 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 22 Feb 2016 09:14:17 -0500 Subject: [PATCH 02/18] Update the metadata.rb and attributes. --- TODO.md | 1 - attributes/default.rb | 70 ------------------------------------------- metadata.rb | 2 ++ 3 files changed, 2 insertions(+), 71 deletions(-) diff --git a/TODO.md b/TODO.md index 7a11ccc1..9ddfec63 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,3 @@ # TODO - Fix the helpers and clean up the where it injects into DSL. -- Add custom resource (and multiple providers) for maintaining the Consul client. - Use the InSpec instead of ServerSpec. diff --git a/attributes/default.rb b/attributes/default.rb index 7704770f..05f8cc7c 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -50,73 +50,3 @@ 'AppRotateOnline' => 1, 'AppRotateBytes' => 20_000_000 } - -default['consul']['checksums'] = { - 'consul_0.5.0_darwin_amd64' => '24d9758c873e9124e0ce266f118078f87ba8d8363ab16c2e59a3cd197b77e964', - 'consul_0.5.0_linux_386' => '4b6147c30596a30361d4753d409f8a1af9518f54f5ed473a4c4ac973738ac0fd', - 'consul_0.5.0_linux_amd64' => '161f2a8803e31550bd92a00e95a3a517aa949714c19d3124c46e56cfdc97b088', - 'consul_0.5.0_windows_386' => '7fd760ee8a5c2756391cacc1e924ae602b16cdad838db068e564f798383ad714', - 'consul_0.5.0_web_ui' => '0081d08be9c0b1172939e92af5a7cf9ba4f90e54fae24a353299503b24bb8be9', - - 'consul_0.5.1_darwin_amd64' => '06fef2ffc5a8ad8883213227efae5d1e0aa4192ccb772ec6086103a7a08fadf8', - 'consul_0.5.1_linux_386' => 'dad93a02c01de885daee191bcc5a05ca2bf106200da61db33694a658432d8399', - 'consul_0.5.1_linux_amd64' => '967ad75865b950698833eaf26415ba48d8a22befb5d4e8c77630ad70f251b100', - 'consul_0.5.1_windows_386' => 'bb9e1753cf793ad6f9db34bd6e18fb0fa5b0696a8a51a7f1c61484386dfe6682', - 'consul_0.5.1_web_ui' => 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1', - - 'consul_0.5.2_darwin_amd64' => '87be515d7dbab760a61a359626a734f738d46ece367f68422b7dec9197d9eeea', - 'consul_0.5.2_linux_386' => '29306ce398109f954ceeea3af79878be4fb0d949f8af3a27c95ccef2101e8f60', - 'consul_0.5.2_linux_amd64' => '171cf4074bfca3b1e46112105738985783f19c47f4408377241b868affa9d445', - 'consul_0.5.2_windows_386' => '2e866812de16f1a6138a0fd1eebc76143f1314826e3b52597a55ac510ae94be6', - 'consul_0.5.2_web_ui' => 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1', - - 'consul_0.6.0_darwin_386' => '95d57bfcc287bc344ec3ae8372cf735651af1158c5b1345e6f30cd9a9c811815', - 'consul_0.6.0_darwin_amd64' => '29ddff01368458048731afa586cec5426c8033a914b43fc83d6442e0a522c114', - 'consul_0.6.0_freebsd_386' => 'c5eb9f5c211612148e1e1cd101670fd08fd1abf9b2e541ac2936ab9637626249', - 'consul_0.6.0_freebsd_amd64' => 'd7be5c95b971f48ccbd2c53c342dced9a3d0a5bc58f57b4f2e75672d96929923', - 'consul_0.6.0_freebsd_arm' => '92f29ad00f8f44d3be43b3b038a904c332757eb2a6848a7d6754583c2791e18b', - 'consul_0.6.0_linux_386' => 'f58f3f03a8b48d89bb8be94a6d1767393ad2a410c920b064066e01c7fa24f06c', - 'consul_0.6.0_linux_amd64' => '307fa26ae32cb8732aed2b3320ed8daf02c28b50d952cbaae8faf67c79f78847', - 'consul_0.6.0_linux_arm' => '425e7332789deb446a486ac25f7143aba5f16453ac46ede39b71ab6a361d8726', - 'consul_0.6.0_windows_386' => '8379afd07668933c120880bba8228277e380abb14e07a6c45b94562ac19b37bd', - 'consul_0.6.0_windows_amd64' => '182beea0d8d346a9bfd70679621a5542aeeeea1f35be81fa3d3aeec2479bac3d', - 'consul_0.6.0_web_ui' => '73c5e7ee50bb4a2efe56331d330e6d7dbf46335599c028344ccc4031c0c32eb0', - - 'consul_0.6.1_darwin_386' => '41dfcc0aefe0a60bdde413eaa8a4a0c98e396d6b438494f1cf29b32d07759b8e', - 'consul_0.6.1_darwin_amd64' => '358654900772b3477497f4a5b5a841f2763dc3062bf29212606a97f5a7a675f3', - 'consul_0.6.1_freebsd_386' => '87d8c56c0c02e2fcde5192614dff9c491af93f7186fd55caae3fbe2c4d6ca80c', - 'consul_0.6.1_freebsd_amd64' => '04688dfabedf6ded7f3d548110c7d9ffc8d6d3a091062593e421702bc42b465d', - 'consul_0.6.1_freebsd_arm' => '7b907fbd4377671de1be2dc0c19f955e1b37cd862c1af8251e9bf6d668b0d3a8', - 'consul_0.6.1_linux_386' => '34b8d4a2a9ec85082b6e93c6785ba9c54663fec414062e45dd4386db46a533c4', - 'consul_0.6.1_linux_amd64' => 'dbb3c348fdb7cdfc03e5617956b243c594a399733afee323e69ef664cdadb1ac', - 'consul_0.6.1_linux_arm' => '5b61e9ed10e02990aa8a2a0116c398c61608bc7f5051cb5a13750ffd47a54d51', - 'consul_0.6.1_windows_386' => '10197d1f7be0d0087414c9965008ddd88e9fcd9ac9d5bd02d72d65eda36f5834', - 'consul_0.6.1_windows_amd64' => '2be6b0f0fdebff00aea202e9846131af570676f52e2936728cbf29ffbb02f57f', - 'consul_0.6.1_web_ui' => 'afccdd540b166b778c7c0483becc5e282bbbb1ee52335bfe94bf757df8c55efc', - - 'consul_0.6.2_darwin_386' => '973105816261c8001fcfa76c9fb707fa56325460476fb0daa97b9ece0602a918', - 'consul_0.6.2_darwin_amd64' => '3089f77fcdb922894456ea6d0bc78a2fb60984d1d3687fa9d8f604b266c83446', - 'consul_0.6.2_freebsd_386' => 'fc87f2ddd2090031e79136954d9e3f85db480d5ed9eba6ae627bf460e4c95e6e', - 'consul_0.6.2_freebsd_amd64' => '1ccf96cb58c6fa927ee21c24d9be368ebe91559ed32626a89a715a3781659e3f', - 'consul_0.6.2_freebsd_arm' => '30d8d09dd88cdd8d5256cea445fd0fed787d73cc6585e2eef7212161f29c8053', - 'consul_0.6.2_linux_386' => '500ac8c75768b7f2d63521d2501ff8cc5fb7f9ddf6c550e9449364810c96f419', - 'consul_0.6.2_linux_amd64' => '7234eba9a6d1ce169ff8d7af91733e63d8fc82193d52d1b10979d8be5c959095', - 'consul_0.6.2_linux_arm' => 'b6b4f66f6dd8b1d4ebbd0339f4ed78c4853c7bd0d42fd15af70179b5bc65482e', - 'consul_0.6.2_solaris_amd64' => 'f5655f0b173e5d51c5b92327d1fc7f24ac0939897a1966da09146e4eb75af9d1', - 'consul_0.6.2_windows_386' => 'f072d89c098dde143897e653d5adaf23125b58062344ef4be4029d635f959654', - 'consul_0.6.2_windows_amd64' => 'df3234fb7def7138b7cb8c73fe7c05942ec1e485925701a7b38fc7e2396a212f', - 'consul_0.6.2_web_ui' => 'f144377b8078df5a3f05918d167a52123089fc47b12fc978e6fb375ae93afc90', - - 'consul_0.6.3_darwin_386' => '7fb30756504cd9559c9b23e5d0d8d73a847ee62ed85d39955b5906c2f59a5bc1', - 'consul_0.6.3_darwin_amd64' => '6dff4ffc61d66aacd627a176737b8725624718a9e68cc81460a3df9b241c7932', - 'consul_0.6.3_freebsd_386' => '4a1aa8f570852eb238b7406172c097f5b32f41a3f01186111e576faa7506248c', - 'consul_0.6.3_freebsd_amd64' => '8bdf2da41e6118af18af9aba0a127d4abb3453a20a9064e1bd1206f5c11ac2c8', - 'consul_0.6.3_freebsd_arm' => '5452d29f1cf0720c4ae0e0ec1cc5e44b0068a0340a6b61ab5ec245fa0f3447ad', - 'consul_0.6.3_linux_386' => '2afb65383ab913344daaa9af827c1e8576c7cae16e93798048122929b6e4cc92', - 'consul_0.6.3_linux_amd64' => 'b0532c61fec4a4f6d130c893fd8954ec007a6ad93effbe283a39224ed237e250', - 'consul_0.6.3_linux_arm' => 'c5fd5278be2757d2468bc7e263af15bc9a9e80fc5108fec658755804ea9bca56', - 'consul_0.6.3_solaris_amd64' => 'e6a286ff17a2345b8800732850eadb858b3dba9486355e1164a774ccec2f0e98', - 'consul_0.6.3_windows_386' => '55733a730c5055d0ed1dc2656b2b6a27b21c7c361a907919cfae90aab2dff870', - 'consul_0.6.3_windows_amd64' => '04cd1fdc9cd3a27ffc64e312e40142db7af0d240608f8080ec6d238294b20652', - 'consul_0.6.3_web_ui' => '93bbb300cacfe8de90fb3bd5ede7d37ae6ce014898edc520b9c96a676b2bbb72' -} diff --git a/metadata.rb b/metadata.rb index 08eade9d..6798cedd 100644 --- a/metadata.rb +++ b/metadata.rb @@ -11,6 +11,8 @@ supports 'centos', '>= 6.4' supports 'redhat', '>= 6.4' supports 'ubuntu', '>= 12.04' +supports 'solaris2' +supports 'freebsd' supports 'arch' supports 'windows' From 8a2144f7a1402fb20190f952e9a05217fa58b223 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 22 Feb 2016 09:26:16 -0500 Subject: [PATCH 03/18] Add a recipe which installs the webui. --- attributes/default.rb | 4 +-- libraries/consul_ui.rb | 77 ------------------------------------------ libraries/helpers.rb | 7 ---- metadata.rb | 4 ++- recipes/web_ui.rb | 9 +++++ 5 files changed, 13 insertions(+), 88 deletions(-) delete mode 100644 libraries/consul_ui.rb create mode 100644 recipes/web_ui.rb diff --git a/attributes/default.rb b/attributes/default.rb index 05f8cc7c..4968ac19 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -5,10 +5,10 @@ # Copyright 2014-2016, Bloomberg Finance L.P. # -# Only used on Linux default['consul']['service_name'] = 'consul' default['consul']['service_user'] = 'consul' default['consul']['service_group'] = 'consul' +default['consul']['install_method'] = 'binary' default['consul']['config']['bag_name'] = 'secrets' default['consul']['config']['bag_item'] = 'consul' @@ -33,8 +33,6 @@ default['consul']['service']['config_dir'] = join_path config_prefix_path, 'conf.d' -default['consul']['service']['install_path'] = windows? ? config_prefix_path : '/srv' -default['consul']['service']['install_method'] = 'binary' default['consul']['service']['binary_url'] = "https://releases.hashicorp.com/consul/%{version}/%{filename}.zip" # rubocop:disable Style/StringLiterals default['consul']['service']['source_url'] = 'https://github.com/hashicorp/consul' diff --git a/libraries/consul_ui.rb b/libraries/consul_ui.rb deleted file mode 100644 index 54e02777..00000000 --- a/libraries/consul_ui.rb +++ /dev/null @@ -1,77 +0,0 @@ -# -# Cookbook: consul -# License: Apache 2.0 -# -# Copyright 2014-2016, Bloomberg Finance L.P. -# -require 'poise' -require_relative 'helpers' - -module ConsulCookbook - module Resource - # Resource for managing the Consul web UI installation. - class ConsulUI < Chef::Resource - include Poise - include ConsulCookbook::Helpers - provides(:consul_ui) - default_action(:install) - - # @!attribute version - # @return [String] - attribute(:version, kind_of: String, required: true) - - # @!attribute install_path - # @return [String] - attribute(:install_path, kind_of: String, default: '/srv') - - # @!attribute owner - # @return [String] - attribute(:owner, kind_of: String, default: 'consul') - - # @!attribute group - # @return [String] - attribute(:group, kind_of: String, default: 'consul') - - # @!attribute binary_url - # @return [String] - attribute(:binary_url, kind_of: String, default: 'https://releases.hashicorp.com/consul/%{version}/%{filename}.zip') - - # @!attribute source_url - # @return [String] - attribute(:source_url, kind_of: String) - end - end - - module Provider - # Provider for managing the Consul web UI installation. - class ConsulUI < Chef::Provider - include Poise - provides(:consul_ui) - - def action_install - notifying_block do - libartifact_file "#{new_resource.name}-#{new_resource.version}" do - artifact_name new_resource.name - artifact_version new_resource.version - owner new_resource.owner - group new_resource.group - install_path new_resource.install_path - remote_url new_resource.binary_url % { version: new_resource.version, filename: new_resource.binary_filename('web_ui') } - remote_checksum new_resource.binary_checksum 'web_ui' - end - end - end - - def action_uninstall - notifying_block do - libartifact_file "#{new_resource.name}-#{new_resource.version}" do - action :delete - artifact_name new_resource.name - artifact_version new_resource.version - install_path new_resource.install_path - end - end - end - end - end -end diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 2b4a44eb..5de5151e 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -75,13 +75,6 @@ def nssm_exe "#{node['nssm']['install_location']}\\nssm.exe" end - def default_environment - { - 'GOMAXPROCS' => [node['cpu']['total'], 2].max.to_s, - 'PATH' => '/usr/local/bin:/usr/bin:/bin' - } - end - def nssm_params %w{Application AppParameters diff --git a/metadata.rb b/metadata.rb index 6798cedd..64eb1e4e 100644 --- a/metadata.rb +++ b/metadata.rb @@ -6,7 +6,9 @@ long_description 'Application cookbook which installs and configures Consul.' version '1.5.0' -recipe 'consul::default', 'Installs, configures and starts the Consul service.' +recipe 'consul::default', 'Installs and configures the Consul service.' +recipe 'consul::web_ui', 'Installs and configures the Consul Web UI.' +recipe 'consul::client_gem', 'Installs the Consul Ruby client as a gem.' supports 'centos', '>= 6.4' supports 'redhat', '>= 6.4' diff --git a/recipes/web_ui.rb b/recipes/web_ui.rb new file mode 100644 index 00000000..9c45e3b3 --- /dev/null +++ b/recipes/web_ui.rb @@ -0,0 +1,9 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# + +consul_installation_web_ui 'install consul-webui from binary' do +end From ec847749c6e7e39408051b6d509d4224a0c926fd Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 22 Feb 2016 09:26:36 -0500 Subject: [PATCH 04/18] Modify the default recipe to install using resources. --- libraries/consul_service.rb | 79 +++++-------------------------------- recipes/default.rb | 12 ++++++ 2 files changed, 22 insertions(+), 69 deletions(-) diff --git a/libraries/consul_service.rb b/libraries/consul_service.rb index 963ecce1..e48f471d 100644 --- a/libraries/consul_service.rb +++ b/libraries/consul_service.rb @@ -9,8 +9,9 @@ module ConsulCookbook module Resource - # A resource for managing the Consul service. - # @since 1.0.0 + # A `consul_service` resource for use with `poise_service`. This + # resource manages the Consul service. + # @since 1.0 class ConsulService < Chef::Resource include Poise provides(:consul_service) @@ -20,54 +21,43 @@ class ConsulService < Chef::Resource # @!attribute version # @return [String] attribute(:version, kind_of: String, required: true) - - # @!attribute install_method - # @return [Symbol] - attribute(:install_method, default: 'binary', equal_to: %w{source binary package}) - - # @!attribute install_path - # @return [String] - attribute(:install_path, kind_of: String, default: lazy { node['consul']['service']['install_path'] }) - # @!attribute config_file # @return [String] attribute(:config_file, kind_of: String, default: lazy { node['consul']['config']['path'] }) - # @!attribute user # @return [String] attribute(:user, kind_of: String, default: 'consul') - # @!attribute group # @return [String] attribute(:group, kind_of: String, default: 'consul') - # @!attribute environment # @return [String] attribute(:environment, kind_of: Hash, default: lazy { default_environment }) - # @!attribute package_name # @return [String] attribute(:package_name, kind_of: String, default: 'consul') - # @!attribute binary_url # @return [String] attribute(:binary_url, kind_of: String) - # @!attribute source_url # @return [String] attribute(:source_url, kind_of: String) - # @!attribute data_dir # @return [String] attribute(:data_dir, kind_of: String, default: lazy { node['consul']['config']['data_dir'] }) - # @!attribute config_dir # @return [String] attribute(:config_dir, kind_of: String, default: lazy { node['consul']['config']['config_dir'] }) - # @!attribute nssm_params # @return [String] attribute(:nssm_params, kind_of: Hash, default: lazy { node['consul']['service']['nssm_params'] }) + + def default_environment + { + 'GOMAXPROCS' => [node['cpu']['total'], 2].max.to_s, + 'PATH' => '/usr/local/bin:/usr/bin:/bin' + } + end end end @@ -82,55 +72,6 @@ class ConsulService < Chef::Provider def action_enable notifying_block do - case new_resource.install_method - when 'package' - package new_resource.package_name do - version new_resource.version unless new_resource.version.nil? - end - when 'binary' - artifact = libartifact_file "consul-#{new_resource.version}" do - artifact_name 'consul' - artifact_version new_resource.version - install_path new_resource.install_path - remote_url new_resource.binary_url % { version: new_resource.version, filename: new_resource.binary_filename('binary') } - remote_checksum new_resource.binary_checksum 'binary' - end - - link '/usr/local/bin/consul' do - to join_path(artifact.current_path, 'consul') - end - when 'source' - include_recipe 'golang::default' - - source_dir = directory join_path(new_resource.install_path, 'consul', 'src') do - recursive true - owner new_resource.user - group new_resource.group - mode '0755' - end - - git join_path(source_dir.path, "consul-#{new_resource.version}") do - repository new_resource.source_url - reference new_resource.version - action :checkout - end - - golang_package 'github.com/hashicorp/consul' do - action :install - end - - directory join_path(new_resource.install_path, 'bin') do - recursive true - owner new_resource.user - group new_resource.group - mode '0755' - end - - link join_path(new_resource.install_path, 'bin', 'consul') do - to join_path(source_dir.path, "consul-#{new_resource.version}", 'consul') - end - end - [new_resource.data_dir, new_resource.config_dir].each do |dirname| directory dirname do recursive true diff --git a/recipes/default.rb b/recipes/default.rb index 827d7f0d..76760bfd 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -47,6 +47,18 @@ node['consul']['config'].each_pair { |k, v| r.send(k, v) } end +case node['consul']['install_method'] +when 'binary' + consul_installation_binary 'install consul from binary' do + end +when 'package' + consul_installation_package 'install consul from package' do + end +when 'git' + consul_installation_git 'install consul from git' do + end +end + consul_service node['consul']['service_name'] do |r| unless platform?('windows') user node['consul']['service_user'] From 262903c9dca1fa05c19b85d80541209ce0a1a3bb Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 22 Feb 2016 09:29:24 -0500 Subject: [PATCH 05/18] Add a default (false) value for firewall. --- attributes/firewall.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 attributes/firewall.rb diff --git a/attributes/firewall.rb b/attributes/firewall.rb new file mode 100644 index 00000000..02977ced --- /dev/null +++ b/attributes/firewall.rb @@ -0,0 +1,8 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# + +default['firewall']['allow_consul'] = false From 656d8e2dec9ee4c2dcec75beb6fd57ff8d3b7fb9 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 22 Feb 2016 09:29:39 -0500 Subject: [PATCH 06/18] Add chef-sugar recipe for easy to use helpers. --- metadata.rb | 1 + recipes/default.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/metadata.rb b/metadata.rb index 64eb1e4e..7dcfd8de 100644 --- a/metadata.rb +++ b/metadata.rb @@ -18,6 +18,7 @@ supports 'arch' supports 'windows' +depends 'chef-sugar' depends 'chef-vault', '~> 1.3' depends 'nssm' depends 'golang' diff --git a/recipes/default.rb b/recipes/default.rb index 76760bfd..47bd3901 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -4,7 +4,9 @@ # # Copyright 2014-2016, Bloomberg Finance L.P. # -if platform_family?('rhel') +include_recipe 'chef-sugar::default' + +if rhel? include_recipe 'yum-epel::default' if node['platform_version'].to_i == 5 end @@ -31,7 +33,7 @@ end end -unless platform?('windows') +unless windows? group node['consul']['service_group'] user node['consul']['service_user'] do shell '/bin/bash' @@ -40,7 +42,7 @@ end config = consul_config node['consul']['service_name'] do |r| - unless platform?('windows') + unless windows? owner node['consul']['service_user'] group node['consul']['service_group'] end @@ -60,7 +62,7 @@ end consul_service node['consul']['service_name'] do |r| - unless platform?('windows') + unless windows? user node['consul']['service_user'] group node['consul']['service_group'] end From e3d8be22aa4f3e8892a4603ad83600fd009be4f0 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 22 Feb 2016 09:31:29 -0500 Subject: [PATCH 07/18] Update the version of cookbook to 2.0. --- libraries/consul_installation_binary.rb | 2 +- libraries/consul_installation_git.rb | 2 +- libraries/consul_installation_package.rb | 2 +- libraries/consul_installation_web_ui.rb | 2 +- libraries/helpers_installation_binary.rb | 2 +- libraries/helpers_installation_web_ui.rb | 2 +- metadata.rb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/consul_installation_binary.rb b/libraries/consul_installation_binary.rb index 4564d71a..789b74c2 100644 --- a/libraries/consul_installation_binary.rb +++ b/libraries/consul_installation_binary.rb @@ -14,7 +14,7 @@ module Resource # @action remove # @provides consul_installation # @provides consul_installation_binary - # @since 1.5 + # @since 2.0 class ConsulInstallationBinary < Chef::Resource include Poise(fused: true) include Helpers::InstallationBinary diff --git a/libraries/consul_installation_git.rb b/libraries/consul_installation_git.rb index b6c97421..6a61fc49 100644 --- a/libraries/consul_installation_git.rb +++ b/libraries/consul_installation_git.rb @@ -14,7 +14,7 @@ module Resource # @action remove # @provides consul_installation # @provides consul_installation_git - # @since 1.5 + # @since 2.0 class ConsulInstallationGit < Chef::Resource include Poise(fused: true) provides(:consul_installation_git) diff --git a/libraries/consul_installation_package.rb b/libraries/consul_installation_package.rb index 3ad65d06..b7df6f3b 100644 --- a/libraries/consul_installation_package.rb +++ b/libraries/consul_installation_package.rb @@ -12,7 +12,7 @@ module Resource # @action remove # @provides consul_installation # @provides consul_installation_package - # @since 1.5 + # @since 2.0 class ConsulInstallationPackage < Chef::Resource include Poise(fused: true) provides(:consul_installation_package) diff --git a/libraries/consul_installation_web_ui.rb b/libraries/consul_installation_web_ui.rb index 54f8a07d..e200541e 100644 --- a/libraries/consul_installation_web_ui.rb +++ b/libraries/consul_installation_web_ui.rb @@ -13,7 +13,7 @@ module Resource # @action create # @action remove # @provides consul_installation_web_ui - # @since 1.5 + # @since 2.0 class ConsulInstallationWebUi < Chef::Resource include Poise(fused: true) include Helpers::InstallationWebUi diff --git a/libraries/helpers_installation_binary.rb b/libraries/helpers_installation_binary.rb index c4d76685..2b6bfd65 100644 --- a/libraries/helpers_installation_binary.rb +++ b/libraries/helpers_installation_binary.rb @@ -7,7 +7,7 @@ module ConsulCookbook module Helpers - # @since 1.5 + # @since 2.0 module InstallationBinary # rubocop:disable Metrics/ModuleLength extend self diff --git a/libraries/helpers_installation_web_ui.rb b/libraries/helpers_installation_web_ui.rb index b728e5fc..6cf866f4 100644 --- a/libraries/helpers_installation_web_ui.rb +++ b/libraries/helpers_installation_web_ui.rb @@ -7,7 +7,7 @@ module ConsulCookbook module Helpers - # @since 1.5 + # @since 2.0 module InstallationWebUi # rubocop:disable Metrics/ModuleLength extend self diff --git a/metadata.rb b/metadata.rb index 7dcfd8de..35f59b41 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Application cookbook which installs and configures Consul.' long_description 'Application cookbook which installs and configures Consul.' -version '1.5.0' +version '2.0.0' recipe 'consul::default', 'Installs and configures the Consul service.' recipe 'consul::web_ui', 'Installs and configures the Consul Web UI.' From 04fce9a074d8646c3489f9c0548be1d76d94533c Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 22 Feb 2016 09:38:27 -0500 Subject: [PATCH 08/18] Fix some notification issues with hup service. --- recipes/default.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/recipes/default.rb b/recipes/default.rb index 47bd3901..9c3d9b5b 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -41,27 +41,32 @@ end end -config = consul_config node['consul']['service_name'] do |r| +service_name = node['consul']['service_name'] +config = consul_config service_name do |r| unless windows? owner node['consul']['service_user'] group node['consul']['service_group'] end node['consul']['config'].each_pair { |k, v| r.send(k, v) } + notifies :restart, "consul_service[#{service_name}]", :delayed end case node['consul']['install_method'] when 'binary' consul_installation_binary 'install consul from binary' do + notifies :restart, "consul_service[#{service_name}]", :delayed end when 'package' consul_installation_package 'install consul from package' do + notifies :restart, "consul_service[#{service_name}]", :delayed end when 'git' consul_installation_git 'install consul from git' do + notifies :restart, "consul_service[#{service_name}]", :delayed end end -consul_service node['consul']['service_name'] do |r| +consul_service service_name do |r| unless windows? user node['consul']['service_user'] group node['consul']['service_group'] @@ -69,5 +74,4 @@ version node['consul']['version'] config_file config.path node['consul']['service'].each_pair { |k, v| r.send(k, v) } - subscribes :restart, "consul_config[#{config.name}]", :delayed end From bba807a27692a081c1d236b6e21b7fd7d006a402 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Sat, 5 Mar 2016 02:06:47 -0500 Subject: [PATCH 09/18] Update the custom resource for install types. --- libraries/consul_installation.rb | 31 ++++ libraries/consul_installation_binary.rb | 200 ++++++++++++++++++----- libraries/consul_installation_git.rb | 73 +++++---- libraries/consul_installation_package.rb | 59 ++++--- libraries/consul_installation_web_ui.rb | 66 -------- libraries/consul_service.rb | 48 ++---- libraries/helpers_installation_binary.rb | 115 ------------- libraries/helpers_installation_web_ui.rb | 31 ---- recipes/default.rb | 16 +- recipes/web_ui.rb | 9 - 10 files changed, 284 insertions(+), 364 deletions(-) create mode 100644 libraries/consul_installation.rb delete mode 100644 libraries/consul_installation_web_ui.rb delete mode 100644 libraries/helpers_installation_binary.rb delete mode 100644 libraries/helpers_installation_web_ui.rb delete mode 100644 recipes/web_ui.rb diff --git a/libraries/consul_installation.rb b/libraries/consul_installation.rb new file mode 100644 index 00000000..dc5fb3ff --- /dev/null +++ b/libraries/consul_installation.rb @@ -0,0 +1,31 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# +require 'poise' + +module ConsulCookbook + module Resource + # A `consul_installation` resource which manages the Consul installation. + # @action create + # @action remove + # @since 2.0 + class ConsulInstallation < Chef::Resource + include Poise(inversion: true) + provides(:consul_installation) + actions(:create, :remove) + default_action(:create) + + # @!attribute version + # The version of Consul to install. + # @return [String] + attribute(:version, kind_of: String, name_attribute: true) + + def consul_binary + @consul_binary ||= provider_for_action(:consul_binary).consul_binary + end + end + end +end diff --git a/libraries/consul_installation_binary.rb b/libraries/consul_installation_binary.rb index 789b74c2..de59546e 100644 --- a/libraries/consul_installation_binary.rb +++ b/libraries/consul_installation_binary.rb @@ -7,68 +7,182 @@ require 'poise' module ConsulCookbook - module Resource - # A `consul_installation` resource which manages the Consul installation - # from an binary. + module Provider + # A `consul_installation` provider which manages Consul binary + # installation from remote source URL. # @action create # @action remove # @provides consul_installation - # @provides consul_installation_binary + # @example + # consul_installation '0.5.0' # @since 2.0 - class ConsulInstallationBinary < Chef::Resource - include Poise(fused: true) - include Helpers::InstallationBinary - provides(:consul_installation) - provides(:consul_installation_binary) + class ConsulInstallationBinary < Chef::Provider + include Poise(inversion: :consul_installation) + provides(:binary) + inversion_attribute 'consul' - # @!attribute version - # @return [String] - attribute(:version, kind_of: String, default: lazy { default_version }) - # @!attribute binary_url - # @return [String] - attribute(:binary_url, kind_of: String, required: true) - # @!attribute binary_path - # @return [String, NilClass] - attribute(:binary_path, kind_of: [String, NilClass], default: nil) - # @!attribute binary_checksum - # @return [String] - attribute(:binary_checksum, kind_of: String, default: lazy { default_checksum }) + # @api private + def self.provides_auto?(_node, _resource) + true + end + + # Set the default inversion options. + # @return [Hash] + # @api private + def self.default_inversion_options(node, resource) + archive_basename = binary_basename(node, resource) + super.merge( + version: new_resource.version, + archive_url: default_archive_url % { version: new_resource.version, basename: archive_basename }, + archive_basename: archive_basename, + archive_checksum: binary_checksum(node, resource), + extract_to: '/opt/consul' + ) + end + + def action_create + archive_url = options[:archive_url] % { + version: options[:version], + basename: options[:archive_basename] + } - action(:create) do notifying_block do - basename = ::File.basename(new_resource.url) - remote_file ::File.join(Chef::Config[:file_cache_path], basename) do - not_if { new_resource.binary_path } + include_recipe 'libarchive::default' + + archive = remote_file options[:archive_basename] do + path ::File.join(Chef::Config[:file_cache_path], name) + source archive_url + checksum options[:archive_checksum] end - artifact = libartifact_file "consul-#{new_resource.version}" do - artifact_name 'consul' - artifact_version new_resource.version - install_path new_resource.target_path - remote_url binary_url - remote_checksum new_resource.binary_checksum + directory ::File.join(options[:extract_to], new_resource.version) do + recursive true end - link '/usr/local/bin/consul' do - to ::File.join(artifact.current_path, 'consul') + libarchive_file options[:archive_basename] do + path archive.path + mode options[:extract_mode] + owner options[:extract_owner] + group options[:extract_group] + extract_to ::File.join(options[:extract_to], new_resource.version) + extract_options options[:extract_options] end end end - action(:remove) do + def action_remove notifying_block do - artifact = libartifact_file "consul-#{new_resource.version}" do - artifact_name 'consul' - artifact_version new_resource.version - install_path new_resource.target_path - remote_url binary_url - remote_checksum new_resource.binary_checksum + directory ::File.join(options[:extract_to], new_resource.version) do + recursive true action :delete end + end + end - link '/usr/local/bin/consul' do - to ::File.join(binary.current_path, 'consul') - action :delete + def consul_binary + ::File.join(options[:extract_to], new_resource.version, 'consul') + end + + def self.default_archive_url + "https://releases.hashicorp.com/consul/%{version}/%{basename}" # rubocop:disable Style/StringLiterals + end + + def self.binary_basename(node, resource) + case node['kernel']['machine'] + when 'x86_64' then ['consul', resource.version, node['os'], 'amd64'].join('_') + when 'i386' then ['consul', resource.version, node['os'], '386'].join('_') + else ['consul', resource.version, node['os'], node['kernel']['machine']].join('_') + end.concat('.zip') + end + + def self.binary_checksum(node, resource) + case [node['os'], node['kernel']['machine']].join('-') + when 'darwin-x86_64' + case resource.version + when '0.5.0' then '24d9758c873e9124e0ce266f118078f87ba8d8363ab16c2e59a3cd197b77e964' + when '0.5.1' then '161f2a8803e31550bd92a00e95a3a517aa949714c19d3124c46e56cfdc97b088' + when '0.5.2' then '87be515d7dbab760a61a359626a734f738d46ece367f68422b7dec9197d9eeea' + when '0.6.0' then '29ddff01368458048731afa586cec5426c8033a914b43fc83d6442e0a522c114' + when '0.6.1' then '358654900772b3477497f4a5b5a841f2763dc3062bf29212606a97f5a7a675f3' + when '0.6.2' then '3089f77fcdb922894456ea6d0bc78a2fb60984d1d3687fa9d8f604b266c83446' + when '0.6.3' then '6dff4ffc61d66aacd627a176737b8725624718a9e68cc81460a3df9b241c7932' + end + when 'darwin-i386' + case resource.version + when '0.6.0' then '95d57bfcc287bc344ec3ae8372cf735651af1158c5b1345e6f30cd9a9c811815' + when '0.6.1' then '41dfcc0aefe0a60bdde413eaa8a4a0c98e396d6b438494f1cf29b32d07759b8e' + when '0.6.2' then '973105816261c8001fcfa76c9fb707fa56325460476fb0daa97b9ece0602a918' + when '0.6.3' then '7fb30756504cd9559c9b23e5d0d8d73a847ee62ed85d39955b5906c2f59a5bc1' + end + when 'solaris-x86_64' + case resource.version + when '0.6.2' then 'f5655f0b173e5d51c5b92327d1fc7f24ac0939897a1966da09146e4eb75af9d1' + when '0.6.3' then 'e6a286ff17a2345b8800732850eadb858b3dba9486355e1164a774ccec2f0e98' + end + when 'windows-x86_64' + case resource.version + when '0.6.0' then '182beea0d8d346a9bfd70679621a5542aeeeea1f35be81fa3d3aeec2479bac3d' + when '0.6.1' then '2be6b0f0fdebff00aea202e9846131af570676f52e2936728cbf29ffbb02f57f' + when '0.6.2' then 'df3234fb7def7138b7cb8c73fe7c05942ec1e485925701a7b38fc7e2396a212f' + when '0.6.3' then '04cd1fdc9cd3a27ffc64e312e40142db7af0d240608f8080ec6d238294b20652' + end + when 'windows-i386' + case resource.version + when '0.5.0' then '7fd760ee8a5c2756391cacc1e924ae602b16cdad838db068e564f798383ad714' + when '0.5.1' then 'bb9e1753cf793ad6f9db34bd6e18fb0fa5b0696a8a51a7f1c61484386dfe6682' + when '0.5.2' then '2e866812de16f1a6138a0fd1eebc76143f1314826e3b52597a55ac510ae94be6' + when '0.6.0' then '8379afd07668933c120880bba8228277e380abb14e07a6c45b94562ac19b37bd' + when '0.6.1' then '10197d1f7be0d0087414c9965008ddd88e9fcd9ac9d5bd02d72d65eda36f5834' + when '0.6.2' then 'f072d89c098dde143897e653d5adaf23125b58062344ef4be4029d635f959654' + when '0.6.3' then '55733a730c5055d0ed1dc2656b2b6a27b21c7c361a907919cfae90aab2dff870' + end + when 'linux-x86_64' + case resource.version + when '0.5.0' then '161f2a8803e31550bd92a00e95a3a517aa949714c19d3124c46e56cfdc97b088' + when '0.5.1' then '967ad75865b950698833eaf26415ba48d8a22befb5d4e8c77630ad70f251b100' + when '0.5.2' then '171cf4074bfca3b1e46112105738985783f19c47f4408377241b868affa9d445' + when '0.6.0' then '307fa26ae32cb8732aed2b3320ed8daf02c28b50d952cbaae8faf67c79f78847' + when '0.6.1' then 'dbb3c348fdb7cdfc03e5617956b243c594a399733afee323e69ef664cdadb1ac' + when '0.6.2' then '7234eba9a6d1ce169ff8d7af91733e63d8fc82193d52d1b10979d8be5c959095' + when '0.6.3' then 'b0532c61fec4a4f6d130c893fd8954ec007a6ad93effbe283a39224ed237e250' + end + when 'linux-i386' + case resource.version + when '0.5.0' then '4b6147c30596a30361d4753d409f8a1af9518f54f5ed473a4c4ac973738ac0fd' + when '0.5.1' then 'dad93a02c01de885daee191bcc5a05ca2bf106200da61db33694a658432d8399' + when '0.5.2' then '29306ce398109f954ceeea3af79878be4fb0d949f8af3a27c95ccef2101e8f60' + when '0.6.0' then 'f58f3f03a8b48d89bb8be94a6d1767393ad2a410c920b064066e01c7fa24f06c' + when '0.6.1' then '34b8d4a2a9ec85082b6e93c6785ba9c54663fec414062e45dd4386db46a533c4' + when '0.6.2' then '500ac8c75768b7f2d63521d2501ff8cc5fb7f9ddf6c550e9449364810c96f419' + when '0.6.3' then '2afb65383ab913344daaa9af827c1e8576c7cae16e93798048122929b6e4cc92' + end + when 'linux-arm' + case resource.version + when '0.6.0' then '425e7332789deb446a486ac25f7143aba5f16453ac46ede39b71ab6a361d8726' + when '0.6.1' then '5b61e9ed10e02990aa8a2a0116c398c61608bc7f5051cb5a13750ffd47a54d51' + when '0.6.2' then 'b6b4f66f6dd8b1d4ebbd0339f4ed78c4853c7bd0d42fd15af70179b5bc65482e' + when '0.6.3' then 'c5fd5278be2757d2468bc7e263af15bc9a9e80fc5108fec658755804ea9bca56' + end + when 'freebsd-x86_64' + case resource.version + when '0.6.0' then 'd7be5c95b971f48ccbd2c53c342dced9a3d0a5bc58f57b4f2e75672d96929923' + when '0.6.1' then '04688dfabedf6ded7f3d548110c7d9ffc8d6d3a091062593e421702bc42b465d' + when '0.6.2' then '1ccf96cb58c6fa927ee21c24d9be368ebe91559ed32626a89a715a3781659e3f' + when '0.6.3' then '8bdf2da41e6118af18af9aba0a127d4abb3453a20a9064e1bd1206f5c11ac2c8' + end + when 'freebsd-i386' + case resource.version + when '0.6.0' then 'c5eb9f5c211612148e1e1cd101670fd08fd1abf9b2e541ac2936ab9637626249' + when '0.6.1' then '87d8c56c0c02e2fcde5192614dff9c491af93f7186fd55caae3fbe2c4d6ca80c' + when '0.6.2' then 'fc87f2ddd2090031e79136954d9e3f85db480d5ed9eba6ae627bf460e4c95e6e' + when '0.6.3' then '4a1aa8f570852eb238b7406172c097f5b32f41a3f01186111e576faa7506248c' + end + when 'freebsd-arm' + case resource.version + when '0.6.0' then '92f29ad00f8f44d3be43b3b038a904c332757eb2a6848a7d6754583c2791e18b' + when '0.6.1' then '7b907fbd4377671de1be2dc0c19f955e1b37cd862c1af8251e9bf6d668b0d3a8' + when '0.6.2' then '30d8d09dd88cdd8d5256cea445fd0fed787d73cc6585e2eef7212161f29c8053' + when '0.6.3' then '5452d29f1cf0720c4ae0e0ec1cc5e44b0068a0340a6b61ab5ec245fa0f3447ad' end end end diff --git a/libraries/consul_installation_git.rb b/libraries/consul_installation_git.rb index 6a61fc49..7a6439cc 100644 --- a/libraries/consul_installation_git.rb +++ b/libraries/consul_installation_git.rb @@ -7,62 +7,65 @@ require 'poise' module ConsulCookbook - module Resource - # A `consul_installation` resource which manages the Consul installation - # from the main git repository. + module Provider + # A `consul_installation` provider which manages Consul installation + # from the Go source builds. # @action create # @action remove # @provides consul_installation - # @provides consul_installation_git + # @example + # consul_installation '0.5.0' do + # provider 'git' + # end # @since 2.0 - class ConsulInstallationGit < Chef::Resource - include Poise(fused: true) - provides(:consul_installation_git) + class ConsulInstallationGit < Chef::Provider + include Poise(inversion: :consul_installation) + provides(:git) + inversion_attribute 'consul' - # @!attribute git_url - # @return [String] - attribute(:git_url, kind_of: String, required: true) - # @!attribute git_ref - # @return [String] - attribute(:git_ref, kind_of: String, default: 'master') - # @!attribute git_path - # @return [String] - attribute(:git_path, kind_of: String, default: '/usr/local/src/consul') + # Set the default inversion options. + # @return [Hash] + # @api private + def self.default_inversion_options(node, new_resource) + super.merge( + version: new_resource.version, + git_url: 'https://github.com/hashicorp/consul', + git_path: '/usr/local/src/consul' + ) + end - action(:create) do + def action_create notifying_block do - include_recipe 'golang::default' + include_recipe 'golang::default', 'build-essential::default' + golang_package 'github.com/mitchellh/gox' + golang_package 'github.com/tools/godep' - git new_resource.git_path do - repository new_resource.git_url - reference new_resource.git_ref + git options[:git_path] do + repository options[:git_url] + reference options.fetch(:git_ref, "v#{new_resource.version}") action :checkout end - golang_package 'github.com/hashicorp/consul' do - action :install - end - - link '/usr/local/bin/consul' do - to ::File.join(new_resource.git_path, 'bin', 'consul') + execute 'make' do + cwd options[:git_path] + environment(PATH: "#{node['go']['install_dir']}/go/bin:#{node['go']['gobin']}:/usr/bin:/bin", + GOPATH: node['go']['gopath']) end end end - action(:remove) do + def action_remove notifying_block do - directory new_resource.git_path do + directory options[:git_path] do recursive true action :delete end - - link ::File.join(new_resource.git_path, 'bin', 'consul') do - to new_resource.target_path - only_if { new_resource.target_path } - action :delete - end end end + + def consul_binary + ::File.join(options[:git_path], 'bin', 'consul') + end end end end diff --git a/libraries/consul_installation_package.rb b/libraries/consul_installation_package.rb index b7df6f3b..dee75c63 100644 --- a/libraries/consul_installation_package.rb +++ b/libraries/consul_installation_package.rb @@ -3,48 +3,61 @@ # License: Apache 2.0 # # Copyright 2014-2016, Bloomberg Finance L.P. +# require 'poise' module ConsulCookbook - module Resource - # A `consul_installation_package` resource. + module Provider + # A `consul_installation` provider which installs Consul from + # package source. # @action create # @action remove # @provides consul_installation - # @provides consul_installation_package + # @example + # consul_installation '0.5.0' do + # provider 'package' + # end # @since 2.0 - class ConsulInstallationPackage < Chef::Resource - include Poise(fused: true) - provides(:consul_installation_package) + class ConsulInstallationPackage < Chef::Provider + include Poise(inversion: :consul_installation) + provides(:package) + inversion_attribute 'consul' - # @!attribute package_version - # @return [String] - attribute(:package_version, kind_of: String, name_attribute: true) - # @!attribute package_name - # @return [String] - attribute(:package_name, kind_of: String, default: 'consul') - # @!attribute package_source - # @return [String] - attribute(:package_source, kind_of: String) + # Set the default inversion options. + # @return [Hash] + # @api private + def self.default_inversion_options(node, new_resource) + super.merge( + version: new_resource.version, + package_name: 'consul' + ) + end - action(:create) do + def action_create notifying_block do - package new_resource.package_name do - version new_resource.package_version if new_resource.package_version - source new_resource.package_source if new_resource.package_source + package options[:package_name] do + source options[:package_source] + checksum options[:package_checksum] + version options[:version] action :upgrade end end end - action(:remove) do + def action_remove notifying_block do - package new_resource.package_name do - version new_resource.package_version if new_resource.package_version - action :remove + package options[:package_name] do + source options[:package_source] + checksum options[:package_checksum] + version options[:version] + action :uninstall end end end + + def consul_binary + options.fetch(:consul_binary, '/usr/local/bin/consul') + end end end end diff --git a/libraries/consul_installation_web_ui.rb b/libraries/consul_installation_web_ui.rb deleted file mode 100644 index e200541e..00000000 --- a/libraries/consul_installation_web_ui.rb +++ /dev/null @@ -1,66 +0,0 @@ -# -# Cookbook: consul -# License: Apache 2.0 -# -# Copyright 2014-2016, Bloomberg Finance L.P. -# -require 'poise' - -module ConsulCookbook - module Resource - # A `consul_installation` resource which manages the Consul Web UI - # installation from an binary. - # @action create - # @action remove - # @provides consul_installation_web_ui - # @since 2.0 - class ConsulInstallationWebUi < Chef::Resource - include Poise(fused: true) - include Helpers::InstallationWebUi - provides(:consul_installation_web_ui) - - # @!attribute version - # @return [String] - attribute(:version, kind_of: String, default: lazy { default_version }) - # @!attribute binary_url - # @return [String] - attribute(:binary_url, kind_of: String, required: true) - # @!attribute binary_path - # @return [String, NilClass] - attribute(:binary_path, kind_of: [String, NilClass], default: nil) - # @!attribute binary_checksum - # @return [String] - attribute(:binary_checksum, kind_of: String, lazy { default_checksum }) - - action(:create) do - notifying_block do - basename = ::File.basename(new_resource.url) - remote_file ::File.join(Chef::Config[:file_cache_path], basename) do - not_if { new_resource.binary_path } - end - - artifact = libartifact_file "consul-webui-#{new_resource.version}" do - artifact_name 'consul-webui' - artifact_version new_resource.version - install_path new_resource.target_path - remote_url binary_url - remote_checksum new_resource.binary_checksum - end - end - end - - action(:remove) do - notifying_block do - artifact = libartifact_file "consul-webui-#{new_resource.version}" do - artifact_name 'consul-webui' - artifact_version new_resource.version - install_path new_resource.target_path - remote_url binary_url - remote_checksum new_resource.binary_checksum - action :delete - end - end - end - end - end -end diff --git a/libraries/consul_service.rb b/libraries/consul_service.rb index e48f471d..ba49d9b2 100644 --- a/libraries/consul_service.rb +++ b/libraries/consul_service.rb @@ -18,30 +18,21 @@ class ConsulService < Chef::Resource include PoiseService::ServiceMixin include ConsulCookbook::Helpers - # @!attribute version - # @return [String] - attribute(:version, kind_of: String, required: true) # @!attribute config_file # @return [String] attribute(:config_file, kind_of: String, default: lazy { node['consul']['config']['path'] }) # @!attribute user + # The service user the Consul process runs as. # @return [String] attribute(:user, kind_of: String, default: 'consul') # @!attribute group + # The service group the Consul process runs as. # @return [String] attribute(:group, kind_of: String, default: 'consul') # @!attribute environment + # The environment that the Consul process starts with. # @return [String] attribute(:environment, kind_of: Hash, default: lazy { default_environment }) - # @!attribute package_name - # @return [String] - attribute(:package_name, kind_of: String, default: 'consul') - # @!attribute binary_url - # @return [String] - attribute(:binary_url, kind_of: String) - # @!attribute source_url - # @return [String] - attribute(:source_url, kind_of: String) # @!attribute data_dir # @return [String] attribute(:data_dir, kind_of: String, default: lazy { node['consul']['config']['data_dir'] }) @@ -51,6 +42,14 @@ class ConsulService < Chef::Resource # @!attribute nssm_params # @return [String] attribute(:nssm_params, kind_of: Hash, default: lazy { node['consul']['service']['nssm_params'] }) + # @!attribute consul_binary + # The location of the Consul executable. + # @return [String] + attribute(:consul_binary, kind_of: String, default: '/usr/local/bin/consul') + + def command + "#{consul_binary} agent -config-file=#{config_file} -config-dir=#{config_dir}" + end def default_environment { @@ -63,7 +62,7 @@ def default_environment module Provider # A provider for managing the Consul service. - # @since 1.0.0 + # @since 1.0 class ConsulService < Chef::Provider include Poise provides(:consul_service) @@ -72,29 +71,18 @@ class ConsulService < Chef::Provider def action_enable notifying_block do - [new_resource.data_dir, new_resource.config_dir].each do |dirname| - directory dirname do - recursive true - owner new_resource.user - group new_resource.group - mode '0755' - end - end - end - super - end - - def action_disable - notifying_block do - file new_resource.config_file do - action :delete + directory [new_resource.data_dir, new_resource.config_dir] do + recursive true + owner new_resource.user + group new_resource.group + mode '0755' end end super end def service_options(service) - service.command(new_resource.command(new_resource.config_file, new_resource.config_dir)) + service.command(new_resource.command) service.directory(new_resource.data_dir) service.user(new_resource.user) service.environment(new_resource.environment) diff --git a/libraries/helpers_installation_binary.rb b/libraries/helpers_installation_binary.rb deleted file mode 100644 index 2b6bfd65..00000000 --- a/libraries/helpers_installation_binary.rb +++ /dev/null @@ -1,115 +0,0 @@ -# -# Cookbook: consul -# License: Apache 2.0 -# -# Copyright 2014-2016, Bloomberg Finance L.P. -# - -module ConsulCookbook - module Helpers - # @since 2.0 - module InstallationBinary # rubocop:disable Metrics/ModuleLength - extend self - - def fancy_filename - case node['kernel']['arch'] - when 'x86_64' then ['consul', version, node['os'], 'amd64'].join('_') - when 'x86' then ['consul', version, node['os'], '386'].join('_') - when 'arm' then ['consul', version, node['os'], 'arm'].join('_') - end - end - - def default_checksum - case [node['os'], node['kernel']['arch']].join('-') - when 'darwin-x86_64' - case version - when '0.5.0' then '24d9758c873e9124e0ce266f118078f87ba8d8363ab16c2e59a3cd197b77e964' - when '0.5.1' then '161f2a8803e31550bd92a00e95a3a517aa949714c19d3124c46e56cfdc97b088' - when '0.5.2' then '87be515d7dbab760a61a359626a734f738d46ece367f68422b7dec9197d9eeea' - when '0.6.0' then '29ddff01368458048731afa586cec5426c8033a914b43fc83d6442e0a522c114' - when '0.6.1' then '358654900772b3477497f4a5b5a841f2763dc3062bf29212606a97f5a7a675f3' - when '0.6.2' then '3089f77fcdb922894456ea6d0bc78a2fb60984d1d3687fa9d8f604b266c83446' - when '0.6.3' then '6dff4ffc61d66aacd627a176737b8725624718a9e68cc81460a3df9b241c7932' - end - when 'darwin-x86' - case version - when '0.6.0' then '95d57bfcc287bc344ec3ae8372cf735651af1158c5b1345e6f30cd9a9c811815' - when '0.6.1' then '41dfcc0aefe0a60bdde413eaa8a4a0c98e396d6b438494f1cf29b32d07759b8e' - when '0.6.2' then '973105816261c8001fcfa76c9fb707fa56325460476fb0daa97b9ece0602a918' - when '0.6.3' then '7fb30756504cd9559c9b23e5d0d8d73a847ee62ed85d39955b5906c2f59a5bc1' - end - when 'solaris-x86_64' - case version - when '0.6.2' then 'f5655f0b173e5d51c5b92327d1fc7f24ac0939897a1966da09146e4eb75af9d1' - when '0.6.3' then 'e6a286ff17a2345b8800732850eadb858b3dba9486355e1164a774ccec2f0e98' - end - when 'windows-x86_64' - case version - when '0.6.0' then '182beea0d8d346a9bfd70679621a5542aeeeea1f35be81fa3d3aeec2479bac3d' - when '0.6.1' then '2be6b0f0fdebff00aea202e9846131af570676f52e2936728cbf29ffbb02f57f' - when '0.6.2' then 'df3234fb7def7138b7cb8c73fe7c05942ec1e485925701a7b38fc7e2396a212f' - when '0.6.3' then '04cd1fdc9cd3a27ffc64e312e40142db7af0d240608f8080ec6d238294b20652' - end - when 'windows-x86' - case version - when '0.5.0' then '7fd760ee8a5c2756391cacc1e924ae602b16cdad838db068e564f798383ad714' - when '0.5.1' then 'bb9e1753cf793ad6f9db34bd6e18fb0fa5b0696a8a51a7f1c61484386dfe6682' - when '0.5.2' then '2e866812de16f1a6138a0fd1eebc76143f1314826e3b52597a55ac510ae94be6' - when '0.6.0' then '8379afd07668933c120880bba8228277e380abb14e07a6c45b94562ac19b37bd' - when '0.6.1' then '10197d1f7be0d0087414c9965008ddd88e9fcd9ac9d5bd02d72d65eda36f5834' - when '0.6.2' then 'f072d89c098dde143897e653d5adaf23125b58062344ef4be4029d635f959654' - when '0.6.3' then '55733a730c5055d0ed1dc2656b2b6a27b21c7c361a907919cfae90aab2dff870' - end - when 'linux-x86_64' - case version - when '0.5.0' then '161f2a8803e31550bd92a00e95a3a517aa949714c19d3124c46e56cfdc97b088' - when '0.5.1' then '967ad75865b950698833eaf26415ba48d8a22befb5d4e8c77630ad70f251b100' - when '0.5.2' then '171cf4074bfca3b1e46112105738985783f19c47f4408377241b868affa9d445' - when '0.6.0' then '307fa26ae32cb8732aed2b3320ed8daf02c28b50d952cbaae8faf67c79f78847' - when '0.6.1' then 'dbb3c348fdb7cdfc03e5617956b243c594a399733afee323e69ef664cdadb1ac' - when '0.6.2' then '7234eba9a6d1ce169ff8d7af91733e63d8fc82193d52d1b10979d8be5c959095' - when '0.6.3' then 'b0532c61fec4a4f6d130c893fd8954ec007a6ad93effbe283a39224ed237e250' - end - when 'linux-x86' - case version - when '0.5.0' then '4b6147c30596a30361d4753d409f8a1af9518f54f5ed473a4c4ac973738ac0fd' - when '0.5.1' then 'dad93a02c01de885daee191bcc5a05ca2bf106200da61db33694a658432d8399' - when '0.5.2' then '29306ce398109f954ceeea3af79878be4fb0d949f8af3a27c95ccef2101e8f60' - when '0.6.0' then 'f58f3f03a8b48d89bb8be94a6d1767393ad2a410c920b064066e01c7fa24f06c' - when '0.6.1' then '34b8d4a2a9ec85082b6e93c6785ba9c54663fec414062e45dd4386db46a533c4' - when '0.6.2' then '500ac8c75768b7f2d63521d2501ff8cc5fb7f9ddf6c550e9449364810c96f419' - when '0.6.3' then '2afb65383ab913344daaa9af827c1e8576c7cae16e93798048122929b6e4cc92' - end - when 'linux-arm' - case version - when '0.6.0' then '425e7332789deb446a486ac25f7143aba5f16453ac46ede39b71ab6a361d8726' - when '0.6.1' then '5b61e9ed10e02990aa8a2a0116c398c61608bc7f5051cb5a13750ffd47a54d51' - when '0.6.2' then 'b6b4f66f6dd8b1d4ebbd0339f4ed78c4853c7bd0d42fd15af70179b5bc65482e' - when '0.6.3' then 'c5fd5278be2757d2468bc7e263af15bc9a9e80fc5108fec658755804ea9bca56' - end - when 'freebsd-x86_64' - case version - when '0.6.0' then 'd7be5c95b971f48ccbd2c53c342dced9a3d0a5bc58f57b4f2e75672d96929923' - when '0.6.1' then '04688dfabedf6ded7f3d548110c7d9ffc8d6d3a091062593e421702bc42b465d' - when '0.6.2' then '1ccf96cb58c6fa927ee21c24d9be368ebe91559ed32626a89a715a3781659e3f' - when '0.6.3' then '8bdf2da41e6118af18af9aba0a127d4abb3453a20a9064e1bd1206f5c11ac2c8' - end - when 'freebsd-x86' - case version - when '0.6.0' then 'c5eb9f5c211612148e1e1cd101670fd08fd1abf9b2e541ac2936ab9637626249' - when '0.6.1' then '87d8c56c0c02e2fcde5192614dff9c491af93f7186fd55caae3fbe2c4d6ca80c' - when '0.6.2' then 'fc87f2ddd2090031e79136954d9e3f85db480d5ed9eba6ae627bf460e4c95e6e' - when '0.6.3' then '4a1aa8f570852eb238b7406172c097f5b32f41a3f01186111e576faa7506248c' - end - when 'freebsd-arm' - case version - when '0.6.0' then '92f29ad00f8f44d3be43b3b038a904c332757eb2a6848a7d6754583c2791e18b' - when '0.6.1' then '7b907fbd4377671de1be2dc0c19f955e1b37cd862c1af8251e9bf6d668b0d3a8' - when '0.6.2' then '30d8d09dd88cdd8d5256cea445fd0fed787d73cc6585e2eef7212161f29c8053' - when '0.6.3' then '5452d29f1cf0720c4ae0e0ec1cc5e44b0068a0340a6b61ab5ec245fa0f3447ad' - end - end - end - end - end -end diff --git a/libraries/helpers_installation_web_ui.rb b/libraries/helpers_installation_web_ui.rb deleted file mode 100644 index 6cf866f4..00000000 --- a/libraries/helpers_installation_web_ui.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# Cookbook: consul -# License: Apache 2.0 -# -# Copyright 2014-2016, Bloomberg Finance L.P. -# - -module ConsulCookbook - module Helpers - # @since 2.0 - module InstallationWebUi # rubocop:disable Metrics/ModuleLength - extend self - - def fancy_filename - ['consul', version, 'web_ui'].join('_') - end - - def default_checksum - case version - when '0.5.0' then '0081d08be9c0b1172939e92af5a7cf9ba4f90e54fae24a353299503b24bb8be9' - when '0.5.1' then 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1' - when '0.5.2' then 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1' - when '0.6.0' then '73c5e7ee50bb4a2efe56331d330e6d7dbf46335599c028344ccc4031c0c32eb0' - when '0.6.1' then 'afccdd540b166b778c7c0483becc5e282bbbb1ee52335bfe94bf757df8c55efc' - when '0.6.2' then 'f144377b8078df5a3f05918d167a52123089fc47b12fc978e6fb375ae93afc90' - when '0.6.3' then '93bbb300cacfe8de90fb3bd5ede7d37ae6ce014898edc520b9c96a676b2bbb72' - end - end - end - end -end diff --git a/recipes/default.rb b/recipes/default.rb index 9c3d9b5b..3549cb5e 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -51,19 +51,11 @@ notifies :restart, "consul_service[#{service_name}]", :delayed end -case node['consul']['install_method'] -when 'binary' - consul_installation_binary 'install consul from binary' do - notifies :restart, "consul_service[#{service_name}]", :delayed - end -when 'package' - consul_installation_package 'install consul from package' do - notifies :restart, "consul_service[#{service_name}]", :delayed - end -when 'git' - consul_installation_git 'install consul from git' do - notifies :restart, "consul_service[#{service_name}]", :delayed +install = consul_installation node['consul']['version'] do |r| + if node['consul']['installation'] + node['consul']['installation'].each_pair { |k, v| r.send(k, v) } end + notifies :restart, "consul_service[#{service_name}]", :delayed end consul_service service_name do |r| diff --git a/recipes/web_ui.rb b/recipes/web_ui.rb deleted file mode 100644 index 9c45e3b3..00000000 --- a/recipes/web_ui.rb +++ /dev/null @@ -1,9 +0,0 @@ -# -# Cookbook: consul -# License: Apache 2.0 -# -# Copyright 2014-2016, Bloomberg Finance L.P. -# - -consul_installation_web_ui 'install consul-webui from binary' do -end From 5cce3efaf1e279734d68a5a7334e61624e8f57c3 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Sun, 6 Mar 2016 23:02:51 -0500 Subject: [PATCH 10/18] Add webui custom resource for installation. --- libraries/consul_installation_webui.rb | 104 +++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 libraries/consul_installation_webui.rb diff --git a/libraries/consul_installation_webui.rb b/libraries/consul_installation_webui.rb new file mode 100644 index 00000000..e9e3e84e --- /dev/null +++ b/libraries/consul_installation_webui.rb @@ -0,0 +1,104 @@ +# +# Cookbook: consul +# License: Apache 2.0 +# +# Copyright 2014-2016, Bloomberg Finance L.P. +# +require 'poise' + +module ConsulCookbook + module Provider + # A `consul_installation` provider which manages Consul Web UI + # remote installation. + # @action create + # @action remove + # @provides consul_installation + # @example + # consul_installation '0.5.0' do + # provider 'webui' + # end + # @since 2.0 + class ConsulInstallationWebui < Chef::Provider + include Poise(inversion: :consul_installation) + provides(:webui) + inversion_attribute 'consul' + + # Set the default inversion options. + # @return [Hash] + # @api private + def self.default_inversion_options(node, resource) + archive_basename = binary_basename(node, resource) + super.merge( + version: new_resource.version, + archive_url: default_archive_url % { version: new_resource.version, basename: archive_basename }, + archive_basename: archive_basename, + archive_checksum: binary_checksum(node, resource), + extract_to: '/opt/consul-webui' + ) + end + + def action_create + archive_url = options[:archive_url] % { + version: options[:version], + basename: options[:archive_basename] + } + + notifying_block do + include_recipe 'libarchive::default' + + archive = remote_file options[:archive_basename] do + path ::File.join(Chef::Config[:file_cache_path], name) + source archive_url + checksum options[:archive_checksum] + end + + directory ::File.join(options[:extract_to], new_resource.version) do + recursive true + end + + libarchive_file options[:archive_basename] do + path archive.path + mode options[:extract_mode] + owner options[:extract_owner] + group options[:extract_group] + extract_to ::File.join(options[:extract_to], new_resource.version) + extract_options options[:extract_options] + end + end + end + + def action_remove + notifying_block do + directory ::File.join(options[:extract_to], new_resource.version) do + recursive true + action :delete + end + end + end + + def consul_binary + ::File.join(options[:extract_to], new_resource.version, 'consul') + end + + def self.default_archive_url + "https://releases.hashicorp.com/consul/%{version}/%{basename}" # rubocop:disable Style/StringLiterals + end + + def self.binary_basename(node, resource) + ['consul', resource.version, 'web_ui'].join('_').concat('zip') + end + + def self.binary_checksum(node, resource) + case resource.version + when '0.5.0' then '0081d08be9c0b1172939e92af5a7cf9ba4f90e54fae24a353299503b24bb8be9' + when '0.5.1' then 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1' + when '0.5.2' then 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1' + when '0.6.0' then '73c5e7ee50bb4a2efe56331d330e6d7dbf46335599c028344ccc4031c0c32eb0' + when '0.6.1' then 'afccdd540b166b778c7c0483becc5e282bbbb1ee52335bfe94bf757df8c55efc' + when '0.6.2' then 'f144377b8078df5a3f05918d167a52123089fc47b12fc978e6fb375ae93afc90' + when '0.6.3' then '93bbb300cacfe8de90fb3bd5ede7d37ae6ce014898edc520b9c96a676b2bbb72' + end + end + end + end +end From a0158e3ae51661e9746dbeab328262662558c3d7 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Sun, 6 Mar 2016 23:06:34 -0500 Subject: [PATCH 11/18] Fix issues with failing integration tests. --- .kitchen.yml | 22 ++++++------------- attributes/default.rb | 4 ---- libraries/consul_installation_binary.rb | 4 ++-- libraries/consul_installation_git.rb | 4 ++-- libraries/consul_installation_package.rb | 4 ++-- libraries/consul_installation_webui.rb | 4 ++-- libraries/consul_service.rb | 13 ++++++----- metadata.rb | 1 + recipes/default.rb | 10 ++++++--- .../serverspec/localhost/default_spec.rb | 15 +++++-------- 10 files changed, 35 insertions(+), 46 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index d9a97eec..bf27e071 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -16,6 +16,8 @@ platforms: suites: - name: default run_list: + - recipe[apt::default] + - recipe[yum::default] - recipe[consul::default] attributes: consul: @@ -26,28 +28,18 @@ suites: encrypt: CGXC2NsXW4AvuB4h5ODYzQ== excludes: - windows-2012r2 - - name: source + - name: git run_list: + - recipe[apt::default] + - recipe[yum::default] - recipe[consul::default] attributes: consul: config: *default-config - service: - install_method: source + installation: + provider: git excludes: - windows-2012r2 - - name: package - run_list: - - recipe[consul::default] - attributes: - consul: - config: *default-config - service: - install_method: package - excludes: - - centos-7.2 - - centos-6.7 - - centos-5.11 - name: acl run_list: - recipe[consul::default] diff --git a/attributes/default.rb b/attributes/default.rb index 4968ac19..c39e7d4d 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -33,10 +33,6 @@ default['consul']['service']['config_dir'] = join_path config_prefix_path, 'conf.d' -default['consul']['service']['binary_url'] = "https://releases.hashicorp.com/consul/%{version}/%{filename}.zip" # rubocop:disable Style/StringLiterals - -default['consul']['service']['source_url'] = 'https://github.com/hashicorp/consul' - default['consul']['version'] = '0.6.3' # Windows only diff --git a/libraries/consul_installation_binary.rb b/libraries/consul_installation_binary.rb index de59546e..96331b4f 100644 --- a/libraries/consul_installation_binary.rb +++ b/libraries/consul_installation_binary.rb @@ -32,8 +32,8 @@ def self.provides_auto?(_node, _resource) def self.default_inversion_options(node, resource) archive_basename = binary_basename(node, resource) super.merge( - version: new_resource.version, - archive_url: default_archive_url % { version: new_resource.version, basename: archive_basename }, + version: resource.version, + archive_url: default_archive_url % { version: resource.version, basename: archive_basename }, archive_basename: archive_basename, archive_checksum: binary_checksum(node, resource), extract_to: '/opt/consul' diff --git a/libraries/consul_installation_git.rb b/libraries/consul_installation_git.rb index 7a6439cc..4a00dd4e 100644 --- a/libraries/consul_installation_git.rb +++ b/libraries/consul_installation_git.rb @@ -26,9 +26,9 @@ class ConsulInstallationGit < Chef::Provider # Set the default inversion options. # @return [Hash] # @api private - def self.default_inversion_options(node, new_resource) + def self.default_inversion_options(node, resource) super.merge( - version: new_resource.version, + version: resource.version, git_url: 'https://github.com/hashicorp/consul', git_path: '/usr/local/src/consul' ) diff --git a/libraries/consul_installation_package.rb b/libraries/consul_installation_package.rb index dee75c63..881c5a20 100644 --- a/libraries/consul_installation_package.rb +++ b/libraries/consul_installation_package.rb @@ -26,9 +26,9 @@ class ConsulInstallationPackage < Chef::Provider # Set the default inversion options. # @return [Hash] # @api private - def self.default_inversion_options(node, new_resource) + def self.default_inversion_options(node, resource) super.merge( - version: new_resource.version, + version: resource.version, package_name: 'consul' ) end diff --git a/libraries/consul_installation_webui.rb b/libraries/consul_installation_webui.rb index e9e3e84e..52056fba 100644 --- a/libraries/consul_installation_webui.rb +++ b/libraries/consul_installation_webui.rb @@ -29,8 +29,8 @@ class ConsulInstallationWebui < Chef::Provider def self.default_inversion_options(node, resource) archive_basename = binary_basename(node, resource) super.merge( - version: new_resource.version, - archive_url: default_archive_url % { version: new_resource.version, basename: archive_basename }, + version: resource.version, + archive_url: default_archive_url % { version: resource.version, basename: archive_basename }, archive_basename: archive_basename, archive_checksum: binary_checksum(node, resource), extract_to: '/opt/consul-webui' diff --git a/libraries/consul_service.rb b/libraries/consul_service.rb index ba49d9b2..7b2b6ae9 100644 --- a/libraries/consul_service.rb +++ b/libraries/consul_service.rb @@ -67,15 +67,16 @@ class ConsulService < Chef::Provider include Poise provides(:consul_service) include PoiseService::ServiceMixin - include ConsulCookbook::Helpers def action_enable notifying_block do - directory [new_resource.data_dir, new_resource.config_dir] do - recursive true - owner new_resource.user - group new_resource.group - mode '0755' + [new_resource.data_dir, new_resource.config_dir].each do |dirname| + directory dirname do + recursive true + owner new_resource.user + group new_resource.group + mode '0755' + end end end super diff --git a/metadata.rb b/metadata.rb index 35f59b41..a7a2bc07 100644 --- a/metadata.rb +++ b/metadata.rb @@ -18,6 +18,7 @@ supports 'arch' supports 'windows' +depends 'build-essential' depends 'chef-sugar' depends 'chef-vault', '~> 1.3' depends 'nssm' diff --git a/recipes/default.rb b/recipes/default.rb index 3549cb5e..10896d1d 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -59,11 +59,15 @@ end consul_service service_name do |r| + version node['consul']['version'] + config_file config.path + consul_binary install.consul_binary + unless windows? user node['consul']['service_user'] group node['consul']['service_group'] end - version node['consul']['version'] - config_file config.path - node['consul']['service'].each_pair { |k, v| r.send(k, v) } + if node['consul']['service'] + node['consul']['service'].each_pair { |k, v| r.send(k, v) } + end end diff --git a/test/integration/default/serverspec/localhost/default_spec.rb b/test/integration/default/serverspec/localhost/default_spec.rb index 42b771c5..e5818519 100644 --- a/test/integration/default/serverspec/localhost/default_spec.rb +++ b/test/integration/default/serverspec/localhost/default_spec.rb @@ -1,15 +1,10 @@ require 'spec_helper' -describe file('/srv/consul/current/consul') do +describe file('/opt/consul/0.6.3/consul') do it { should be_file } it { should be_executable } end -describe file('/usr/local/bin/consul') do - it { should be_symlink } - it { should be_linked_to '/srv/consul/current/consul' } -end - describe group('consul') do it { should exist } end @@ -31,7 +26,7 @@ end end -describe command('/usr/local/bin/consul members -detailed') do +describe command('/opt/consul/0.6.3/consul members -detailed') do its(:exit_status) { should eq 0 } its(:stdout) { should match %r{\balive\b} } its(:stdout) { should match %r{\brole=consul\b} } @@ -47,7 +42,7 @@ it { should be_file } it { should be_owned_by 'consul' } it { should be_grouped_into 'consul' } - + it { should be_mode 640 } end @@ -55,7 +50,7 @@ it { should be_directory } it { should be_owned_by 'consul' } it { should be_grouped_into 'consul' } - + it { should be_mode 755 } end @@ -63,6 +58,6 @@ it { should be_directory } it { should be_owned_by 'consul' } it { should be_grouped_into 'consul' } - + it { should be_mode 755 } end From 0381574b57ca34382a904ac74da9d87e1090ed1a Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 7 Mar 2016 16:46:35 -0500 Subject: [PATCH 12/18] Fix YARD documentation and annotations,. --- libraries/consul_config.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libraries/consul_config.rb b/libraries/consul_config.rb index a8b393e8..20b654a2 100644 --- a/libraries/consul_config.rb +++ b/libraries/consul_config.rb @@ -9,7 +9,7 @@ module ConsulCookbook module Resource - # @since 1.0.0 + # @since 1.0 class ConsulConfig < Chef::Resource include Poise(fused: true) include ConsulCookbook::Helpers @@ -18,23 +18,18 @@ class ConsulConfig < Chef::Resource # @!attribute path # @return [String] attribute(:path, kind_of: String, name_attribute: true) - # @!attribute owner # @return [String] attribute(:owner, kind_of: String, default: 'consul') - # @!attribute group # @return [String] attribute(:group, kind_of: String, default: 'consul') - # @!attribute bag_name # @return [String] attribute(:bag_name, kind_of: String, default: 'secrets') - # @!attribute bag_item # @return [String] attribute(:bag_item, kind_of: String, default: 'consul') - # @!attribute options # @return [Hash] attribute(:options, option_collector: true) From 5090ca2be0e69afc94cbc0ac6efe0e9778982b03 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 7 Mar 2016 16:46:54 -0500 Subject: [PATCH 13/18] Update the test kitchen harness for webui. --- .kitchen.yml | 12 ++++++++++++ test/cookbooks/consul_spec/recipes/consul_ui.rb | 6 ------ 2 files changed, 12 insertions(+), 6 deletions(-) delete mode 100644 test/cookbooks/consul_spec/recipes/consul_ui.rb diff --git a/.kitchen.yml b/.kitchen.yml index bf27e071..36bbb4c7 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -40,6 +40,18 @@ suites: provider: git excludes: - windows-2012r2 + - name: webui + run_list: + - recipe[apt::default] + - recipe[yum::default] + - recipe[consul::default] + attributes: + consul: + config: *default-config + installation: + provider: webui + excludes: + - windows-2012r2 - name: acl run_list: - recipe[consul::default] diff --git a/test/cookbooks/consul_spec/recipes/consul_ui.rb b/test/cookbooks/consul_spec/recipes/consul_ui.rb deleted file mode 100644 index a52abf4b..00000000 --- a/test/cookbooks/consul_spec/recipes/consul_ui.rb +++ /dev/null @@ -1,6 +0,0 @@ - consul_ui 'myconsul-ui' do - owner 'myconsul' - group 'myconsul' - version '0.5.1' - install_path '/opt' - end From ea2fe47769a76c0bb22a1a3d15f27e3e1932c4aa Mon Sep 17 00:00:00 2001 From: John Bellone Date: Mon, 7 Mar 2016 16:54:57 -0500 Subject: [PATCH 14/18] Remove TLS certificate management from this policy. I am deferring the management of TLS certificates to wrapper cookbooks. This closes #247. --- libraries/consul_config.rb | 54 ---------------- .../acl/serverspec/localhost/default_spec.rb | 30 --------- .../serverspec/localhost/default_spec.rb | 63 ------------------- test/spec/libraries/consul_config_spec.rb | 45 ------------- 4 files changed, 192 deletions(-) delete mode 100644 test/integration/acl/serverspec/localhost/default_spec.rb delete mode 100644 test/integration/default/serverspec/localhost/default_spec.rb diff --git a/libraries/consul_config.rb b/libraries/consul_config.rb index 20b654a2..081ac53f 100644 --- a/libraries/consul_config.rb +++ b/libraries/consul_config.rb @@ -113,50 +113,6 @@ def tls? action(:create) do notifying_block do - if new_resource.tls? - include_recipe 'chef-vault::default' - - [new_resource.ca_file, new_resource.cert_file, new_resource.key_file].each do |filename| - directory ::File.dirname(filename) do - recursive true - if node['os'].eql? 'linux' - owner new_resource.owner - group new_resource.group - mode '0755' - end - end - end - - item = chef_vault_item(new_resource.bag_name, new_resource.bag_item) - file new_resource.ca_file do - content item['ca_certificate'] - if node['os'].eql? 'linux' - owner new_resource.owner - group new_resource.group - mode '0644' - end - end - - file new_resource.cert_file do - content item['certificate'] - if node['os'].eql? 'linux' - owner new_resource.owner - group new_resource.group - mode '0644' - end - end - - file new_resource.key_file do - sensitive true - content item['private_key'] - if node['os'].eql? 'linux' - owner new_resource.owner - group new_resource.group - mode '0640' - end - end - end - directory ::File.dirname(new_resource.path) do recursive true if node['os'].eql? 'linux' @@ -180,16 +136,6 @@ def tls? action(:delete) do notifying_block do - if new_resource.tls? - file new_resource.cert_file do - action :delete - end - - file new_resource.key_file do - action :delete - end - end - file new_resource.path do action :delete end diff --git a/test/integration/acl/serverspec/localhost/default_spec.rb b/test/integration/acl/serverspec/localhost/default_spec.rb deleted file mode 100644 index 319666c8..00000000 --- a/test/integration/acl/serverspec/localhost/default_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper' - -describe command('curl -s "http://localhost:8500/v1/acl/info/anonymous"') do - its(:exit_status) { should eq 0 } - its(:stdout) { should match('"ID":"anonymous"') } - its(:stdout) { should match('"Name":"Anonymous Token"') } - its(:stdout) { should match('"Type":"client"') } - its(:stdout) { should match('"Rules":""') } -end - -describe file('/tmp/anonymous-notified') do - it { should_not exist } -end - -describe command('curl -s "http://localhost:8500/v1/acl/info/management_token"') do - its(:exit_status) { should eq 0 } - its(:stdout) { should match('[]') } -end - -describe file('/tmp/management_token-notified') do - it { should exist } -end - -describe command('curl -s "http://localhost:8500/v1/acl/info/reader_token"') do - its(:exit_status) { should eq 0 } - its(:stdout) { should match('"ID":"reader_token"') } - its(:stdout) { should match('"Name":""') } - its(:stdout) { should match('"Type":"client"') } - its(:stdout) { should match /\"Rules\":\"dummyrule_line1\\ndummyrule_line2\\n\"/ } -end diff --git a/test/integration/default/serverspec/localhost/default_spec.rb b/test/integration/default/serverspec/localhost/default_spec.rb deleted file mode 100644 index e5818519..00000000 --- a/test/integration/default/serverspec/localhost/default_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'spec_helper' - -describe file('/opt/consul/0.6.3/consul') do - it { should be_file } - it { should be_executable } -end - -describe group('consul') do - it { should exist } -end - -describe user('consul') do - it { should exist } - it { should belong_to_group('consul') } - it { should have_login_shell('/bin/bash') } -end - -describe service('consul') do - it { should be_enabled } - it { should be_running } -end - -[8300, 8400, 8500, 8600].each do |p| - describe port(p) do - it { should be_listening } - end -end - -describe command('/opt/consul/0.6.3/consul members -detailed') do - its(:exit_status) { should eq 0 } - its(:stdout) { should match %r{\balive\b} } - its(:stdout) { should match %r{\brole=consul\b} } - its(:stdout) { should match %r{\bbootstrap=1\b} } - its(:stdout) { should match %r{\bdc=fortmeade\b} } -end - -config_file = '/etc/consul/consul.json' -config_dir = '/etc/consul/conf.d' -data_dir = '/var/lib/consul' - -describe file(config_file) do - it { should be_file } - it { should be_owned_by 'consul' } - it { should be_grouped_into 'consul' } - - it { should be_mode 640 } -end - -describe file(config_dir) do - it { should be_directory } - it { should be_owned_by 'consul' } - it { should be_grouped_into 'consul' } - - it { should be_mode 755 } -end - -describe file(data_dir) do - it { should be_directory } - it { should be_owned_by 'consul' } - it { should be_grouped_into 'consul' } - - it { should be_mode 755 } -end diff --git a/test/spec/libraries/consul_config_spec.rb b/test/spec/libraries/consul_config_spec.rb index a5454f83..017e0428 100644 --- a/test/spec/libraries/consul_config_spec.rb +++ b/test/spec/libraries/consul_config_spec.rb @@ -8,7 +8,6 @@ before do recipe = double('Chef::Recipe') allow_any_instance_of(Chef::RunContext).to receive(:include_recipe).and_return([recipe]) - allow_any_instance_of(Chef::Provider).to receive(:chef_vault_item) { { 'ca_certificate' => 'foo', 'certificate' => 'bar', 'private_key' => 'baz' } } end context 'sets options directly' do @@ -29,50 +28,6 @@ EOH end - context 'manages certificates' do - recipe do - consul_config '/etc/consul/default.json' do - key_file '/etc/consul/ssl/private/consul.key' - ca_file '/etc/consul/ssl/CA/ca.crt' - cert_file '/etc/consul/ssl/certs/consul.crt' - verify_incoming true - verify_outgoing true - end - end - - it { is_expected.to create_directory('/etc/consul/ssl/CA') } - it { is_expected.to create_directory('/etc/consul/ssl/certs') } - it { is_expected.to create_directory('/etc/consul/ssl/private') } - - it do - is_expected.to create_file('/etc/consul/ssl/CA/ca.crt') - .with(content: 'foo') - .with(owner: 'consul') - .with(group: 'consul') - .with(mode: '0644') - end - - it do - is_expected.to create_file('/etc/consul/ssl/certs/consul.crt') - .with(content: 'bar') - .with(owner: 'consul') - .with(group: 'consul') - .with(mode: '0644') - end - - it do - is_expected.to create_file('/etc/consul/ssl/private/consul.key') - .with(content: 'baz') - .with(sensitive: true) - .with(owner: 'consul') - .with(group: 'consul') - .with(mode: '0640') - end - - it { is_expected.to create_directory('/etc/consul') } - it { is_expected.to create_file('/etc/consul/default.json') } - end - context 'deletes configuration' do recipe do consul_config '/etc/consul/default.json' do From 20332b3dffacb69f12f44391dd0358cd672124fe Mon Sep 17 00:00:00 2001 From: John Bellone Date: Wed, 16 Mar 2016 20:56:39 -0400 Subject: [PATCH 15/18] Fix support for Consul agent install on windows. --- .kitchen.yml | 2 +- attributes/default.rb | 1 - libraries/consul_installation.rb | 4 +- libraries/consul_installation_binary.rb | 34 ++++++---- libraries/consul_installation_git.rb | 4 +- libraries/consul_installation_package.rb | 4 +- libraries/consul_installation_webui.rb | 4 +- libraries/consul_service.rb | 2 +- libraries/consul_service_windows.rb | 21 +------ recipes/default.rb | 2 +- .../acl/serverspec/default_spec.rb | 30 +++++++++ .../default/serverspec/default_spec.rb | 63 +++++++++++++++++++ .../serverspec/localhost/logging_spec.rb | 11 ---- .../serverspec}/default_spec.rb | 12 +++- 14 files changed, 137 insertions(+), 57 deletions(-) create mode 100644 test/integration/acl/serverspec/default_spec.rb create mode 100644 test/integration/default/serverspec/default_spec.rb delete mode 100644 test/integration/windefault/serverspec/localhost/logging_spec.rb rename test/integration/{windefault/serverspec/localhost => zip/serverspec}/default_spec.rb (75%) diff --git a/.kitchen.yml b/.kitchen.yml index 36bbb4c7..71a218bc 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -71,7 +71,7 @@ suites: - centos-7.2 - centos-6.7 - centos-5.11 - - name: windefault + - name: zip includes: - windows-2012r2 run_list: diff --git a/attributes/default.rb b/attributes/default.rb index c39e7d4d..912c3b3a 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -8,7 +8,6 @@ default['consul']['service_name'] = 'consul' default['consul']['service_user'] = 'consul' default['consul']['service_group'] = 'consul' -default['consul']['install_method'] = 'binary' default['consul']['config']['bag_name'] = 'secrets' default['consul']['config']['bag_item'] = 'consul' diff --git a/libraries/consul_installation.rb b/libraries/consul_installation.rb index dc5fb3ff..b231a120 100644 --- a/libraries/consul_installation.rb +++ b/libraries/consul_installation.rb @@ -23,8 +23,8 @@ class ConsulInstallation < Chef::Resource # @return [String] attribute(:version, kind_of: String, name_attribute: true) - def consul_binary - @consul_binary ||= provider_for_action(:consul_binary).consul_binary + def consul_program + @program ||= provider_for_action(:consul_program).consul_program end end end diff --git a/libraries/consul_installation_binary.rb b/libraries/consul_installation_binary.rb index 96331b4f..f2b9ed09 100644 --- a/libraries/consul_installation_binary.rb +++ b/libraries/consul_installation_binary.rb @@ -19,7 +19,7 @@ module Provider class ConsulInstallationBinary < Chef::Provider include Poise(inversion: :consul_installation) provides(:binary) - inversion_attribute 'consul' + inversion_attribute('consul') # @api private def self.provides_auto?(_node, _resource) @@ -47,8 +47,6 @@ def action_create } notifying_block do - include_recipe 'libarchive::default' - archive = remote_file options[:archive_basename] do path ::File.join(Chef::Config[:file_cache_path], name) source archive_url @@ -59,13 +57,23 @@ def action_create recursive true end - libarchive_file options[:archive_basename] do - path archive.path - mode options[:extract_mode] - owner options[:extract_owner] - group options[:extract_group] - extract_to ::File.join(options[:extract_to], new_resource.version) - extract_options options[:extract_options] + windows_zipfile options[:archive_basename] do + path ::File.join(options[:extract_to], new_resource.version) + source archive.path + only_if { node.platform?('windows') } + not_if { ::File.exist?(consul_program) } + end + + unless node.platform?('windows') + include_recipe 'libarchive::default' + libarchive_file options[:archive_basename] do + path archive.path + mode options[:extract_mode] + owner options[:extract_owner] + group options[:extract_group] + extract_to ::File.join(options[:extract_to], new_resource.version) + extract_options options[:extract_options] + end end end end @@ -79,8 +87,10 @@ def action_remove end end - def consul_binary - ::File.join(options[:extract_to], new_resource.version, 'consul') + def consul_program + @program ||= ::File.join(options[:extract_to], new_resource.version, 'consul') + return @program unless node.platform?('windows') + @program + '.exe' end def self.default_archive_url diff --git a/libraries/consul_installation_git.rb b/libraries/consul_installation_git.rb index 4a00dd4e..95eb805c 100644 --- a/libraries/consul_installation_git.rb +++ b/libraries/consul_installation_git.rb @@ -21,7 +21,7 @@ module Provider class ConsulInstallationGit < Chef::Provider include Poise(inversion: :consul_installation) provides(:git) - inversion_attribute 'consul' + inversion_attribute('consul') # Set the default inversion options. # @return [Hash] @@ -63,7 +63,7 @@ def action_remove end end - def consul_binary + def consul_program ::File.join(options[:git_path], 'bin', 'consul') end end diff --git a/libraries/consul_installation_package.rb b/libraries/consul_installation_package.rb index 881c5a20..d27bd868 100644 --- a/libraries/consul_installation_package.rb +++ b/libraries/consul_installation_package.rb @@ -55,8 +55,8 @@ def action_remove end end - def consul_binary - options.fetch(:consul_binary, '/usr/local/bin/consul') + def consul_program + options.fetch(:consul_program, '/usr/local/bin/consul') end end end diff --git a/libraries/consul_installation_webui.rb b/libraries/consul_installation_webui.rb index 52056fba..c6a47cbc 100644 --- a/libraries/consul_installation_webui.rb +++ b/libraries/consul_installation_webui.rb @@ -21,7 +21,7 @@ module Provider class ConsulInstallationWebui < Chef::Provider include Poise(inversion: :consul_installation) provides(:webui) - inversion_attribute 'consul' + inversion_attribute('consul') # Set the default inversion options. # @return [Hash] @@ -76,7 +76,7 @@ def action_remove end end - def consul_binary + def consul_program ::File.join(options[:extract_to], new_resource.version, 'consul') end diff --git a/libraries/consul_service.rb b/libraries/consul_service.rb index 7b2b6ae9..dc9aad28 100644 --- a/libraries/consul_service.rb +++ b/libraries/consul_service.rb @@ -45,7 +45,7 @@ class ConsulService < Chef::Resource # @!attribute consul_binary # The location of the Consul executable. # @return [String] - attribute(:consul_binary, kind_of: String, default: '/usr/local/bin/consul') + attribute(:program, kind_of: String, default: '/usr/local/bin/consul') def command "#{consul_binary} agent -config-file=#{config_file} -config-dir=#{config_dir}" diff --git a/libraries/consul_service_windows.rb b/libraries/consul_service_windows.rb index 1b646574..31d17dd6 100644 --- a/libraries/consul_service_windows.rb +++ b/libraries/consul_service_windows.rb @@ -19,44 +19,25 @@ class ConsulServiceWindows < Chef::Provider def action_enable notifying_block do - case new_resource.install_method - when 'binary' - windows_zipfile "consul-#{new_resource.version}" do - action :unzip - path new_resource.install_path - source new_resource.binary_url % { version: new_resource.version, filename: new_resource.binary_filename('binary') } - not_if { correct_version?(join_path(new_resource.install_path, 'consul.exe'), new_resource.version) } - end - else - Chef::Application.fatal!('The Consul Service provider for Windows only supports the binary install_method at this time') - end - directories = %W{#{new_resource.data_dir} #{new_resource.config_dir} #{::File.dirname(new_resource.nssm_params['AppStdout'])} #{::File.dirname(new_resource.nssm_params['AppStderr'])}}.uniq.compact - - # ::File.dirname '' == '.' directories.delete_if { |i| i.eql? '.' }.each do |dirname| directory dirname do recursive true - # owner new_resource.user - # group new_resource.group - # mode '0755' end end nssm 'consul' do action :install - program join_path(new_resource.install_path, 'consul.exe') - # Don't try and set empty parameters + program new_resource.program params new_resource.nssm_params.select { |_k, v| v != '' } args command(new_resource.config_file, new_resource.config_dir) not_if { nssm_service_installed? } end if nssm_service_installed? - # The nssm resource does not check param values after they've been set mismatch_params = check_nssm_params unless mismatch_params.empty? mismatch_params.each do |k, v| diff --git a/recipes/default.rb b/recipes/default.rb index 10896d1d..77793323 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -61,7 +61,7 @@ consul_service service_name do |r| version node['consul']['version'] config_file config.path - consul_binary install.consul_binary + program install.consul_program unless windows? user node['consul']['service_user'] diff --git a/test/integration/acl/serverspec/default_spec.rb b/test/integration/acl/serverspec/default_spec.rb new file mode 100644 index 00000000..319666c8 --- /dev/null +++ b/test/integration/acl/serverspec/default_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe command('curl -s "http://localhost:8500/v1/acl/info/anonymous"') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match('"ID":"anonymous"') } + its(:stdout) { should match('"Name":"Anonymous Token"') } + its(:stdout) { should match('"Type":"client"') } + its(:stdout) { should match('"Rules":""') } +end + +describe file('/tmp/anonymous-notified') do + it { should_not exist } +end + +describe command('curl -s "http://localhost:8500/v1/acl/info/management_token"') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match('[]') } +end + +describe file('/tmp/management_token-notified') do + it { should exist } +end + +describe command('curl -s "http://localhost:8500/v1/acl/info/reader_token"') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match('"ID":"reader_token"') } + its(:stdout) { should match('"Name":""') } + its(:stdout) { should match('"Type":"client"') } + its(:stdout) { should match /\"Rules\":\"dummyrule_line1\\ndummyrule_line2\\n\"/ } +end diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb new file mode 100644 index 00000000..e5818519 --- /dev/null +++ b/test/integration/default/serverspec/default_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe file('/opt/consul/0.6.3/consul') do + it { should be_file } + it { should be_executable } +end + +describe group('consul') do + it { should exist } +end + +describe user('consul') do + it { should exist } + it { should belong_to_group('consul') } + it { should have_login_shell('/bin/bash') } +end + +describe service('consul') do + it { should be_enabled } + it { should be_running } +end + +[8300, 8400, 8500, 8600].each do |p| + describe port(p) do + it { should be_listening } + end +end + +describe command('/opt/consul/0.6.3/consul members -detailed') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match %r{\balive\b} } + its(:stdout) { should match %r{\brole=consul\b} } + its(:stdout) { should match %r{\bbootstrap=1\b} } + its(:stdout) { should match %r{\bdc=fortmeade\b} } +end + +config_file = '/etc/consul/consul.json' +config_dir = '/etc/consul/conf.d' +data_dir = '/var/lib/consul' + +describe file(config_file) do + it { should be_file } + it { should be_owned_by 'consul' } + it { should be_grouped_into 'consul' } + + it { should be_mode 640 } +end + +describe file(config_dir) do + it { should be_directory } + it { should be_owned_by 'consul' } + it { should be_grouped_into 'consul' } + + it { should be_mode 755 } +end + +describe file(data_dir) do + it { should be_directory } + it { should be_owned_by 'consul' } + it { should be_grouped_into 'consul' } + + it { should be_mode 755 } +end diff --git a/test/integration/windefault/serverspec/localhost/logging_spec.rb b/test/integration/windefault/serverspec/localhost/logging_spec.rb deleted file mode 100644 index 203a0045..00000000 --- a/test/integration/windefault/serverspec/localhost/logging_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -context 'logging' do - describe file('C:\foo\bar\out.log') do - it { should be_file } - end - - describe file('C:\foo\bar\err.log') do - it { should be_file } - end -end \ No newline at end of file diff --git a/test/integration/windefault/serverspec/localhost/default_spec.rb b/test/integration/zip/serverspec/default_spec.rb similarity index 75% rename from test/integration/windefault/serverspec/localhost/default_spec.rb rename to test/integration/zip/serverspec/default_spec.rb index 6f76cf45..a5dc125e 100644 --- a/test/integration/windefault/serverspec/localhost/default_spec.rb +++ b/test/integration/zip/serverspec/default_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe file('C:\Program Files\consul\consul.exe') do +describe file('C:\opt\consul\0.6.3\consul.exe') do it { should be_file } end @@ -15,7 +15,7 @@ end end -describe command('& "C:\Program Files\consul\consul.exe" members -detailed') do +describe command('& "C:\opt\consul\0.6.3\consul.exe" members -detailed') do its(:exit_status) { should eq 0 } its(:stdout) { should match %r{\balive\b} } its(:stdout) { should match %r{\brole=consul\b} } @@ -38,3 +38,11 @@ describe file(data_dir) do it { should be_directory } end + +describe file('C:\foo\bar\out.log') do + it { should be_file } +end + +describe file('C:\foo\bar\err.log') do + it { should be_file } +end From b25b15efe763e7f475abd390062b17e1f4d08765 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Wed, 16 Mar 2016 21:26:01 -0400 Subject: [PATCH 16/18] Remove the webui provider in favor of using config. --- .kitchen.yml | 23 ++---- libraries/consul_installation_webui.rb | 104 ------------------------- libraries/consul_service.rb | 4 +- 3 files changed, 8 insertions(+), 123 deletions(-) delete mode 100644 libraries/consul_installation_webui.rb diff --git a/.kitchen.yml b/.kitchen.yml index 71a218bc..87f12c86 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -47,9 +47,12 @@ suites: - recipe[consul::default] attributes: consul: - config: *default-config - installation: - provider: webui + config: + bootstrap: true + server: true + ui: true + datacenter: FortMeade + encrypt: CGXC2NsXW4AvuB4h5ODYzQ== excludes: - windows-2012r2 - name: acl @@ -84,17 +87,3 @@ suites: nssm_params: AppStdout: C:\foo\bar\out.log AppStderr: C:\foo\bar\err.log - # - name: atlas - # excludes: - # - windows-2012r2 - # run_list: - # - recipe[consul::default] - # attributes: - # consul: - # config: - # bootstrap: true - # server: true - # datacenter: fortmeade - # atlas_join: true - # atlas_infrastructure: <%= ENV.fetch('ATLAS_INFRASTRUCTURE', 'example/cluster') %> - # atlas_token: <%= ENV.fetch('ATLAS_TOKEN', 'NOT_REAL') %> diff --git a/libraries/consul_installation_webui.rb b/libraries/consul_installation_webui.rb deleted file mode 100644 index c6a47cbc..00000000 --- a/libraries/consul_installation_webui.rb +++ /dev/null @@ -1,104 +0,0 @@ -# -# Cookbook: consul -# License: Apache 2.0 -# -# Copyright 2014-2016, Bloomberg Finance L.P. -# -require 'poise' - -module ConsulCookbook - module Provider - # A `consul_installation` provider which manages Consul Web UI - # remote installation. - # @action create - # @action remove - # @provides consul_installation - # @example - # consul_installation '0.5.0' do - # provider 'webui' - # end - # @since 2.0 - class ConsulInstallationWebui < Chef::Provider - include Poise(inversion: :consul_installation) - provides(:webui) - inversion_attribute('consul') - - # Set the default inversion options. - # @return [Hash] - # @api private - def self.default_inversion_options(node, resource) - archive_basename = binary_basename(node, resource) - super.merge( - version: resource.version, - archive_url: default_archive_url % { version: resource.version, basename: archive_basename }, - archive_basename: archive_basename, - archive_checksum: binary_checksum(node, resource), - extract_to: '/opt/consul-webui' - ) - end - - def action_create - archive_url = options[:archive_url] % { - version: options[:version], - basename: options[:archive_basename] - } - - notifying_block do - include_recipe 'libarchive::default' - - archive = remote_file options[:archive_basename] do - path ::File.join(Chef::Config[:file_cache_path], name) - source archive_url - checksum options[:archive_checksum] - end - - directory ::File.join(options[:extract_to], new_resource.version) do - recursive true - end - - libarchive_file options[:archive_basename] do - path archive.path - mode options[:extract_mode] - owner options[:extract_owner] - group options[:extract_group] - extract_to ::File.join(options[:extract_to], new_resource.version) - extract_options options[:extract_options] - end - end - end - - def action_remove - notifying_block do - directory ::File.join(options[:extract_to], new_resource.version) do - recursive true - action :delete - end - end - end - - def consul_program - ::File.join(options[:extract_to], new_resource.version, 'consul') - end - - def self.default_archive_url - "https://releases.hashicorp.com/consul/%{version}/%{basename}" # rubocop:disable Style/StringLiterals - end - - def self.binary_basename(node, resource) - ['consul', resource.version, 'web_ui'].join('_').concat('zip') - end - - def self.binary_checksum(node, resource) - case resource.version - when '0.5.0' then '0081d08be9c0b1172939e92af5a7cf9ba4f90e54fae24a353299503b24bb8be9' - when '0.5.1' then 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1' - when '0.5.2' then 'ad883aa52e1c0136ab1492bbcedad1210235f26d59719fb6de3ef6464f1ff3b1' - when '0.6.0' then '73c5e7ee50bb4a2efe56331d330e6d7dbf46335599c028344ccc4031c0c32eb0' - when '0.6.1' then 'afccdd540b166b778c7c0483becc5e282bbbb1ee52335bfe94bf757df8c55efc' - when '0.6.2' then 'f144377b8078df5a3f05918d167a52123089fc47b12fc978e6fb375ae93afc90' - when '0.6.3' then '93bbb300cacfe8de90fb3bd5ede7d37ae6ce014898edc520b9c96a676b2bbb72' - end - end - end - end -end diff --git a/libraries/consul_service.rb b/libraries/consul_service.rb index dc9aad28..38766b63 100644 --- a/libraries/consul_service.rb +++ b/libraries/consul_service.rb @@ -42,13 +42,13 @@ class ConsulService < Chef::Resource # @!attribute nssm_params # @return [String] attribute(:nssm_params, kind_of: Hash, default: lazy { node['consul']['service']['nssm_params'] }) - # @!attribute consul_binary + # @!attribute program # The location of the Consul executable. # @return [String] attribute(:program, kind_of: String, default: '/usr/local/bin/consul') def command - "#{consul_binary} agent -config-file=#{config_file} -config-dir=#{config_dir}" + "#{program} agent -config-file=#{config_file} -config-dir=#{config_dir}" end def default_environment From 753397b5d055e6981d0f56a7fd45e7310051e09e Mon Sep 17 00:00:00 2001 From: John Bellone Date: Wed, 16 Mar 2016 22:52:28 -0400 Subject: [PATCH 17/18] Add freebsd to the test-kitchen build matrix. --- .kitchen.yml | 38 +++++++++++++++----------------------- Berksfile | 3 +++ 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 87f12c86..c2182dc6 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -7,17 +7,30 @@ provisioner: platforms: - name: ubuntu-14.04 + run_list: + - recipe[apt::default] - name: ubuntu-12.04 + run_list: + - recipe[apt::default] - name: centos-7.2 + run_list: + - recipe[yum::default] - name: centos-6.7 + run_list: + - recipe[yum::default] - name: centos-5.11 + run_list: + - recipe[yum::default] + - name: freebsd-10.2 + run_list: + - recipe[freebsd::default] - name: windows-2012r2 + run_list: + - recipe[windows::default] suites: - name: default run_list: - - recipe[apt::default] - - recipe[yum::default] - recipe[consul::default] attributes: consul: @@ -26,12 +39,8 @@ suites: server: true datacenter: FortMeade encrypt: CGXC2NsXW4AvuB4h5ODYzQ== - excludes: - - windows-2012r2 - name: git run_list: - - recipe[apt::default] - - recipe[yum::default] - recipe[consul::default] attributes: consul: @@ -42,8 +51,6 @@ suites: - windows-2012r2 - name: webui run_list: - - recipe[apt::default] - - recipe[yum::default] - recipe[consul::default] attributes: consul: @@ -53,8 +60,6 @@ suites: ui: true datacenter: FortMeade encrypt: CGXC2NsXW4AvuB4h5ODYzQ== - excludes: - - windows-2012r2 - name: acl run_list: - recipe[consul::default] @@ -74,16 +79,3 @@ suites: - centos-7.2 - centos-6.7 - centos-5.11 - - name: zip - includes: - - windows-2012r2 - run_list: - - recipe[consul::default] - attributes: - consul: - service_user: vagrant - config: *default-config - service: - nssm_params: - AppStdout: C:\foo\bar\out.log - AppStderr: C:\foo\bar\err.log diff --git a/Berksfile b/Berksfile index eba2a958..d051b0ec 100644 --- a/Berksfile +++ b/Berksfile @@ -4,4 +4,7 @@ metadata group :test, :integration do cookbook 'consul_spec', path: 'test/cookbooks/consul_spec' cookbook 'apt' + cookbook 'freebsd' + cookbook 'windows' + cookbook 'yum' end From 28c19e761031274803981bb5b32d86c9a89a8355 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Thu, 17 Mar 2016 00:11:14 -0400 Subject: [PATCH 18/18] Update cookbook to use zipfile resource. --- libraries/consul_installation_binary.rb | 24 +++--------------------- metadata.rb | 2 +- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/libraries/consul_installation_binary.rb b/libraries/consul_installation_binary.rb index f2b9ed09..c41a3ca5 100644 --- a/libraries/consul_installation_binary.rb +++ b/libraries/consul_installation_binary.rb @@ -47,34 +47,16 @@ def action_create } notifying_block do - archive = remote_file options[:archive_basename] do - path ::File.join(Chef::Config[:file_cache_path], name) - source archive_url - checksum options[:archive_checksum] - end - directory ::File.join(options[:extract_to], new_resource.version) do recursive true end - windows_zipfile options[:archive_basename] do + zipfile options[:archive_basename] do path ::File.join(options[:extract_to], new_resource.version) - source archive.path - only_if { node.platform?('windows') } + source archive_url + checksum options[:archive_checksum] not_if { ::File.exist?(consul_program) } end - - unless node.platform?('windows') - include_recipe 'libarchive::default' - libarchive_file options[:archive_basename] do - path archive.path - mode options[:extract_mode] - owner options[:extract_owner] - group options[:extract_group] - extract_to ::File.join(options[:extract_to], new_resource.version) - extract_options options[:extract_options] - end - end end end diff --git a/metadata.rb b/metadata.rb index a7a2bc07..f3df939c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -24,9 +24,9 @@ depends 'nssm' depends 'golang' depends 'firewall', '~> 2.0' -depends 'libartifact', '~> 1.3' depends 'poise', '~> 2.2' depends 'poise-service', '~> 1.0' +depends 'rubyzip', '~> 1.0' depends 'yum-epel' source_url 'https://github.com/johnbellone/consul-cookbook' if respond_to?(:source_url)