Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

135
cookbooks/ark/CHANGELOG.md Normal file
View File

@@ -0,0 +1,135 @@
ark Cookbook CHANGELOG
======================
This file is used to list changes made in each version of the ark cookbook.
v0.9.0 (2014-06-06)
-------------------
* [COOK-3642] Add Windows support
v0.8.2 (2014-04-23)
-------------------
- [COOK-4514] - Support for SLES with the Ark cookbook
v0.8.0 (2014-04-10)
-------------------
- [COOK-2771] - Add support for XZ compression
v0.7.2 (2014-03-28)
-------------------
- [COOK-4477] - Fix failing test suite
- [COOK-4484] - Replace strip_leading_dir attribute with more general strip_components
v0.7.0 (2014-03-18)
-------------------
- [COOK-4437] - configure and install_with_make should chown after unpack
v0.6.0 (2014-02-27)
-------------------
[COOK-3786] - Unable to install multiple versions of archive without duplication
v0.5.0 (2014-02-21)
-------------------
### Bug
- **[COOK-4288](https://tickets.opscode.com/browse/COOK-4288)** - Cleanup the Kitchen
### Improvement
- **[COOK-4264](https://tickets.opscode.com/browse/COOK-4264)** - Add node['ark']['package_dependencies'] to allow tuning packages.
v0.4.2
------
### Improvement
- **[COOK-3854](https://tickets.opscode.com/browse/COOK-3854)** - Capability with mac_os_x: '/bin/chown' - No such file or directory
- Cleaning up some style for rubucop
- Updating test harness
v0.4.0
------
### Improvement
- **[COOK-3539](https://tickets.opscode.com/browse/COOK-3539)** - Allow dumping of bz2 and gzip files
v0.3.2
------
### Bug
- **[COOK-3191](https://tickets.opscode.com/browse/COOK-3191)** - Propogate unzip failures
- **[COOK-3118](https://tickets.opscode.com/browse/COOK-3118)** - Set cookbook attribute in provider
- **[COOK-3055](https://tickets.opscode.com/browse/COOK-3055)** - Use proper scope in helper module
- **[COOK-3054](https://tickets.opscode.com/browse/COOK-3054)** - Fix notification resource updating
### Improvement
- **[COOK-3179](https://tickets.opscode.com/browse/COOK-3179)** - README updates and refactor
v0.3.0
------
### Improvement
- [COOK-3087]: Can't use ark with chef < 11
### Bug
- [COOK-3064]: `only_if` statements in ark's `install_with_make` and configure actions are not testing for file existence correctly.
- [COOK-3067]: ark kitchen test for `cherry_pick` is expecting the binary to be in the same parent folder as in the archive.
v0.2.4
------
### Bug
- [COOK-3048]: Ark provider contains a `ruby_block` resource without a block attribute
- [COOK-3063]: Ark cookbook `cherry_pick` action's unzip command does not close if statement
- [COOK-3065]: Ark install action does not symlink binaries correctly
v0.2.2
------
- Update the README to reflect the requirement for Chef 11 to use the ark resource (`use_inline_resources`).
- Making this a release so it will also appear on the community site page.
v0.2.0
------
### Bug
- [COOK-2772]: Ark cookbook has foodcritic failures in provides/default.rb
### Improvement
- [COOK-2520]: Refactor ark providers to use the '`use_inline_resources`' LWRP DSL feature
v0.1.0
------
- [COOK-2335] - ark resource broken on Chef 11
v0.0.1
------
- [COOK-2026] - Allow `cherry_pick` action to be used for directories as well as files
v0.0.1
------
- [COOK-1593] - README formatting updates for better display on Community Site
v0.0.1
------
### Bug
- dangling "unless"
### Improvement
- add `setup_py_*` actions
- add vagrantfile
- add foodcritic test
- travis.ci support
v0.0.10 (May 23, 2012
------
### Bug
- `strip_leading_dir` not working for zip files https://github.com/bryanwb/chef-ark/issues/19
### Improvement
- use autogen.sh to generate configure script for configure action https://github.com/bryanwb/chef-ark/issues/16
- support more file extensions https://github.com/bryanwb/chef-ark/pull/18
- add extension attribute which allows you to download files which do not have the file extension as part of the URL

305
cookbooks/ark/README.md Normal file
View File

@@ -0,0 +1,305 @@
# <a name="title"></a> chef-ark [![Build Status](https://secure.travis-ci.org/opscode-cookbooks/ark.png?branch=master)](https://travis-ci.org/opscode-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 is a modified verion of Infochimp's awesome
[install_from cookbook](http://github.com/infochimps-cookbooks/install_from).
It has been heavily refactored and extended to meet different use
cases.
Given a simple project archive available at a url:
ark 'pig' do
url 'http://apache.org/pig/pig-0.8.0.tar.gz'
end
The provider will:
* fetch it to to `/var/cache/chef/`
* 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 enviroment `PATH` variable
By default, the ark will not run again if the `:path` is not empty.
Ark provides many actions to accommodate different use cases, such as
`:dump`, `:cherry_pick`, `:put`, and `:install_with_make`.
At this time ark only handles files available from URLs. It does not
handle local files.
Requirements
============
This cookbook requires Chef 11 for the provider, as it uses the
`use_inline_resources` method.
More about
[use_inline_resources](http://docs.opscode.com/lwrp_common_inline_compile.html)
in the Chef documentation.
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.
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.
Resources/Providers
===================
* `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`. It does _not_ run the configure step at this
time
- `:dump`: strips all directories from the archive and dumps the
contained files into a specified path
- `:cherry_pick`: extract a specified file from an archive and places
in specified path
- `:put`: extract the archive to a specified path, does not create any
symbolic links
- `:remove`: removes the extracted directory and related symlink #TODO
- `:setup_py_build`: runs the command "python setup.py build" in the
extracted directory
- `:setup_py_install`: runs the comand "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`
- `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, 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.
- `version`: software version, defaults to `1`.
- `checksum`: sha256 checksum, used for security .
- `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/<name>-<version>` 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`
### 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`
# install Apache Ivy dependency resolution tool
ark "ivy" do
url 'http://someurl.example.com/ivy.tar.gz'
version '2.2.0'
checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'
action :install
end
This example copies `jdk-7u2-linux-x64.tar.gz` to
`/var/cache/chef/jdk-7.2.tar.gz`, unpacks its contents to
`/usr/local/jvm/jdk-7.2/` -- stripping the leading directory, symlinks
`/usr/local/jvm/default` to `/usr/local/jvm/jdk-7.2`, and adds
`/usr/local/jvm/jdk-7.2/bin/` to the global `PATH` for all users. The
user 'foobar' is the owner of the `/usr/local/jvm/jdk-7.2` directory:
ark 'jdk' do
url 'http://download.example.com/jdk-7u2-linux-x64.tar.gz'
version '7.2'
path "/usr/local/jvm/"
home_dir "/usr/local/jvm/default"
checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'
append_env_path true
owner 'foobar'
end
Install Apache Ivy dependency resolution tool in <path>/resource_name in this case
`/usr/local/ivy`, do not symlink, and strip any leading directory if one
exists in the tarball:
ark "ivy" do
url 'http://someurl.example.com/ivy.tar.gz'
checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'
action :put
end
Install Apache Ivy dependency resolution tool in /home/foobar/ivy, strip any
leading directory if one exists:
ark "ivy" do
path "/home/foobar
url 'http://someurl.example.com/ivy.tar.gz'
checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'
action :put
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:
ark "my_jars" do
url "http://example.com/bunch_of_jars.zip"
path "/usr/local/tomcat/lib"
creates "mysql.jar"
owner "tomcat"
action :dump
end
Extract specific files from a tarball (currently only handles one named file):
ark 'mysql-connector-java' do
url 'http://oracle.com/mysql-connector.zip'
creates 'mysql-connector-java-5.0.8-bin.jar'
path '/usr/local/tomcat/lib'
action :cherry_pick
end
Build and install haproxy and use alternave values for `prefix_root`, `prefix_home`, and `prefix_bin`:
ark "haproxy" do
url "http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120403.tar.gz"
version "1.5"
checksum 'ba0424bf7d23b3a607ee24bbb855bb0ea347d7ffde0bec0cb12a89623cbaf911'
make_opts [ 'TARGET=linux26' ]
prefix_root '/opt'
prefix_home '/opt'
prefix_bin '/opt/bin'
action :install_with_make
end
You can also pass multiple actions to ark and supply the file extension in case
the file extension can not be determined by the URL:
ark "test_autogen" do
url 'https://github.com/zeromq/libzmq/tarball/master'
extension "tar.gz"
action [ :configure, :install_with_make ]
end
License and Author
==================
- Author: Philip (flip) Kromer - Infochimps, Inc(<coders@infochimps.com>)
- Author: Bryan W. Berry (<bryan.berry@gmail.com>)
- Author: Denis Barishev (<denis.barishev@gmail.com>)
- Author: Sean OMeara (<someara@opscode.com>)
- Copyright: 2011, Philip (flip) Kromer - Infochimps, Inc
- Copyright: 2012, Bryan W. Berry
- Copyright: 2012, Denis Barishev
- Copyright: 2013, Opscode, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,16 @@
default['ark']['apache_mirror'] = 'http://apache.mirrors.tds.net'
default['ark']['prefix_root'] = '/usr/local'
default['ark']['prefix_bin'] = '/usr/local/bin'
default['ark']['prefix_home'] = '/usr/local'
if node['platform_family'] === 'windows'
default['ark']['tar'] = "\"#{default['7-zip']['home']}\\7z.exe\""
else
default['ark']['tar'] = '/bin/tar'
end
pkgs = %w(libtool autoconf) unless platform_family?('mac_os_x','windows')
pkgs += %w(unzip rsync make gcc) unless platform_family?('mac_os_x','windows')
pkgs += %w(autogen) unless platform_family?('rhel', 'fedora', 'mac_os_x', 'suse','windows')
pkgs += %w(gtar) if platform?('freebsd')
default['ark']['package_dependencies'] = pkgs

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,102 @@
require 'minitest/spec'
describe_recipe 'ark::test' do
# It's often convenient to load these includes in a separate
# helper along with
# your own helper methods, but here we just include them directly:
include MiniTest::Chef::Assertions
include MiniTest::Chef::Context
include MiniTest::Chef::Resources
it 'installed the unzip package' do
package('unzip').must_be_installed
end
if RUBY_PLATFORM =~ /freebsd/
it 'installs the gnu tar package on freebsc' do
package('gtar').must_be_installed
end
end
it 'puts an ark in the desired directory w/out symlinks' do
directory('/usr/local/test_put').must_exist
end
it 'dumps the correct files into place with correct owner and group' do
file('/usr/local/foo_dump/foo1.txt').must_have(:owner, 'foobarbaz').and(:group, 'foobarbaz')
end
it 'cherrypicks the mysql connector and set the correct owner and group' do
file('/usr/local/foo_cherry_pick/foo1.txt').must_have(:owner, 'foobarbaz').and(:group, 'foobarbaz')
end
it 'cherrypicks the file from a zip' do
file('/usr/local/foo_cherry_pick_from_zip/foo1.txt').must_exist
end
it 'creates directory and symlink properly for the full ark install' do
directory('/usr/local/foo-2').must_have(:owner, 'foobarbaz').and(:group, 'foobarbaz')
link('/usr/local/foo').must_exist.with(:link_type, :symbolic).and(:to, '/usr/local/foo-2')
end
it 'symlinks multiple binary commands' do
link('/usr/local/bin/do_foo').must_exist.with(:link_type, :symbolic).and(:to, '/usr/local/foo-2/bin/do_foo')
link('/usr/local/bin/do_more_foo').must_exist.with(:link_type, :symbolic).and(:to, '/usr/local/foo-2/bin/do_more_foo')
end
it 'appends to the environment PATH' do
unless RUBY_PLATFORM =~ /freebsd/
file('/etc/profile.d/foo_append_env.sh').must_include '/usr/local/foo_append_env-7.0.26/bin'
bin_path_present = !ENV['PATH'].scan('/usr/local/foo_append_env-7.0.26/bin').empty?
assert bin_path_present
end
end
it 'doesnt strip top-level directory if specified' do
directory('/usr/local/foo_dont_strip/foo_sub').must_exist
end
it 'does strip for zip file' do
file('/usr/local/foo_zip_strip/foo1.txt').must_exist
end
it 'successfully compiles haproxy' do
file('/usr/local/haproxy-1.5/haproxy').must_exist
end
unless RUBY_PLATFORM =~ /freebsd/
it 'installs haproxy binary' do
file('/usr/local/sbin/haproxy').must_exist
directory('/usr/local/doc/haproxy').must_exist
end
end
it 'creates an alternate prefix_bin' do
link('/opt/bin/do_foo').must_exist.with(:link_type, :symbolic).and(:to, '/opt/foo_alt_bin-3/bin/do_foo')
end
it 'properly unpacks .tbz and .tgz archives' do
file('/usr/local/foo_tbz/foo1.txt').must_exist
file('/usr/local/foo_tgz/foo1.txt').must_exist
end
it 'sends notification when resource updated' do
file('/tmp/foobarbaz/notification_successful.txt').must_exist
end
it 'uses autogen.sh to generate configure script' do
file('/usr/local/test_autogen-1/configure').must_exist
end
it 'strips 2 components out of foo_sub.tar.gz archive path' do
directory('/usr/local/foo_sub-1/bin').must_exist
file('/usr/local/foo_sub-1/foo1.txt').must_exist
end
it 'strips 2 components out of foo_sub.zip archive path' do
directory('/usr/local/foo_sub-2/bin').must_exist
file('/usr/local/foo_sub-2/foo1.txt').must_exist
end
end

View File

@@ -0,0 +1,234 @@
# libs
module Opscode
module Ark
module ProviderHelpers
private
def unpack_type
case parse_file_extension
when /tar.gz|tgz/ then "tar_xzf"
when /tar.bz2|tbz/ then "tar_xjf"
when /tar.xz|txz/ then "tar_xJf"
when /zip|war|jar/ then "unzip"
else fail "Don't know how to expand #{new_resource.url}"
end
end
def parse_file_extension
if new_resource.extension.nil?
# purge any trailing redirect
url = new_resource.url.clone
url =~ %r{^https?:\/\/.*(.bin|bz2|gz|jar|tbz|tgz|txz|war|xz|zip)(\/.*\/)}
url.gsub!(Regexp.last_match(2), '') unless Regexp.last_match(2).nil?
# remove tailing query string
release_basename = ::File.basename(url.gsub(/\?.*\z/, '')).gsub(/-bin\b/, '')
# (\?.*)? accounts for a trailing querystring
Chef::Log.debug("DEBUG: release_basename is #{release_basename}")
release_basename =~ /^(.+?)\.(jar|tar\.bz2|tar\.gz|tar\.xz|tbz|tgz|txz|war|zip)(\?.*)?/
Chef::Log.debug("DEBUG: file_extension is #{Regexp.last_match(2)}")
new_resource.extension = Regexp.last_match(2)
end
new_resource.extension
end
def unpack_command
if node['platform_family'] === 'windows'
cmd = sevenzip_command
else
case unpack_type
when "tar_xzf"
cmd = tar_command("xzf")
when "tar_xjf"
cmd = tar_command("xjf")
when "tar_xJf"
cmd = tar_command("xJf")
when "unzip"
cmd = unzip_command
end
end
Chef::Log.debug("DEBUG: cmd: #{cmd}")
cmd
end
def tar_command(tar_args)
cmd = node['ark']['tar']
cmd += " #{tar_args} "
cmd += new_resource.release_file
cmd += tar_strip_args
cmd
end
def unzip_command
if new_resource.strip_components > 0
require 'tmpdir'
tmpdir = Dir.mktmpdir
strip_dir = '*/' * new_resource.strip_components
cmd = "unzip -q -u -o #{new_resource.release_file} -d #{tmpdir}"
cmd += " && rsync -a #{tmpdir}/#{strip_dir} #{new_resource.path}"
cmd += " && rm -rf #{tmpdir}"
cmd
else
"unzip -q -u -o #{new_resource.release_file} -d #{new_resource.path}"
end
end
def sevenzip_command
if new_resource.strip_components > 0
require 'tmpdir'
tmpdir = Dir.mktmpdir
cmd = sevenzip_command_builder(tmpdir,'e')
cmd += " && "
currdir = tmpdir
var = 0
while var < new_resource.strip_components do
var += 1
cmd += "for /f %#{var} in ('dir /ad /b \"#{currdir.gsub! '/', '\\'}\"') do "
currdir += "\\%#{var}"
end
cmd += "xcopy \"#{currdir}\" \"#{new_resource.home_dir}\" /s /e"
else
cmd = sevenzip_command_builder(new_resource.path,'x')
end
cmd
end
def sevenzip_command_builder(dir, command)
cmd = "#{node['ark']['tar']} #{command} \"";
cmd += new_resource.release_file
cmd += "\" "
case parse_file_extension
when /tar.gz|tgz|tar.bz2|tbz|tar.xz|txz/
cmd += " -so | #{node['ark']['tar']} x -aoa -si -ttar"
end
cmd += " -o\"#{dir}\" -uy"
cmd
end
def dump_command
if node['platform_family'] === 'windows'
cmd = sevenzip_command_builder(new_resource.path,'e')
else
case unpack_type
when "tar_xzf", "tar_xjf", "tar_xJf"
cmd = "tar -mxf \"#{new_resource.release_file}\" -C \"#{new_resource.path}\""
when "unzip"
cmd = "unzip -j -q -u -o \"#{new_resource.release_file}\" -d \"#{new_resource.path}\""
end
end
Chef::Log.debug("DEBUG: cmd: #{cmd}")
cmd
end
def cherry_pick_command
if node['platform_family'] === 'windows'
cmd = sevenzip_command_builder(new_resource.path,'e')
cmd += " -r #{new_resource.creates}"
else
case unpack_type
when "tar_xzf"
cmd = cherry_pick_tar_command("xzf")
when "tar_xjf"
cmd = cherry_pick_tar_command("xjf")
when "tar_xJf"
cmd = cherry_pick_tar_command("xJf")
when "unzip"
cmd = "unzip -t #{new_resource.release_file} \"*/#{new_resource.creates}\" ; stat=$? ;"
cmd += "if [ $stat -eq 11 ] ; then "
cmd += "unzip -j -o #{new_resource.release_file} \"#{new_resource.creates}\" -d #{new_resource.path} ;"
cmd += "elif [ $stat -ne 0 ] ; then false ;"
cmd += "else "
cmd += "unzip -j -o #{new_resource.release_file} \"*/#{new_resource.creates}\" -d #{new_resource.path} ;"
cmd += "fi"
end
end
Chef::Log.debug("DEBUG: cmd: #{cmd}")
cmd
end
def cherry_pick_tar_command(tar_args)
cmd = node['ark']['tar']
cmd += " #{tar_args}"
cmd += " #{new_resource.release_file}"
cmd += " -C"
cmd += " #{new_resource.path}"
cmd += " #{new_resource.creates}"
cmd += tar_strip_args
cmd
end
def set_paths
release_ext = parse_file_extension
prefix_bin = new_resource.prefix_bin.nil? ? new_resource.run_context.node['ark']['prefix_bin'] : new_resource.prefix_bin
prefix_root = new_resource.prefix_root.nil? ? new_resource.run_context.node['ark']['prefix_root'] : new_resource.prefix_root
if new_resource.prefix_home.nil?
default_home_dir = ::File.join(new_resource.run_context.node['ark']['prefix_home'], new_resource.name)
else
default_home_dir = ::File.join(new_resource.prefix_home, new_resource.name)
end
# set effective paths
new_resource.prefix_bin = prefix_bin
new_resource.version ||= "1" # initialize to one if nil
new_resource.home_dir ||= default_home_dir
if node['platform_family'] === 'windows'
new_resource.path = new_resource.win_install_dir
else
new_resource.path = ::File.join(prefix_root, "#{new_resource.name}-#{new_resource.version}")
end
Chef::Log.debug("path is #{new_resource.path}")
new_resource.release_file = ::File.join(Chef::Config[:file_cache_path], "#{new_resource.name}-#{new_resource.version}.#{release_ext}")
end
def set_put_paths
release_ext = parse_file_extension
path = new_resource.path.nil? ? new_resource.run_context.node['ark']['prefix_root'] : new_resource.path
new_resource.path = ::File.join(path, new_resource.name)
Chef::Log.debug("DEBUG: path is #{new_resource.path}")
new_resource.release_file = ::File.join(Chef::Config[:file_cache_path], "#{new_resource.name}.#{release_ext}")
end
def set_dump_paths
release_ext = parse_file_extension
new_resource.release_file = ::File.join(Chef::Config[:file_cache_path], "#{new_resource.name}.#{release_ext}")
end
def tar_strip_args
new_resource.strip_components > 0 ? " --strip-components=#{new_resource.strip_components}" : ""
end
def show_deprecations
if [true, false].include?(new_resource.strip_leading_dir)
Chef::Log.warn("DEPRECATED: strip_leading_dir attribute was deprecated. Use strip_components instead.")
end
end
def owner_command
if node['platform_family'] === 'windows'
cmd = "icacls #{new_resource.path}\\* /setowner #{new_resource.owner}"
else
cmd = "chown -R #{new_resource.owner}:#{new_resource.group} #{new_resource.path}"
end
cmd
end
# def unpacked?(path)
# if new_resource.creates
# full_path = ::File.join(new_resource.path, new_resource.creates)
# else
# full_path = path
# end
# if ::File.directory? full_path
# if ::File.stat(full_path).nlink == 2
# false
# else
# true
# end
# elsif ::File.exists? full_path
# true
# else
# false
# end
# end
end
end
end

File diff suppressed because one or more lines are too long

16
cookbooks/ark/metadata.rb Normal file
View File

@@ -0,0 +1,16 @@
name 'ark'
maintainer 'Bryan W. Berry'
maintainer_email 'bryan.berry@gmail.com'
license 'Apache 2.0'
description 'Installs/Configures ark'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.9.0'
%w( debian ubuntu centos redhat fedora windows ).each do |os|
supports os
end
recipe 'ark::default', 'Installs and configures ark'
depends 'windows'
depends '7-zip'

View File

@@ -0,0 +1,396 @@
#
# Cookbook Name:: ark
# Provider:: Ark
#
# Author:: Bryan W. Berry <bryan.berry@gmail.com>
# Author:: Sean OMeara <someara@opscode.com
# Copyright 2012, Bryan W. Berry
# Copyright 2013, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources if defined?(use_inline_resources)
include ::Opscode::Ark::ProviderHelpers
# From resources/default.rb
# :install, :put, :dump, :cherry_pick, :install_with_make, :configure, :setup_py_build, :setup_py_install, :setup_py
#
# Used in test.rb
# :install, :put, :dump, :cherry_pick, :install_with_make, :configure
#################
# action :install
#################
action :install do
show_deprecations
set_paths
directory new_resource.path do
recursive true
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
remote_file new_resource.release_file do
Chef::Log.debug('DEBUG: new_resource.release_file')
source new_resource.url
checksum new_resource.checksum if new_resource.checksum
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# unpack based on file extension
_unpack_command = unpack_command
execute "unpack #{new_resource.release_file}" do
command _unpack_command
cwd new_resource.path
environment new_resource.environment
notifies :run, "execute[set owner on #{new_resource.path}]"
action :nothing
end
# set_owner
_owner_command = owner_command
execute "set owner on #{new_resource.path}" do
command _owner_command
action :nothing
end
# usually on windows there is no central directory with executables where the applciations are linked
if not node['platform_family'] === 'windows'
# symlink binaries
new_resource.has_binaries.each do |bin|
link ::File.join(new_resource.prefix_bin, ::File.basename(bin)) do
to ::File.join(new_resource.path, bin)
end
end
# action_link_paths
link new_resource.home_dir do
to new_resource.path
end
# Add to path for interactive bash sessions
template "/etc/profile.d/#{new_resource.name}.sh" do
cookbook 'ark'
source 'add_to_path.sh.erb'
owner 'root'
group 'root'
mode '0755'
cookbook 'ark'
variables(:directory => "#{new_resource.path}/bin")
only_if { new_resource.append_env_path }
end
end
# Add to path for the current chef-client converge.
bin_path = ::File.join(new_resource.path, 'bin')
ruby_block "adding '#{bin_path}' to chef-client ENV['PATH']" do
block do
ENV['PATH'] = bin_path + ':' + ENV['PATH']
end
only_if { new_resource.append_env_path && ENV['PATH'].scan(bin_path).empty? }
end
end
##############
# action :put
##############
action :put do
show_deprecations
set_put_paths
directory new_resource.path do
recursive true
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# download
remote_file new_resource.release_file do
source new_resource.url
checksum new_resource.checksum if new_resource.checksum
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# unpack based on file extension
_unpack_command = unpack_command
execute "unpack #{new_resource.release_file}" do
command _unpack_command
cwd new_resource.path
environment new_resource.environment
notifies :run, "execute[set owner on #{new_resource.path}]"
action :nothing
end
# set_owner
_owner_command = owner_command
execute "set owner on #{new_resource.path}" do
command _owner_command
action :nothing
end
end
###########################
# action :dump
###########################
action :dump do
show_deprecations
set_dump_paths
directory new_resource.path do
recursive true
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# download
remote_file new_resource.release_file do
Chef::Log.debug("DEBUG: new_resource.release_file #{new_resource.release_file}")
source new_resource.url
checksum new_resource.checksum if new_resource.checksum
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# unpack based on file extension
_dump_command = dump_command
execute "unpack #{new_resource.release_file}" do
command _dump_command
cwd new_resource.path
environment new_resource.environment
notifies :run, "execute[set owner on #{new_resource.path}]"
action :nothing
end
# set_owner
_owner_command = owner_command
execute "set owner on #{new_resource.path}" do
command _owner_command
action :nothing
end
end
###########################
# action :unzip
###########################
action :unzip do
show_deprecations
set_dump_paths
directory new_resource.path do
recursive true
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# download
remote_file new_resource.release_file do
Chef::Log.debug("DEBUG: new_resource.release_file #{new_resource.release_file}")
source new_resource.url
checksum new_resource.checksum if new_resource.checksum
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# unpack based on file extension
_unzip_command = unzip_command
execute "unpack #{new_resource.release_file}" do
command _unzip_command
cwd new_resource.path
environment new_resource.environment
notifies :run, "execute[set owner on #{new_resource.path}]"
action :nothing
end
# set_owner
_owner_command = owner_command
execute "set owner on #{new_resource.path}" do
command _owner_command
action :nothing
end
end
#####################
# action :cherry_pick
#####################
action :cherry_pick do
show_deprecations
set_dump_paths
Chef::Log.debug("DEBUG: new_resource.creates #{new_resource.creates}")
directory new_resource.path do
recursive true
action :create
notifies :run, "execute[cherry_pick #{new_resource.creates} from #{new_resource.release_file}]"
end
# download
remote_file new_resource.release_file do
source new_resource.url
checksum new_resource.checksum if new_resource.checksum
action :create
notifies :run, "execute[cherry_pick #{new_resource.creates} from #{new_resource.release_file}]"
end
_unpack_type = unpack_type
_cherry_pick_command = cherry_pick_command
execute "cherry_pick #{new_resource.creates} from #{new_resource.release_file}" do
Chef::Log.debug("DEBUG: unpack_type: #{_unpack_type}")
command _cherry_pick_command
creates "#{new_resource.path}/#{new_resource.creates}"
notifies :run, "execute[set owner on #{new_resource.path}]"
action :nothing
end
# set_owner
_owner_command = owner_command
execute "set owner on #{new_resource.path}" do
command _owner_command
action :nothing
end
end
###########################
# action :install_with_make
###########################
action :install_with_make do
show_deprecations
set_paths
directory new_resource.path do
recursive true
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
remote_file new_resource.release_file do
Chef::Log.debug('DEBUG: new_resource.release_file')
source new_resource.url
checksum new_resource.checksum if new_resource.checksum
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# unpack based on file extension
_unpack_command = unpack_command
execute "unpack #{new_resource.release_file}" do
command _unpack_command
cwd new_resource.path
environment new_resource.environment
notifies :run, "execute[set owner on #{new_resource.path}]"
notifies :run, "execute[autogen #{new_resource.path}]"
notifies :run, "execute[configure #{new_resource.path}]"
notifies :run, "execute[make #{new_resource.path}]"
notifies :run, "execute[make install #{new_resource.path}]"
action :nothing
end
# set_owner
_owner_command = owner_command
execute "set owner on #{new_resource.path}" do
command _owner_command
action :nothing
end
execute "autogen #{new_resource.path}" do
command './autogen.sh'
only_if { ::File.exist? "#{new_resource.path}/autogen.sh" }
cwd new_resource.path
environment new_resource.environment
action :nothing
ignore_failure true
end
execute "configure #{new_resource.path}" do
command "./configure #{new_resource.autoconf_opts.join(' ')}"
only_if { ::File.exist? "#{new_resource.path}/configure" }
cwd new_resource.path
environment new_resource.environment
action :nothing
end
execute "make #{new_resource.path}" do
command "make #{new_resource.make_opts.join(' ')}"
cwd new_resource.path
environment new_resource.environment
action :nothing
end
execute "make install #{new_resource.path}" do
command "make install #{new_resource.make_opts.join(' ')}"
cwd new_resource.path
environment new_resource.environment
action :nothing
end
# unless new_resource.creates and ::File.exists? new_resource.creates
# end
end
action :configure do
show_deprecations
set_paths
directory new_resource.path do
recursive true
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
remote_file new_resource.release_file do
Chef::Log.debug('DEBUG: new_resource.release_file')
source new_resource.url
checksum new_resource.checksum if new_resource.checksum
action :create
notifies :run, "execute[unpack #{new_resource.release_file}]"
end
# unpack based on file extension
_unpack_command = unpack_command
execute "unpack #{new_resource.release_file}" do
command _unpack_command
cwd new_resource.path
environment new_resource.environment
notifies :run, "execute[set owner on #{new_resource.path}]"
notifies :run, "execute[autogen #{new_resource.path}]"
notifies :run, "execute[configure #{new_resource.path}]"
action :nothing
end
# set_owner
_owner_command = owner_command
execute "set owner on #{new_resource.path}" do
command _owner_command
action :nothing
end
execute "autogen #{new_resource.path}" do
command './autogen.sh'
only_if { ::File.exist? "#{new_resource.path}/autogen.sh" }
cwd new_resource.path
environment new_resource.environment
action :nothing
ignore_failure true
end
execute "configure #{new_resource.path}" do
command "./configure #{new_resource.autoconf_opts.join(' ')}"
only_if { ::File.exist? "#{new_resource.path}/configure" }
cwd new_resource.path
environment new_resource.environment
action :nothing
end
end

View File

@@ -0,0 +1,27 @@
#
# Cookbook Name:: ark
# Recipe:: default
#
# Author:: Bryan W. Berry <bryan.berry@gmail.com>
# Copyright 2012, Bryan W. Berry
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Array(node['ark']['package_dependencies']).each do |pkg|
package pkg
end
if node['platform_family'] === 'windows'
include_recipe "7-zip"
end

View File

@@ -0,0 +1,152 @@
# require 'fileutils'
# remove file so we can test sending notification on its creation
FileUtils.rm_f '/tmp/foobarbaz/foo1.txt' if ::File.exist? '/tmp/foobarbaz/foo1.txt'
ruby_block 'test_notification' do
block do
FileUtils.touch '/tmp/foobarbaz/notification_successful.txt' if ::File.exist? '/tmp/foobarbaz/foo1.txt'
end
action :nothing
end
user 'foobarbaz'
directory '/opt/bin' do
recursive true
end
ark 'foo' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.tar.gz'
checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8'
version '2'
prefix_root '/usr/local'
owner 'foobarbaz'
group 'foobarbaz'
has_binaries ['bin/do_foo', 'bin/do_more_foo']
action :install
end
ark 'test_put' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.tar.gz'
checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8'
owner 'foobarbaz'
group 'foobarbaz'
action :put
end
ark 'test_dump' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.zip'
checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0'
path '/usr/local/foo_dump'
creates 'foo1.txt'
owner 'foobarbaz'
group 'foobarbaz'
action :dump
end
ark 'cherry_pick_test' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.tar.gz'
checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8'
path '/usr/local/foo_cherry_pick'
owner 'foobarbaz'
group 'foobarbaz'
creates 'foo_sub/foo1.txt'
action :cherry_pick
end
ark 'cherry_pick_with_zip' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.zip'
checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0'
path '/usr/local/foo_cherry_pick_from_zip'
creates 'foo_sub/foo1.txt'
action :cherry_pick
end
ark 'foo_append_env' do
version '7.0.26'
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.tar.gz'
checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8'
append_env_path true
action :install
end
ark 'foo_dont_strip' do
version '2'
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.tar.gz'
checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8'
strip_components 0
action :install
end
ark 'foo_zip_strip' do
version '2'
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.zip'
checksum 'deea3a324115c9ca0f3078362f807250080bf1b27516f7eca9d34aad863a11e0'
action :install
end
ark 'haproxy' do
url 'http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120403.tar.gz'
version '1.5'
checksum 'ba0424bf7d23b3a607ee24bbb855bb0ea347d7ffde0bec0cb12a89623cbaf911'
make_opts ['TARGET=linux26']
action :install_with_make
end unless platform?('freebsd')
ark 'foo_alt_bin' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.tar.gz'
checksum '5996e676f17457c823d86f1605eaa44ca8a81e70d6a0e5f8e45b51e62e0c52e8'
version '3'
prefix_root '/opt'
prefix_home '/opt'
prefix_bin '/opt/bin'
owner 'foobarbaz'
group 'foobarbaz'
has_binaries ['bin/do_foo']
action :install
end
ark 'foo_tbz' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.tbz'
version '3'
end
ark 'foo_tgz' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.tgz'
version '3'
end
ark 'foo_txz' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.txz'
version '3'
end
ark 'test notification' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo.zip'
path '/tmp/foobarbaz'
creates 'foo1.txt'
action :dump
notifies :create, 'ruby_block[test_notification]', :immediately
end
ark 'test_autogen' do
url 'https://github.com/zeromq/libzmq/tarball/master'
extension 'tar.gz'
action :configure
# autoconf in RHEL < 6 is too old
not_if { platform_family?('rhel') && node['platform_version'].to_f < 6.0 }
end
ark 'foo_sub' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo_sub.tar.gz'
version '1'
strip_components 2
end
ark 'foo_sub' do
url 'https://github.com/opscode-cookbooks/ark/raw/master/files/default/foo_sub.zip'
version '2'
strip_components 2
end

View File

@@ -0,0 +1,55 @@
#
# Cookbook Name:: ark
# Resource:: Ark
#
# Author:: Bryan W. Berry <bryan.berry@gmail.com>
# Copyright 2012, Bryan W. Berry
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
def initialize(name, run_context = nil)
super
@resource_name = :ark
@allowed_actions.push(:install, :dump, :cherry_pick, :put, :install_with_make, :configure, :setup_py_build, :setup_py_install, :setup_py, :unzip)
@action = :install
@provider = Chef::Provider::Ark
end
attr_accessor :path, :release_file, :prefix_bin, :prefix_root, :home_dir, :extension, :version
attribute :owner, :kind_of => String, :default => 'root'
attribute :group, :kind_of => [String, Fixnum], :default => 0
attribute :url, :kind_of => String, :required => true
attribute :path, :kind_of => String, :default => nil
attribute :full_path, :kind_of => String, :default => nil
attribute :append_env_path, :kind_of => [TrueClass, FalseClass], :default => false
attribute :checksum, :regex => /^[a-zA-Z0-9]{64}$/, :default => nil
attribute :has_binaries, :kind_of => Array, :default => []
attribute :creates, :kind_of => String, :default => nil
attribute :release_file, :kind_of => String, :default => ''
attribute :strip_leading_dir, :kind_of => [TrueClass, FalseClass, NilClass]
attribute :strip_components, :kind_of => Integer, :default => 1
attribute :mode, :kind_of => Fixnum, :default => 0755
attribute :prefix_root, :kind_of => String, :default => nil
attribute :prefix_home, :kind_of => String, :default => nil
attribute :prefix_bin, :kind_of => String, :default => nil
attribute :version, :kind_of => String, :default => nil
attribute :home_dir, :kind_of => String, :default => nil
attribute :win_install_dir, :kind_of => String, :default => nil
attribute :environment, :kind_of => Hash, :default => {}
attribute :autoconf_opts, :kind_of => Array, :default => []
attribute :make_opts, :kind_of => Array, :default => []
attribute :home_dir, :kind_of => String, :default => nil
attribute :autoconf_opts, :kind_of => Array, :default => []
attribute :extension, :kind_of => String

View File

@@ -0,0 +1 @@
export PATH=<%= @directory -%>:$PATH