From 5faf2a05c82e04548313a821272ea603a249e432 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 7 Nov 2016 14:12:14 -0800 Subject: [PATCH 1/8] Move tar/7zip path logic out of attributes and into helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents failures on Windows when 7zip doesn’t exist at the beginning of the run Signed-off-by: Tim Smith --- .kitchen.yml | 6 ++ README.md | 57 +++++++++++++++---- attributes/default.rb | 17 ++---- libraries/sevenzip_command_builder.rb | 4 +- libraries/tar_command_builder.rb | 15 +++-- .../cookbooks/ark_spec/recipes/cherry_pick.rb | 2 +- .../cookbooks/ark_spec/recipes/default.rb | 16 +++--- .../cookbooks/ark_spec/recipes/dump.rb | 2 +- .../cookbooks/ark_spec/recipes/install.rb | 2 +- .../ark_spec/recipes/install_windows.rb | 2 +- .../ark_spec/recipes/install_with_binaries.rb | 2 +- .../cookbooks/ark_spec/recipes/put.rb | 2 +- .../cookbooks/ark_spec/recipes/unzip.rb | 2 +- 13 files changed, 87 insertions(+), 42 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 6c925141..8f761fa7 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -21,6 +21,12 @@ platforms: - name: ubuntu-12.04 - name: ubuntu-14.04 - name: ubuntu-16.04 + - name: windows-2008r2 + driver: + box: chef/windows-server-2008r2-standard # private box + - name: windows-2012r2 + driver: + box: chef/windows-server-2012r2-standard # private box suites: - name: default diff --git a/README.md b/README.md index a966df8e..0383fa89 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # ark cookbook + [![Build Status](https://travis-ci.org/chef-cookbooks/ark.svg?branch=master)](https://travis-ci.org/chef-cookbooks/ark) [![Cookbook Version](https://img.shields.io/cookbook/v/ark.svg)](https://supermarket.chef.io/cookbooks/ark) ## Overview + This cookbook provides `ark`, a resource for managing software archives. It manages the fetch-unpack-configure-build-install process common to installing software from source, or from binary distributions that are not fully fledged OS packages. This cookbook started its life as a modified version of Infochimp's install_from cookbook. It has since been heavily refactored and extended to meet different use cases. @@ -15,8 +17,9 @@ end ``` The provider will: + - fetch it to to `/var/cache/chef/` -- unpack it to the default path (`/usr/local/pig-0.8.0`) +- unpack it to the default path (`/usr/local/pig-0.8.0`) - create a symlink for `:home_dir` (`/usr/local/pig`) pointing to path - add specified binary commands to the environment `PATH` variable @@ -25,7 +28,9 @@ By default, the ark will not run again if the `:path` is not empty. Ark provides At this time ark only handles files available from URLs using the [remote_file](http://docs.chef.io/resource_remote_file.html) provider. It does handle local files using the `file://` protocol. ## Requirements + ### Platforms + - Debian/Ubuntu - RHEL/CentOS/Scientific/Oracle - Fedora @@ -33,30 +38,38 @@ At this time ark only handles files available from URLs using the [remote_file]( - SmartOS - Mac OS X - openSUSE / SUSE Linux Enterprises +- Windows Should work on common Unix/Linux systems with typical userland utilities like tar, gzip, etc. May require the installation of build tools for compiling from source, but that installation is outside the scope of this cookbook. ### Chef + - Chef 12.1+ ### Cookbooks + - build-essential - seven_zip - windows ## Attributes + Customize the attributes to suit site specific conventions and defaults. -- `node['ark']['apache_mirror']` - if the URL is an apache mirror, use the attribute as the default. -- `node['ark']['prefix_root']` - default base location if the `prefix_root` is not passed into the resource. -- `node['ark']['prefix_bin']` - default binary location if the `prefix_bin` is not passed into the resource. -- `node['ark']['prefix_home']` - default home location if the `prefix_home` is not passed into the resource. -- `node['ark']['win_install_dir']` - directory where the files will be put on windows -- `node['ark']['package_dependencies']` - prerequisite system packages that need to be installed to support ark. + +- `node['ark']['apache_mirror']` - if the URL is an apache mirror, use the attribute as the default. default: `http://apache.mirrors.tds.net` +- `node['ark']['prefix_root']` - default base location if the `prefix_root` is not passed into the resource. default: `/usr/local` +- `node['ark']['prefix_bin']` - default binary location if the `prefix_bin` is not passed into the resource. default: `/usr/local/bin` +- `node['ark']['prefix_home']` - default home location if the `prefix_home` is not passed into the resource. default: `/usr/local` +- `node['ark']['package_dependencies']` - prerequisite system packages that need to be installed to support ark. default: varies based on platform +- `node['ark']['tar']` - allows overriding the default path to the tar binary, which varies based on platform +- `node['ark']['sevenzip_binary']` - allows overriding the default path to the 7zip binary, which is determined based on registry key value ## Resources + - `ark` - does the extract/build/configure dance ### Actions + - `:install`: extracts the file and creates a 'friendly' symbolic link to the extracted directory path - `:configure`: configure ahead of the install action - `:install_with_make`: extracts the archive to a path, runs `make`, and `make install`. @@ -69,34 +82,43 @@ Customize the attributes to suit site specific conventions and defaults. - `:setup_py_install`: runs the command "python setup.py install" in the extracted directory ### :cherry_pick + Extract a specified file from an archive and places in specified path. #### Relevant Attribute Parameters for :cherry_pick + - `path`: directory to place file in. - `creates`: specific file to cherry-pick. ### :dump + Strips all directories from the archive and dumps the contained files into a specified path. NOTE: This currently only works for zip archives #### Attribute Parameters for :dump + - `path`: path to dump files to. - `mode`: file mode for `app_home`, as an integer. + - Example: `0775` - `creates`: if you are appending files to a given directory, ark needs a condition to test whether the file has already been extracted. You can specify with creates, a file whose existence indicates the ark has previously been extracted and does not need to be extracted again. ### :put + Extract the archive to a specified path, does not create any symbolic links. #### Attribute Parameters for :put + - `path`: path to extract to. + - Default: `/usr/local` - `append_env_path`: boolean, if true, append the `./bin` directory of the extracted directory to the global `PATH` variable for all users. ### Attribute Parameters + - `name`: name of the package, defaults to the resource name. - `url`: url for tarball, `.tar.gz`, `.bin` (oracle-specific), `.war`, and `.zip` currently supported. Also supports special syntax - `:name:version:apache_mirror:` that will auto-magically construct download url from the apache mirrors site. @@ -104,39 +126,51 @@ Extract the archive to a specified path, does not create any symbolic links. - `mode`: file mode for `app_home`, is an integer. - `prefix_root`: default `prefix_root`, for use with `:install*` actions. - `prefix_home`: default directory prefix for a friendly symlink to the path. + - Example: `/usr/local/maven` -> `/usr/local/maven-2.2.1` - `prefix_bin`: default directory to place a symlink to a binary command. + - Example: `/opt/bin/mvn` -> `/opt/maven-2.2.1/bin/mvn`, where the `prefix_bin` is `/opt/bin` - `path`: path to extract the ark to. The `:install*` actions overwrite any user-provided values for `:path`. + - Default: `/usr/local/-` for the `:install`, `:install_with_make` actions - `home_dir`: symbolic link to the path `:prefix_root/:name-:version`, does not apply to `:dump`, `:put`, or `:cherry_pick` actions. + - Default: `:prefix_root/:name` - `has_binaries`: array of binary commands to symlink into `/usr/local/bin/`, you must specify the relative path. + - Example: `[ 'bin/java', 'bin/javaws' ]` - `append_env_path`: boolean, similar to `has_binaries` but less granular. If true, append the `./bin` directory of the extracted directory to. the `PATH` environment variable for all users, by placing a file in `/etc/profile.d/`. The commands are symbolically linked into `/usr/bin/*`. This option provides more granularity than the boolean option. + - Example: `mvn`, `java`, `javac`, etc. - `environment`: hash of environment variables to pass to invoked shell commands like `tar`, `unzip`, `configure`, and `make`. + - `strip_components`: number of components in path to strip when extracting archive. With default value of `1`, ark strips the leading directory from an archive, which is the default for both `unzip` and `tar` commands. + - `autoconf_opts`: an array of command line options for use with the GNU `autoconf` script. + - Example: `[ '--include=/opt/local/include', '--force' ]` - `make_opts`: an array of command line options for use with `make`. + - Example: `[ '--warn-undefined-variables', '--load-average=2' ]` - `owner`: owner of extracted directory. + - Default: `root` - `backup`: The number of backups to be kept in /var/chef/backup (for UNIX- and Linux-based platforms) or C:/chef/backup (for the Microsoft Windows platform). Set to false to prevent backups from being kept. - - Default: `5` + - Default: `5` #### Examples + This example copies `ivy.tar.gz` to `/var/cache/chef/ivy-2.2.0.tar.gz`, unpacks its contents to `/usr/local/ivy-2.2.0/` -- stripping the leading directory, and symlinks `/usr/local/ivy` to `/usr/local/ivy-2.2.0` ```ruby @@ -163,7 +197,7 @@ This example copies `jdk-7u2-linux-x64.tar.gz` to `/var/cache/chef/jdk-7.2.tar.g end ``` -Install Apache Ivy dependency resolution tool in /resource_name in this case `/usr/local/ivy`, do not symlink, and strip any leading directory if one exists in the tarball: +Install Apache Ivy dependency resolution tool in `/resource_name` in this case `/usr/local/ivy`, do not symlink, and strip any leading directory if one exists in the tarball: ```ruby ark "ivy" do @@ -173,7 +207,7 @@ Install Apache Ivy dependency resolution tool in /resource_name in this ca end ``` -Install Apache Ivy dependency resolution tool in /home/foobar/ivy, strip any leading directory if one exists, don't keep backup copies of ivy.tar.gz: +Install Apache Ivy dependency resolution tool in `/home/foobar/ivy`, strip any leading directory if one exists, don't keep backup copies of `ivy.tar.gz`: ```ruby ark "ivy" do @@ -185,7 +219,7 @@ Install Apache Ivy dependency resolution tool in /home/foobar/ivy, strip any lea end ``` - Strip all directories and dump files into path specified by the path attribute. You must specify the `creates` attribute in order to keep the extraction from running every time. The directory path will be created if it doesn't already exist: +Strip all directories and dump files into path specified by the path attribute. You must specify the `creates` attribute in order to keep the extraction from running every time. The directory path will be created if it doesn't already exist: ```ruby ark "my_jars" do @@ -234,6 +268,7 @@ You can also pass multiple actions to ark and supply the file extension in case ``` ## License & Authors + - Author: Philip (flip) Kromer - Infochimps, Inc([coders@infochimps.com](mailto:coders@infochimps.com)) - Author: Bryan W. Berry ([bryan.berry@gmail.com](mailto:bryan.berry@gmail.com)) - Author: Denis Barishev ([denis.barishev@gmail.com](mailto:denis.barishev@gmail.com)) diff --git a/attributes/default.rb b/attributes/default.rb index 945e1d96..0f44dbd1 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -20,17 +20,12 @@ default['ark']['prefix_root'] = '/usr/local' default['ark']['prefix_bin'] = '/usr/local/bin' default['ark']['prefix_home'] = '/usr/local' -default['ark']['tar'] = case node['platform_family'] - when 'windows' - "\"#{::Win32::Registry::HKEY_LOCAL_MACHINE.open( - 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe', ::Win32::Registry::KEY_READ).read_s('Path')}\\7z.exe\"" - when 'mac_os_x', 'freebsd' - '/usr/bin/tar' - when 'smartos' - '/bin/gtar' - else - '/bin/tar' - end + +# the default path will be determined based on platform, but can be overridden here +default['ark']['tar'] = nil + +# the default path will be determined from the registry, but you may override here +default['ark']['sevenzip_binary'] = nil pkgs = %w(libtool autoconf) unless platform_family?('mac_os_x') pkgs += %w(make) unless platform_family?('mac_os_x', 'freebsd') diff --git a/libraries/sevenzip_command_builder.rb b/libraries/sevenzip_command_builder.rb index 48e62952..b2c224a6 100644 --- a/libraries/sevenzip_command_builder.rb +++ b/libraries/sevenzip_command_builder.rb @@ -40,7 +40,9 @@ def sevenzip_command end def sevenzip_binary - resource.run_context.node['ark']['tar'] + @tar_binary ||= node['ark']['sevenzip_binary'] || + "\"#{::Win32::Registry::HKEY_LOCAL_MACHINE.open( + 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe', ::Win32::Registry::KEY_READ).read_s('Path')}\\7z.exe\"" end def sevenzip_command_builder(dir, command) diff --git a/libraries/tar_command_builder.rb b/libraries/tar_command_builder.rb index 00ed522c..0207eeaa 100644 --- a/libraries/tar_command_builder.rb +++ b/libraries/tar_command_builder.rb @@ -18,16 +18,23 @@ def initialize(resource) private + def tar_binary + @tar_binary ||= node['ark']['tar'] || case node['platform_family'] + when 'mac_os_x', 'freebsd' + '/usr/bin/tar' + when 'smartos' + '/bin/gtar' + else + '/bin/tar' + end + end + attr_reader :resource def node resource.run_context.node end - def tar_binary - resource.run_context.node['ark']['tar'] - end - def args case resource.extension when /^(tar)$/ then 'xf' diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb b/spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb index 9b960f6f..95eba8f1 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb @@ -4,7 +4,7 @@ checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' path '/usr/local/foo_cherry_pick' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' creates 'foo_sub/foo1.txt' action :cherry_pick end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/default.rb b/spec/fixtures/cookbooks/ark_spec/recipes/default.rb index 75c8f474..b02c96d9 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/default.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/default.rb @@ -1,4 +1,4 @@ -apt_update 'update' +apt_update 'update' if platform_family?('debian') include_recipe 'ark' @@ -12,10 +12,10 @@ action :nothing end -group 'foobarbaz' +group 'foobarbaz_group' user 'foobarbaz' do - group 'foobarbaz' + group 'foobarbaz_group' end directory '/opt/bin' do @@ -28,7 +28,7 @@ version '2' prefix_root '/usr/local' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' has_binaries ['bin/do_foo', 'bin/do_more_foo'] action :install end @@ -37,7 +37,7 @@ url 'https://github.com/burtlo/ark/raw/master/files/default/foo.tar.gz' checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' action :put end @@ -47,7 +47,7 @@ path '/usr/local/foo_dump' creates 'foo1.txt' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' action :dump end @@ -56,7 +56,7 @@ checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' path '/usr/local/foo_cherry_pick' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' creates 'foo_sub/foo1.txt' action :cherry_pick end @@ -108,7 +108,7 @@ prefix_home '/opt' prefix_bin '/opt/bin' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' has_binaries ['bin/do_foo'] action :install end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/dump.rb b/spec/fixtures/cookbooks/ark_spec/recipes/dump.rb index c67b95b9..e6fbc2c3 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/dump.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/dump.rb @@ -5,6 +5,6 @@ path '/usr/local/foo_dump' creates 'foo1.txt' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' action :dump end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/install.rb b/spec/fixtures/cookbooks/ark_spec/recipes/install.rb index 37ca9b41..06c89b63 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/install.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/install.rb @@ -5,6 +5,6 @@ version '2' prefix_root '/usr/local' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' action :install end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb b/spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb index ee0a0546..d0cd318c 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb @@ -6,7 +6,7 @@ prefix_root 'C:\\' win_install_dir 'C:\\install' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' # has_binaries %w( bin\do_foo bin\do_more_foo ) action :install end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb b/spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb index c21d4a2b..3b74b69a 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb @@ -5,7 +5,7 @@ version '2' prefix_root '/usr/local' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' has_binaries ['bin/do_foo', 'bin/do_more_foo'] action :install end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/put.rb b/spec/fixtures/cookbooks/ark_spec/recipes/put.rb index 839d166c..904fc2c0 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/put.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/put.rb @@ -3,6 +3,6 @@ url 'https://github.com/burtlo/ark/raw/master/files/default/foo.tar.gz' checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' action :put end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb b/spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb index a55580a9..0f00a31a 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb @@ -5,6 +5,6 @@ path '/usr/local/foo_dump' creates 'foo1.txt' owner 'foobarbaz' - group 'foobarbaz' + group 'foobarbaz_group' action :unzip end From 9af26bafe28c27c6788c526f1c569273fcf97e0a Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 10 Nov 2016 23:29:55 -0800 Subject: [PATCH 2/8] Add windows test recipe and fix node access in the libraries Signed-off-by: Tim Smith --- .kitchen.yml | 15 +++++++++++++++ libraries/sevenzip_command_builder.rb | 2 +- libraries/tar_command_builder.rb | 2 +- .../cookbooks/ark_spec/recipes/cherry_pick.rb | 2 +- .../cookbooks/ark_spec/recipes/dump.rb | 2 +- .../ark_spec/recipes/install_windows.rb | 2 +- .../ark_spec/recipes/install_with_binaries.rb | 2 +- .../fixtures/cookbooks/ark_spec/recipes/put.rb | 2 +- .../cookbooks/ark_spec/recipes/unzip.rb | 2 +- .../cookbooks/ark_spec/recipes/windows.rb | 18 ++++++++++++++++++ 10 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 spec/fixtures/cookbooks/ark_spec/recipes/windows.rb diff --git a/.kitchen.yml b/.kitchen.yml index 8f761fa7..fb319ec9 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -18,6 +18,12 @@ platforms: run_list: yum::dnf_yum_compat - name: opensuse-13.2 - name: opensuse-leap-42.1 + - name: sles-12-sp1 + driver: + box: chef/sles-12-sp1-x86_64 # private box + - name: solaris-11.3 + driver: + box: chef/solaris-11.3 # private box - name: ubuntu-12.04 - name: ubuntu-14.04 - name: ubuntu-16.04 @@ -32,3 +38,12 @@ suites: - name: default run_list: - recipe[ark_spec] + excludes: + - windows-2008r2 + - windows-2012r2 +- name: windows + run_list: + - recipe[ark_spec::windows] + includes: + - windows-2008r2 + - windows-2012r2 diff --git a/libraries/sevenzip_command_builder.rb b/libraries/sevenzip_command_builder.rb index b2c224a6..9d6f3247 100644 --- a/libraries/sevenzip_command_builder.rb +++ b/libraries/sevenzip_command_builder.rb @@ -40,7 +40,7 @@ def sevenzip_command end def sevenzip_binary - @tar_binary ||= node['ark']['sevenzip_binary'] || + @tar_binary ||= resource.run_context.node['ark']['sevenzip_binary'] || "\"#{::Win32::Registry::HKEY_LOCAL_MACHINE.open( 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe', ::Win32::Registry::KEY_READ).read_s('Path')}\\7z.exe\"" end diff --git a/libraries/tar_command_builder.rb b/libraries/tar_command_builder.rb index 0207eeaa..c476587d 100644 --- a/libraries/tar_command_builder.rb +++ b/libraries/tar_command_builder.rb @@ -19,7 +19,7 @@ def initialize(resource) private def tar_binary - @tar_binary ||= node['ark']['tar'] || case node['platform_family'] + @tar_binary ||= resource.run_context.node['ark']['tar'] || case node['platform_family'] when 'mac_os_x', 'freebsd' '/usr/bin/tar' when 'smartos' diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb b/spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb index 95eba8f1..9b960f6f 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/cherry_pick.rb @@ -4,7 +4,7 @@ checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' path '/usr/local/foo_cherry_pick' owner 'foobarbaz' - group 'foobarbaz_group' + group 'foobarbaz' creates 'foo_sub/foo1.txt' action :cherry_pick end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/dump.rb b/spec/fixtures/cookbooks/ark_spec/recipes/dump.rb index e6fbc2c3..c67b95b9 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/dump.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/dump.rb @@ -5,6 +5,6 @@ path '/usr/local/foo_dump' creates 'foo1.txt' owner 'foobarbaz' - group 'foobarbaz_group' + group 'foobarbaz' action :dump end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb b/spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb index d0cd318c..ee0a0546 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/install_windows.rb @@ -6,7 +6,7 @@ prefix_root 'C:\\' win_install_dir 'C:\\install' owner 'foobarbaz' - group 'foobarbaz_group' + group 'foobarbaz' # has_binaries %w( bin\do_foo bin\do_more_foo ) action :install end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb b/spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb index 3b74b69a..c21d4a2b 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/install_with_binaries.rb @@ -5,7 +5,7 @@ version '2' prefix_root '/usr/local' owner 'foobarbaz' - group 'foobarbaz_group' + group 'foobarbaz' has_binaries ['bin/do_foo', 'bin/do_more_foo'] action :install end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/put.rb b/spec/fixtures/cookbooks/ark_spec/recipes/put.rb index 904fc2c0..839d166c 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/put.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/put.rb @@ -3,6 +3,6 @@ url 'https://github.com/burtlo/ark/raw/master/files/default/foo.tar.gz' checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' owner 'foobarbaz' - group 'foobarbaz_group' + group 'foobarbaz' action :put end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb b/spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb index 0f00a31a..a55580a9 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/unzip.rb @@ -5,6 +5,6 @@ path '/usr/local/foo_dump' creates 'foo1.txt' owner 'foobarbaz' - group 'foobarbaz_group' + group 'foobarbaz' action :unzip end diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/windows.rb b/spec/fixtures/cookbooks/ark_spec/recipes/windows.rb new file mode 100644 index 00000000..5cf13ca2 --- /dev/null +++ b/spec/fixtures/cookbooks/ark_spec/recipes/windows.rb @@ -0,0 +1,18 @@ +include_recipe 'ark' + +group 'foobarbaz' + +user 'foobarbaz' do + group 'foobarbaz' +end + +ark 'foo' do + url 'https://github.com/burtlo/ark/raw/master/files/default/foo.tar.gz' + checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8' + version '2' + win_install_dir 'C:\dir' + owner 'foobarbaz' + group 'foobar' + has_binaries ['bin\do_foo', 'bin\do_more_foo'] + action :install +end From d42d5bc6b98485ac3fd7a41130804f9cbc2e43d6 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 14 Nov 2016 21:15:30 -0800 Subject: [PATCH 3/8] Cookstyle fixes Signed-off-by: Tim Smith --- libraries/tar_command_builder.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/tar_command_builder.rb b/libraries/tar_command_builder.rb index c476587d..83311afa 100644 --- a/libraries/tar_command_builder.rb +++ b/libraries/tar_command_builder.rb @@ -20,13 +20,13 @@ def initialize(resource) def tar_binary @tar_binary ||= resource.run_context.node['ark']['tar'] || case node['platform_family'] - when 'mac_os_x', 'freebsd' - '/usr/bin/tar' - when 'smartos' - '/bin/gtar' - else - '/bin/tar' - end + when 'mac_os_x', 'freebsd' + '/usr/bin/tar' + when 'smartos' + '/bin/gtar' + else + '/bin/tar' + end end attr_reader :resource From 175b5f572357ad324a3d896839bdd12bf0874c5a Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 14 Nov 2016 22:05:50 -0800 Subject: [PATCH 4/8] Remove the tar attribute specs Signed-off-by: Tim Smith --- spec/recipes/default_spec.rb | 4 ---- spec/recipes/windows/default_spec.rb | 8 -------- 2 files changed, 12 deletions(-) diff --git a/spec/recipes/default_spec.rb b/spec/recipes/default_spec.rb index 495ab1b8..09a663af 100644 --- a/spec/recipes/default_spec.rb +++ b/spec/recipes/default_spec.rb @@ -29,9 +29,5 @@ it 'prefix home' do expect(default_cookbook_attribute('prefix_home')).to eq '/usr/local' end - - it 'tar binary' do - expect(default_cookbook_attribute('tar')).to eq '/bin/tar' - end end end diff --git a/spec/recipes/windows/default_spec.rb b/spec/recipes/windows/default_spec.rb index 6bdf2608..fe7f6486 100644 --- a/spec/recipes/windows/default_spec.rb +++ b/spec/recipes/windows/default_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe_recipe 'ark::default' do - include_context 'seven zip installed' - def node_attributes { platform: 'windows', version: '2012R2' } end @@ -10,10 +8,4 @@ def node_attributes it 'does include the 7-zip recipe' do expect(chef_run).to include_recipe('seven_zip') end - - context 'sets default attributes' do - it 'tar binary' do - expect(default_cookbook_attribute('tar')).to eq %("C:\\Program Files\\7-Zip\\7z.exe") - end - end end From 95f2a89eabf7e5c49dea486853a19b51da7eb592 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 14 Nov 2016 22:06:01 -0800 Subject: [PATCH 5/8] Fix failing suse package specs Signed-off-by: Tim Smith --- spec/recipes/suse/default_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/recipes/suse/default_spec.rb b/spec/recipes/suse/default_spec.rb index dcf4c5a5..38fb25b6 100644 --- a/spec/recipes/suse/default_spec.rb +++ b/spec/recipes/suse/default_spec.rb @@ -6,6 +6,6 @@ def node_attributes end it 'installs core packages' do - expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc)) + expect(chef_run).to install_package(%w(libtool autoconf make unzip rsync gcc xz bzip2 tar)) end end From 85207cf6827a8f858d41eab0cc621e1ba97f0f8a Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 14 Nov 2016 23:09:51 -0800 Subject: [PATCH 6/8] Fix windows fixture cookbook Signed-off-by: Tim Smith --- spec/fixtures/cookbooks/ark_spec/recipes/windows.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/fixtures/cookbooks/ark_spec/recipes/windows.rb b/spec/fixtures/cookbooks/ark_spec/recipes/windows.rb index 5cf13ca2..ab60bcca 100644 --- a/spec/fixtures/cookbooks/ark_spec/recipes/windows.rb +++ b/spec/fixtures/cookbooks/ark_spec/recipes/windows.rb @@ -1,6 +1,6 @@ include_recipe 'ark' -group 'foobarbaz' +group 'foobar' user 'foobarbaz' do group 'foobarbaz' From 14da869ba87c36c9584fea5287e5092e8b7a32f3 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 14 Nov 2016 23:14:34 -0800 Subject: [PATCH 7/8] Use the Chef DSL for accessing registry keys Signed-off-by: Tim Smith --- libraries/sevenzip_command_builder.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/sevenzip_command_builder.rb b/libraries/sevenzip_command_builder.rb index 9d6f3247..70953b75 100644 --- a/libraries/sevenzip_command_builder.rb +++ b/libraries/sevenzip_command_builder.rb @@ -1,5 +1,7 @@ module Ark class SevenZipCommandBuilder + include Chef::DSL::RegistryHelper # for the registry helper method + def unpack sevenzip_command end @@ -41,8 +43,9 @@ def sevenzip_command def sevenzip_binary @tar_binary ||= resource.run_context.node['ark']['sevenzip_binary'] || - "\"#{::Win32::Registry::HKEY_LOCAL_MACHINE.open( - 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe', ::Win32::Registry::KEY_READ).read_s('Path')}\\7z.exe\"" + if registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path') + "\"#{registry_get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path')}\\7z.exe\"" + end end def sevenzip_command_builder(dir, command) From 3bdfb638b15ddc2620e0f01d7054d9542efad3dc Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 15 Nov 2016 16:03:12 -0800 Subject: [PATCH 8/8] Go back to W32 for the registry and add a helper with better failure messaging Signed-off-by: Tim Smith --- libraries/sevenzip_command_builder.rb | 22 ++++++++++++++++------ libraries/tar_command_builder.rb | 22 +++++++++++----------- spec/libraries/default_spec.rb | 4 +++- spec/spec_helper.rb | 4 ++-- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/libraries/sevenzip_command_builder.rb b/libraries/sevenzip_command_builder.rb index 70953b75..8d8a9934 100644 --- a/libraries/sevenzip_command_builder.rb +++ b/libraries/sevenzip_command_builder.rb @@ -1,7 +1,5 @@ module Ark class SevenZipCommandBuilder - include Chef::DSL::RegistryHelper # for the registry helper method - def unpack sevenzip_command end @@ -22,6 +20,10 @@ def initialize(resource) attr_reader :resource + def node + resource.run_context.node + end + def sevenzip_command if resource.strip_components <= 0 return sevenzip_command_builder(resource.path, 'x') @@ -42,10 +44,18 @@ def sevenzip_command end def sevenzip_binary - @tar_binary ||= resource.run_context.node['ark']['sevenzip_binary'] || - if registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path') - "\"#{registry_get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path')}\\7z.exe\"" - end + @tar_binary ||= (node['ark']['sevenzip_binary'] || sevenzip_path_from_registry) + end + + def sevenzip_path_from_registry + begin + basepath = ::Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe').read_s('Path') + + # users like pretty errors + rescue ::Win32::Registry::Error + raise 'Failed to find the path of 7zip binary by searching checking HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path. Make sure to install 7zip before using this resource. If 7zip is installed and you still receive this message you can also specify the 7zip binary path by setting node["ark"]["sevenzip_binary"]' + end + "#{basepath}7z.exe" end def sevenzip_command_builder(dir, command) diff --git a/libraries/tar_command_builder.rb b/libraries/tar_command_builder.rb index 83311afa..291dbb97 100644 --- a/libraries/tar_command_builder.rb +++ b/libraries/tar_command_builder.rb @@ -18,23 +18,23 @@ def initialize(resource) private - def tar_binary - @tar_binary ||= resource.run_context.node['ark']['tar'] || case node['platform_family'] - when 'mac_os_x', 'freebsd' - '/usr/bin/tar' - when 'smartos' - '/bin/gtar' - else - '/bin/tar' - end - end - attr_reader :resource def node resource.run_context.node end + def tar_binary + @tar_binary ||= node['ark']['tar'] || case node['platform_family'] + when 'mac_os_x', 'freebsd' + '/usr/bin/tar' + when 'smartos' + '/bin/gtar' + else + '/bin/tar' + end + end + def args case resource.extension when /^(tar)$/ then 'xf' diff --git a/spec/libraries/default_spec.rb b/spec/libraries/default_spec.rb index e70dd843..020ced5a 100644 --- a/spec/libraries/default_spec.rb +++ b/spec/libraries/default_spec.rb @@ -121,6 +121,8 @@ end describe '#cherry_pick_command' do + include_context 'seven zip installed' + context "when the node's platform_family is windows" do it 'generates a 7-zip command' do with_node_attributes(platform_family: 'windows') @@ -132,7 +134,7 @@ run_context: double(node: { 'ark' => { 'tar' => 'sevenzip_command' } }) ) - expect(cherry_pick_command).to eq('sevenzip_command e "/resource/release_file" -o"/resource/path" -uy -r /resource/creates') + expect(cherry_pick_command).to eq('C:\\Program Files\\7-Zip7z.exe e "/resource/release_file" -o"/resource/path" -uy -r /resource/creates') end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 855127b4..272855d3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -114,7 +114,7 @@ def recipe_name fake_hkey_local_machine = double('fake_hkey_local_machine') seven_zip_win32_registry = double('seven_zip_registry') allow(seven_zip_win32_registry).to receive(:read_s).with('Path').and_return('C:\\Program Files\\7-Zip') - allow(fake_hkey_local_machine).to receive(:open).with('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe', ::Win32::Registry::KEY_READ).and_return(seven_zip_win32_registry) + allow(fake_hkey_local_machine).to receive(:open).with('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe').and_return(seven_zip_win32_registry) fake_hkey_local_machine end @@ -125,7 +125,7 @@ class Registry end end end - stub_const('::Win32::Registry::KEY_READ', double('win32_registry_key_read')) unless defined? ::Win32::Registry::KEY_READ stub_const('::Win32::Registry::HKEY_LOCAL_MACHINE', fake_hkey_local_machine) + stub_const('::Win32::Registry::Error', double('win32_registry_error')) unless defined? ::Win32::Registry::Error end end