From 47a5efc021fac6e5a6efe6ee45f1fcfcf1ef3681 Mon Sep 17 00:00:00 2001 From: Edgaras Lukosevicius Date: Thu, 13 Apr 2017 18:51:46 +0300 Subject: [PATCH] Update cookbook for Chef 13 --- .gitignore | 1 + .kitchen.yml | 14 ++++++ Berksfile | 2 +- Vagrantfile | 25 ++-------- metadata.rb | 14 +++--- providers/install.rb | 57 +++++++++------------- recipes/default.rb | 2 +- recipes/install.rb | 5 +- resources/install.rb | 3 +- test/integration/default/bats/ioncube.bats | 3 ++ 10 files changed, 58 insertions(+), 68 deletions(-) create mode 100644 .kitchen.yml create mode 100644 test/integration/default/bats/ioncube.bats diff --git a/.gitignore b/.gitignore index 45b891c..88c60bc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ Berksfile.lock .*.sw[a-z] *.un~ /cookbooks +.kitchen # Bundler Gemfile.lock diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..05c20fe --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,14 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + +platforms: + - name: centos-7.3 + +suites: + - name: default + run_list: + - recipe[php-ioncube::install] diff --git a/Berksfile b/Berksfile index c4bb297..34fea21 100644 --- a/Berksfile +++ b/Berksfile @@ -1,3 +1,3 @@ -site :opscode +source 'https://supermarket.chef.io' metadata diff --git a/Vagrantfile b/Vagrantfile index 8eb4c2b..0d1aef5 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,25 +1,21 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -Vagrant.configure("2") do |config| +Vagrant.configure('2') do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. - config.vm.hostname = "php-ioncube-berkshelf" + config.vm.hostname = 'php-ioncube-berkshelf' # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "base" - - # The url from where the 'config.vm.box' box will be fetched if it - # doesn't already exist on the user's system. - config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box" + config.vm.box = 'bento/centos-7.3' # Assign this VM to a host-only network IP, allowing you to access it # via the IP. Host-only networks can talk to the host machine as well as # any other machines on the same network, but cannot be accessed (through this # network interface) by any external networks. - config.vm.network :private_network, ip: "33.33.33.10" + config.vm.network :private_network, ip: '33.33.33.10' # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on @@ -52,9 +48,6 @@ Vagrant.configure("2") do |config| # View the documentation for the provider you're using for more # information on available options. - config.ssh.max_tries = 40 - config.ssh.timeout = 120 - # The path to the Berksfile to use with Vagrant Berkshelf # config.berkshelf.berksfile_path = "./Berksfile" @@ -67,16 +60,8 @@ Vagrant.configure("2") do |config| # config.berkshelf.except = [] config.vm.provision :chef_solo do |chef| - chef.json = { - :mysql => { - :server_root_password => 'rootpass', - :server_debian_password => 'debpass', - :server_repl_password => 'replpass' - } - } - chef.run_list = [ - "recipe[php-ioncube::default]" + 'recipe[php-ioncube::install]' ] end end diff --git a/metadata.rb b/metadata.rb index 6a1f554..18b1464 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,9 +1,9 @@ -name "php-ioncube" -maintainer "Andriy Samilyak" -maintainer_email "samilyak@gmail.com" -license "All rights reserved" -description "Installs/Configures php-ioncube" +name 'php-ioncube' +maintainer 'Andriy Samilyak' +maintainer_email 'samilyak@gmail.com' +license 'All rights reserved' +description 'Installs/Configures php-ioncube' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.2.0" +version '0.2.2' -depends "php" +depends 'php' diff --git a/providers/install.rb b/providers/install.rb index ac13986..4d4dda2 100644 --- a/providers/install.rb +++ b/providers/install.rb @@ -1,29 +1,25 @@ -use_inline_resources if defined?(use_inline_resources) - action :install do + arch_string = case node['kernel']['machine'] + when 'x86_64' + 'x86-64' + when /i[36]86/ + 'x86' + else + node['kernel']['machine'] + end - case run_context.node[:kernel][:machine] - when 'x86_64' - arch_string = 'x86-64' - when /i[36]86/ - arch_string = 'x86' - else - arch_string = run_context.node[:kernel][:machine] - end - - Chef::Log.debug("case selected #{arch_string}") + Chef::Log.debug("Selected #{arch_string} arch") remote_file "/usr/local/src/ioncube_loaders_lin_#{arch_string}.tar.gz" do source "http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_lin_#{arch_string}.tar.gz" - mode "0644" action :create_if_missing - notifies :run, "script[extract_ioncube_php]", :immediately + notifies :run, 'script[Extract_ioncube_php]', :immediately end - script "extract_ioncube_php" do - interpreter "bash" - user "root" - cwd "/usr/local/src/" + script 'Extract_ioncube_php' do + interpreter 'bash' + user 'root' + cwd '/usr/local/src/' action :nothing code <<-EOH tar xvfz /usr/local/src/ioncube_loaders_lin_#{arch_string}.tar.gz @@ -31,29 +27,24 @@ EOH end - ruby_block "determine php version" do + ruby_block 'Determine php version' do block do - php_version_output = `php --version` + php_version_output = shell_out!('php --version').stdout php_version = php_version_output.match(/PHP ([0-9]+\.[0-9]+)\.[0-9]+/)[1] - Chef::Log.info("detected PHP version #{php_version}") - ioncube_file_resource = run_context.resource_collection.find(:file => "#{run_context.node[:php][:ext_conf_dir]}/ioncube.ini") + Chef::Log.info("Detected PHP version #{php_version}") + ioncube_file_resource = resource_collection.find(file: "#{node['php']['ext_conf_dir']}/ioncube.ini") ioncube_file_resource.content "; priority=00\nzend_extension=/usr/local/ioncube/ioncube_loader_lin_" + php_version + ".so\n" end - only_if { run_context.node[:php_ioncube][:version] == '' } + only_if { node['php_ioncube']['version'] == '' } end - file "#{run_context.node[:php][:ext_conf_dir]}/ioncube.ini" do - content "; priority=00\nzend_extension=/usr/local/ioncube/ioncube_loader_lin_" + run_context.node[:php_ioncube][:version] + ".so\n" # dynamically defined during convergence in above ruby_block - owner "root" - group "root" - mode "0644" - action :create + file "#{node['php']['ext_conf_dir']}/ioncube.ini" do + content "; priority=00\nzend_extension=/usr/local/ioncube/ioncube_loader_lin_" + node['php_ioncube']['version'] + ".so\n" end if new_resource.updated_by_last_action? - Chef::Log.info("new_resource.updated_by_last_action is true") + Chef::Log.info('new_resource.updated_by_last_action is true') else - Chef::Log.info("new_resource.updated_by_last_action is false") + Chef::Log.info('new_resource.updated_by_last_action is false') end - -end \ No newline at end of file +end diff --git a/recipes/default.rb b/recipes/default.rb index c6b744e..37a7834 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1 +1 @@ -include_recipe "php" +include_recipe 'php' diff --git a/recipes/install.rb b/recipes/install.rb index 0a4db14..2bd559b 100644 --- a/recipes/install.rb +++ b/recipes/install.rb @@ -1,5 +1,2 @@ include_recipe 'php-ioncube::default' - -php_ioncube_install "ioncube" do - action :install -end +php_ioncube_install 'ioncube' diff --git a/resources/install.rb b/resources/install.rb index a7f608b..8019c2a 100644 --- a/resources/install.rb +++ b/resources/install.rb @@ -1,7 +1,6 @@ actions :install -attribute :name, :kind_of => String, :default => 'phpioncube', :name_attribute => true -attribute :arch, :kind_of => String, :default => node[:kernel][:machine] +property :arch, String, default: node['kernel']['machine'] def initialize(*args) super diff --git a/test/integration/default/bats/ioncube.bats b/test/integration/default/bats/ioncube.bats new file mode 100644 index 0000000..b3aacf4 --- /dev/null +++ b/test/integration/default/bats/ioncube.bats @@ -0,0 +1,3 @@ +@test "Check if ionCube Loader is loaded" { + php -m | grep -E '^ionCube Loader' +}