Get rid of the application and poise cookbooks
This commit is contained in:
parent
d7bc5e6f08
commit
05834b6013
10
Berksfile
10
Berksfile
|
@ -9,16 +9,6 @@ cookbook 'redisio', '~> 6.4.1'
|
|||
cookbook 'postfix', '= 5.0.2'
|
||||
cookbook 'php', '~> 8.0.0'
|
||||
cookbook 'composer', '~> 2.7.0'
|
||||
cookbook 'poise-ruby-build', '~> 1.1.0'
|
||||
cookbook 'application', '~> 5.2.0'
|
||||
cookbook 'application_javascript', '~> 1.0.0'
|
||||
cookbook 'application_git', '= 1.1.0' # 1.2.0 doesn't work with knife-solo
|
||||
cookbook 'poise', '~> 2.8.2'
|
||||
cookbook 'poise-languages', '~> 2.1.1'
|
||||
cookbook 'poise-javascript', git: 'https://github.com/67p/poise-javascript.git',
|
||||
ref: 'e5fff15'
|
||||
cookbook 'poise-archive', '~> 1.5.0'
|
||||
cookbook 'poise-service', '~> 1.5.2'
|
||||
cookbook 'users', '~> 5.3.1'
|
||||
cookbook 'hostname', '= 0.4.2'
|
||||
cookbook 'firewall', '~> 2.6.3'
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
DEPENDENCIES
|
||||
apache2 (= 3.3.0)
|
||||
application (~> 5.2.0)
|
||||
application_git (= 1.1.0)
|
||||
application_javascript (~> 1.0.0)
|
||||
apt (~> 7.3.0)
|
||||
ark (>= 5.0.0)
|
||||
build-essential (~> 8.2.1)
|
||||
|
@ -35,15 +32,6 @@ DEPENDENCIES
|
|||
ohai (~> 5.2.5)
|
||||
openssl (~> 8.5.5)
|
||||
php (~> 8.0.0)
|
||||
poise (~> 2.8.2)
|
||||
poise-archive (~> 1.5.0)
|
||||
poise-javascript
|
||||
git: https://github.com/67p/poise-javascript.git
|
||||
revision: e5fff15098ac80c2a625b8d77d4eaf39d48f7ba7
|
||||
ref: e5fff15
|
||||
poise-languages (~> 2.1.1)
|
||||
poise-ruby-build (~> 1.1.0)
|
||||
poise-service (~> 1.5.2)
|
||||
postfix (= 5.0.2)
|
||||
redisio (~> 6.4.1)
|
||||
ruby_build (~> 2.5.0)
|
||||
|
@ -54,18 +42,6 @@ DEPENDENCIES
|
|||
|
||||
GRAPH
|
||||
apache2 (3.3.0)
|
||||
application (5.2.0)
|
||||
poise (~> 2.4)
|
||||
poise-service (~> 1.0)
|
||||
application_git (1.1.0)
|
||||
application (~> 5.0)
|
||||
git (>= 0.0.0)
|
||||
poise (~> 2.0)
|
||||
application_javascript (1.0.0)
|
||||
application (~> 5.0)
|
||||
poise (~> 2.0)
|
||||
poise-javascript (~> 1.0)
|
||||
poise-service (~> 1.0)
|
||||
apt (7.3.0)
|
||||
ark (6.0.3)
|
||||
seven_zip (>= 3.1)
|
||||
|
@ -124,30 +100,6 @@ GRAPH
|
|||
openssl (8.5.5)
|
||||
php (8.0.1)
|
||||
yum-epel (>= 0.0.0)
|
||||
poise (2.8.2)
|
||||
poise-archive (1.5.0)
|
||||
poise (~> 2.6)
|
||||
poise-build-essential (1.0.0)
|
||||
poise (~> 2.6)
|
||||
poise-git (1.0.0)
|
||||
poise (~> 2.6)
|
||||
poise-languages (~> 2.1)
|
||||
poise-javascript (1.2.1)
|
||||
poise (~> 2.0)
|
||||
poise-languages (~> 2.0)
|
||||
poise-languages (2.1.2)
|
||||
poise (~> 2.5)
|
||||
poise-archive (~> 1.0)
|
||||
poise-ruby (2.4.0)
|
||||
poise (~> 2.0)
|
||||
poise-languages (~> 2.0)
|
||||
poise-ruby-build (1.1.0)
|
||||
poise (~> 2.0)
|
||||
poise-build-essential (~> 1.0)
|
||||
poise-git (~> 1.0)
|
||||
poise-ruby (~> 2.1)
|
||||
poise-service (1.5.2)
|
||||
poise (~> 2.0)
|
||||
postfix (5.0.2)
|
||||
redisio (6.4.1)
|
||||
selinux (>= 0.0.0)
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
# Application Changelog
|
||||
|
||||
## v5.2.0
|
||||
|
||||
* Add `application_directory` resource.
|
||||
* Chef 13 compatibility.
|
||||
|
||||
## v5.1.0
|
||||
|
||||
* Add `application_cookbook_file`, `application_file`, and `application_template` resources.
|
||||
|
||||
## v5.0.0
|
||||
|
||||
* Massive rewrite on top of newer Chef patterns. See the 5.0 README for details.
|
||||
|
||||
## v4.1.6
|
||||
|
||||
* Support for Chef 12.
|
||||
* Add `strict_ssh` option to enable host key checking.
|
||||
* Add `keep_releases` option to control number of releases to keep.
|
||||
* Allow passing a path to a file for `deploy_key`.
|
||||
|
||||
## v4.1.4
|
||||
|
||||
* [COOK-3343](https://tickets.opscode.com/browse/COOK-3343) - Can't parse release candidate version number.
|
||||
|
||||
## v4.1.2
|
||||
|
||||
* [COOK-3343](https://tickets.opscode.com/browse/COOK-3343) - Can't parse release candidate version number.
|
||||
|
||||
## v4.1.0
|
||||
|
||||
* [COOK-3343] - Can't parse release candidate version number.
|
||||
|
||||
## v4.0.0
|
||||
|
||||
* Removes compatability with Chef 10.
|
||||
* [COOK-3564](https://tickets.opscode.com/browse/COOK-3564) - Replace calls to `Chef::Mixin::RecipeDefinitionDSLCore`.
|
||||
|
||||
## v3.0.0
|
||||
|
||||
* [COOK-3306]: Multiple Memory Leaks in Application Cookbook.
|
||||
|
||||
## v2.0.4
|
||||
|
||||
* [COOK-2812]: application cookbook doesn't allow to specify a block as `restart_command`.
|
||||
|
||||
## v2.0.2
|
||||
|
||||
* [COOK-2537]: Provide proper `respond_to` behavior when using `method_missing`.
|
||||
* [COOK-2713]: application resource should Allow sub-resource attributes to propogate up.
|
||||
|
||||
### Improvement
|
||||
* [COOK-2597]: Allow customization for `shallow_clone` when doing a git deploy.
|
||||
|
||||
## v2.0.0
|
||||
|
||||
This release is incompatible with previous releases (hence major version change). The recipes used in older versions are deprecated and completely removed. See README.md for further detail.
|
||||
|
||||
* [COOK-1673] - `deploy_revision` in the application cookbook gives an argument error.
|
||||
* [COOK-1820] - Application cookbook: remove deprecated recipes.
|
||||
|
||||
## v1.0.4
|
||||
|
||||
* [COOK-1567] - Add git submodules to application cookbook.
|
||||
|
||||
## v1.0.2
|
||||
|
||||
* [COOK-1312] - string callbacks fail with method not found (really included this time).
|
||||
* [COOK-1332] - add `release_path` and `shared_path` methods.
|
||||
* [COOK-1333] - add example for running migrations.
|
||||
* [COOK-1360] - fix minor typos in README.
|
||||
* [COOK-1374] - use runit attributes in unicorn run script.
|
||||
|
||||
## v1.0.0
|
||||
|
||||
This release introduces the LWRP for application deployment, as well as other improvements. The recipes will be deprecated in August 2012 as indicated by their warning messages and in the README.md.
|
||||
|
||||
* [COOK-634] - Implement LWRP for application deployment.
|
||||
* [COOK-1116] - use other SCMs than git.
|
||||
* [COOK-1252] - add `:force_deploy` that maps to corresponding action of deploy resource.
|
||||
* [COOK-1253] - fix rollback error.
|
||||
* [COOK-1312] - string callbacks fail with method not found.
|
||||
* [COOK-1313] - implicit file based hooks aren't invoked.
|
||||
* [COOK-1318] - Create `to_ary` method to resolve issue in resources() lookup on "application[foo]" resources.
|
||||
|
||||
## v0.99.14
|
||||
|
||||
* [COOK-1065] - use pip in virtualenv during deploy.
|
||||
|
||||
## v0.99.12
|
||||
|
||||
* [COOK-606] application cookbook deployment recipes should use ipaddress instead of fqdn.
|
||||
|
||||
## v0.99.11
|
||||
|
||||
* make the `_default` `chef_environment` look like production rails env.
|
||||
|
||||
## v0.99.10
|
||||
|
||||
* Use Chef 0.10's `node.chef_environment` instead of `node['app_environment']`.
|
|
@ -1,260 +0,0 @@
|
|||
# Application cookbook
|
||||
|
||||
[![Build Status](https://img.shields.io/travis/poise/application.svg)](https://travis-ci.org/poise/application)
|
||||
[![Gem Version](https://img.shields.io/gem/v/poise-application.svg)](https://rubygems.org/gems/poise-application)
|
||||
[![Cookbook Version](https://img.shields.io/cookbook/v/application.svg)](https://supermarket.chef.io/cookbooks/application)
|
||||
[![Coverage](https://img.shields.io/codeclimate/coverage/github/poise/application.svg)](https://codeclimate.com/github/poise/application)
|
||||
[![Gemnasium](https://img.shields.io/gemnasium/poise/application.svg)](https://gemnasium.com/poise/application)
|
||||
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
A [Chef](https://www.chef.io/) cookbook to deploy applications.
|
||||
|
||||
## Getting Started
|
||||
|
||||
The application cookbook provides a central framework to deploy applications
|
||||
using Chef. Generally this will be web applications using things like Rails,
|
||||
Django, or NodeJS, but the framework makes no specific assumptions. The core
|
||||
`application` resource provides DSL support and helpers, but the heavy lifting
|
||||
is all done in specific plugins detailed below. Each deployment starts with
|
||||
an `application` resource:
|
||||
|
||||
```ruby
|
||||
application '/path/to/deploy' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
|
||||
# ...
|
||||
end
|
||||
```
|
||||
|
||||
The `application` resource uses the Poise subresource system for plugins. This
|
||||
means you configure the steps of the deployment like normal recipe code inside
|
||||
the `application` resource, with a few special additions:
|
||||
|
||||
```ruby
|
||||
application '/path/to/deploy' do
|
||||
# Application resource properties.
|
||||
owner 'root'
|
||||
group 'root'
|
||||
|
||||
# Subresources, like normal recipe code.
|
||||
package 'ruby'
|
||||
git '/path/to/deploy' do
|
||||
repository 'https://github.com/example/myapp.git'
|
||||
end
|
||||
application_rails '/path/to/deploy' do
|
||||
database 'mysql://dbhost/myapp'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
When evaluating the recipe inside the `application` resource, it first checks
|
||||
for `application_#{resource}`, as well as looking for an LWRP of the same name
|
||||
in any cookbook starting with `application_`. This means that a resource named
|
||||
`application_foo` can be used as `foo` inside the `application` resource:
|
||||
|
||||
```ruby
|
||||
application '/path/to/deploy' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
|
||||
rails '/path/to/deploy' do
|
||||
database 'mysql://dbhost/myapp'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
Additionally if a resource inside the `application` block doesn't have a name,
|
||||
it uses the same name as the application resource itself:
|
||||
|
||||
```ruby
|
||||
application '/path/to/deploy' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
|
||||
rails do
|
||||
database 'mysql://dbhost/myapp'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
Other than those two special features, the recipe code inside the `application`
|
||||
resource is processed just like any other recipe.
|
||||
|
||||
## Available Plugins
|
||||
|
||||
* [`application_git`](https://github.com/poise/application_git) – Deploy
|
||||
application code from a git repository.
|
||||
* [`application_ruby`](https://github.com/poise/application_ruby) – Manage Ruby
|
||||
deployments, such as Rails or Sinatra applications.
|
||||
* [`application_python`](https://github.com/poise/application_python) – Manage
|
||||
Python deployments, such as Django or Flask applications.
|
||||
* [`application_javascript`](https://github.com/poise/application_javascript) –
|
||||
Manage server-side JavaScript deployments using Node.js or io.js.
|
||||
* `application_java` – *Coming soon!*
|
||||
* `application_go` – *Coming soon!*
|
||||
* `application_erlang` – *Coming soon!*
|
||||
|
||||
## Requirements
|
||||
|
||||
Chef 12 or newer is required.
|
||||
|
||||
## Resources
|
||||
|
||||
### `application`
|
||||
|
||||
The `application` resource has top-level configuration properties for each
|
||||
deployment and acts as a container for other deployment plugin resources.
|
||||
|
||||
```ruby
|
||||
application '/opt/test_sinatra' do
|
||||
git 'https://github.com/example/my_sinatra_app.git'
|
||||
bundle_install do
|
||||
deployment true
|
||||
end
|
||||
unicorn do
|
||||
port 9000
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:deploy` – Deploy the application. *(default)*
|
||||
* `:start` - Run `:start` on all subresources that support it.
|
||||
* `:stop` - Run `:stop` on all subresources that support it.
|
||||
* `:restart` - Run `:restart` on all subresources that support it.
|
||||
* `:reload` - Run `:reload` on all subresources that support it.
|
||||
|
||||
#### Properties
|
||||
|
||||
* `path` – Path to deploy the application to. *(name attribute)*
|
||||
* `environment` – Environment variables for all application deployment steps.
|
||||
* `group` – System group to deploy the application as.
|
||||
* `owner` – System user to deploy the application as.
|
||||
* `action_on_update` – Action to run on the application resource when any
|
||||
subresource is updated. *(default: restart)*
|
||||
* `action_on_update_immediately` – Run the `action_on_update` notification with
|
||||
`:immediately`. *(default: false)*
|
||||
|
||||
### `application_cookbook_file`, `application_directory`, `application_file`, `application_template`
|
||||
|
||||
The `application_cookbook_file`, `application_directory`, `application_file`, and `application_template`
|
||||
resources extend the core Chef resources to take some application-level
|
||||
configuration in to account:
|
||||
|
||||
```ruby
|
||||
application '/opt/myapp' do
|
||||
template 'myapp.conf' do
|
||||
source 'myapp.conf.erb'
|
||||
end
|
||||
directory 'logs'
|
||||
end
|
||||
```
|
||||
|
||||
If the resource name is a relative path, it will be expanded relative to the
|
||||
application path. If an owner or group is declared for the application, those
|
||||
will be the default user and group for the resource.
|
||||
|
||||
All other actions and properties are the same as the similar resource in core Chef.
|
||||
|
||||
## Examples
|
||||
|
||||
Some test recipes are available as examples for common application frameworks:
|
||||
|
||||
* [Sinatra](https://github.com/poise/application_ruby/blob/master/test/cookbooks/application_ruby_test/recipes/sinatra.rb)
|
||||
* [Rails](https://github.com/poise/application_ruby/blob/master/test/cookbooks/application_ruby_test/recipes/rails.rb)
|
||||
* [Flask](https://github.com/poise/application_python/blob/master/test/cookbook/recipes/flask.rb)
|
||||
* [Django](https://github.com/poise/application_python/blob/master/test/cookbook/recipes/django.rb)
|
||||
* [Express](https://github.com/poise/application_javascript/blob/master/test/cookbook/recipes/express.rb)
|
||||
|
||||
## Upgrading From 4.x
|
||||
|
||||
While the overall design of the revamped application resource is similar to the
|
||||
4.x version, some changes will need to be made. The `name` property no longer
|
||||
exists, with the name attribute being used as the path to the deployment.
|
||||
The `packages` property has been removed as this is more easily handled via
|
||||
normal recipe code.
|
||||
|
||||
The SCM-related properties like `repository` and `revision` are now handled by
|
||||
normal plugins. If you were deploying from a private git repository you will
|
||||
likely want to use the `application_git` cookbook, otherwise just use the
|
||||
built-in `git` or `svn` resources as per normal.
|
||||
|
||||
The properties related to the `deploy` resource like `strategy` and `symlinks`
|
||||
have been removed. The `deploy` resource is no longer used so these aren't
|
||||
relevant. As a side effect of this, you'll likely want to point the upgraded
|
||||
deployment at a new folder or manually clean the `current` and `shared` folders
|
||||
from the existing folder. The pseudo-Capistrano layout used by the `deploy`
|
||||
resource has few benefits in a config-managed world and introduced a lot of
|
||||
complexity and moving pieces that are no longer required.
|
||||
|
||||
With the removal of the `deploy` resource, the callback properties and commands
|
||||
are no longer used as well. Subresources no longer use the complex
|
||||
actions-as-callbacks arrangement as existed before, instead following normal
|
||||
Chef recipe flow. Individual subresources may need to be tweaked to work with
|
||||
newer versions of the cookbooks they come from, though most have stayed similar
|
||||
in overall approach.
|
||||
|
||||
## Database Migrations and Chef
|
||||
|
||||
Several of the web application deployment plugins include optional support to
|
||||
run database migrations from Chef. For "toy" applications where the app and
|
||||
database run together on a single machine, this is fine and is a nice time
|
||||
saver. For anything more complex I highly recommend not running database
|
||||
migrations from Chef. Some initial operations like creating the database and/or
|
||||
database user are more reasonable as they tend to be done only once and by their
|
||||
nature the application does not yet have users so some level of eventual
|
||||
consistency is more acceptable. With migrations on a production application, I
|
||||
encourage using Chef and the application cookbooks to handle deploying the code
|
||||
and writing configuration files, but use something more specific to run the
|
||||
actual migration task. [Fabric](http://www.fabfile.org/),
|
||||
[Capistrano](http://capistranorb.com/), and [Rundeck](http://rundeck.org/) are
|
||||
all good choices for this orchestration tooling.
|
||||
|
||||
Migrations can generally be applied idempotently but they have unique
|
||||
constraints (pun definitely intended) that make them tricky in a Chef-like,
|
||||
convergence-based system. First and foremost is that many table alterations
|
||||
lock the table for updating for at least some period of time. That can mean that
|
||||
while staging the new code or configuration data can happen within a window, the
|
||||
migration itself needs to be run in careful lockstep with the rest of the
|
||||
deployment process (eg. moving things in and out of load balancers). Beyond
|
||||
that, while most web frameworks have internal idempotence checks for migrations,
|
||||
running the process on two servers at the same time can have unexpected effects.
|
||||
|
||||
Overall migrations are best thought of as a procedural step rather than a
|
||||
declaratively modeled piece of the system.
|
||||
|
||||
## Application Signals and Updates
|
||||
|
||||
The `application` resource exposes `start`, `stop`, `restart`, and `reload`
|
||||
actions which will dispatch to any subresources attached to the application.
|
||||
This allows for generic application-level restart or reload signals that will
|
||||
work with any type of deployment.
|
||||
|
||||
Additionally the `action_on_update` property is used to set a default
|
||||
notification so any subresource that updates will trigger an application
|
||||
restart or reload. This can be disabled by setting `action_on_update false` if
|
||||
you want to take manual control of service restarts.
|
||||
|
||||
## Sponsors
|
||||
|
||||
Development sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).
|
||||
|
||||
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2015-2016, Noah Kantrowitz
|
||||
|
||||
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.
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
autoload :AppMixin, 'poise_application/app_mixin'
|
||||
autoload :Error, 'poise_application/error'
|
||||
autoload :Resources, 'poise_application/resources'
|
||||
autoload :ServiceMixin, 'poise_application/service_mixin'
|
||||
autoload :Utils, 'poise_application/utils'
|
||||
autoload :VERSION, 'poise_application/version'
|
||||
end
|
|
@ -1,64 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise/utils'
|
||||
|
||||
require 'poise_application/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
# A helper mixin for `file`-like resources to make them take application
|
||||
# resource data. Relative paths are expanded against the application path and
|
||||
# the app owner/group are the default user/group for the resource.
|
||||
#
|
||||
# @api private
|
||||
# @since 5.1.0
|
||||
module AppFileMixin
|
||||
include Poise::Utils::ResourceProviderMixin
|
||||
|
||||
module Resource
|
||||
include PoiseApplication::AppMixin
|
||||
|
||||
def initialize(*)
|
||||
super
|
||||
# So our lazy default below can work. Not needed on 12.7+.
|
||||
remove_instance_variable(:@path) if instance_variable_defined?(:@path)
|
||||
end
|
||||
|
||||
# @!attribute path
|
||||
# Override the default path to be relative to the app path.
|
||||
# @return [String]
|
||||
attribute(:path, kind_of: String, default: lazy { parent ? ::File.expand_path(name, parent.path) : name })
|
||||
|
||||
# @!attribute group
|
||||
# Override the default group to be the app group if unspecified.
|
||||
# @return [String, Integer]
|
||||
attribute(:group, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.group })
|
||||
|
||||
# @!attribute owner
|
||||
# Override the default user to be the app owner if unspecified.
|
||||
# @return [String, Integer]
|
||||
attribute(:owner, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.owner })
|
||||
|
||||
# For the forgetful.
|
||||
alias_method :user, :owner
|
||||
end
|
||||
|
||||
module Provider
|
||||
include PoiseApplication::AppMixin
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,69 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/mash'
|
||||
require 'poise/provider'
|
||||
require 'poise/resource'
|
||||
require 'poise/utils'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
# A helper mixin for application resources and providers. These are things
|
||||
# intended to be used as subresources of the `application` resource.
|
||||
#
|
||||
# @since 5.0.0
|
||||
module AppMixin
|
||||
include Poise::Utils::ResourceProviderMixin
|
||||
|
||||
# A helper mixin for application resources.
|
||||
module Resource
|
||||
include Poise::Resource
|
||||
|
||||
# Set the parent type and optional flag.
|
||||
poise_subresource(:application, true)
|
||||
|
||||
# @!attribute path
|
||||
# Base path for the application.
|
||||
# @return [String]
|
||||
attribute(:path, kind_of: String, name_attribute: true)
|
||||
|
||||
# A delegator for accessing the application state. If no application
|
||||
# parent is found, the state will be tracked internally within the
|
||||
# resource.
|
||||
#
|
||||
# @return [Hash<Symbol, Object>]
|
||||
def app_state
|
||||
if parent
|
||||
parent.app_state
|
||||
else
|
||||
# If there isn't a parent, just track within the resource.
|
||||
@local_app_state ||= Mash.new
|
||||
end
|
||||
end
|
||||
|
||||
# Environment variables stored in the application state.
|
||||
#
|
||||
# @return [Hash<String, String>]
|
||||
def app_state_environment
|
||||
app_state[:environment] ||= Mash.new
|
||||
end
|
||||
end
|
||||
|
||||
module Provider
|
||||
include Poise::Provider
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application/resources'
|
|
@ -1,24 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
# Base exception class for poise-application errors.
|
||||
#
|
||||
# @since 5.0.0
|
||||
class Error < Exception
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application/resources/application'
|
||||
require 'poise_application/resources/application_cookbook_file'
|
||||
require 'poise_application/resources/application_directory'
|
||||
require 'poise_application/resources/application_file'
|
||||
require 'poise_application/resources/application_template'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
# Chef resources and providers for poise-application.
|
||||
#
|
||||
# @since 5.0.0
|
||||
module Resources
|
||||
end
|
||||
end
|
|
@ -1,259 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/dsl/recipe' # On 12.4+ this will pull in chef/dsl/resources.
|
||||
require 'chef/resource'
|
||||
require 'chef/provider'
|
||||
require 'poise'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
module Resources
|
||||
# (see Application::Resource)
|
||||
# @since 5.0.0
|
||||
module Application
|
||||
# An `application` resource to manage application deployment.
|
||||
#
|
||||
# @since 5.0.0
|
||||
# @provides application
|
||||
# @action deploy
|
||||
# @action start
|
||||
# @action stop
|
||||
# @action restart
|
||||
# @action reload
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# git '...'
|
||||
# poise_service 'myapp' do
|
||||
# command '/srv/myapp/main'
|
||||
# end
|
||||
# end
|
||||
class Resource < Chef::Resource
|
||||
include Poise(container: true, container_namespace: false)
|
||||
provides(:application)
|
||||
actions(:deploy, :start, :stop, :restart, :reload)
|
||||
|
||||
# @!attribute path
|
||||
# Application base path.
|
||||
# @return [String]
|
||||
attribute(:path, kind_of: String, name_attribute: true)
|
||||
# @!attribute environment
|
||||
# Environment variables to set for the whole application.
|
||||
# @return [Hash<String, String>]
|
||||
attribute(:environment, kind_of: Hash, default: lazy { Mash.new })
|
||||
# @!attribute owner
|
||||
# System user that will own the application. This can be overriden in
|
||||
# individual subresources.
|
||||
# @return [String]
|
||||
attribute(:owner, kind_of: String)
|
||||
# @!attribute group
|
||||
# System group that will own the application. This can be overriden in
|
||||
# individual subresources.
|
||||
# @return [String]
|
||||
attribute(:group, kind_of: String)
|
||||
# @!attribute action_on_update
|
||||
# Action to run when any subresource is updated. Defaults to `:restart`.
|
||||
# @return [String, Symbol, nil, false]
|
||||
attribute(:action_on_update, kind_of: [Symbol, String, NilClass, FalseClass], default: :restart)
|
||||
# @!attribute action_on_update_immediately
|
||||
# Run the {#action_on_update} notification with `:immediately`.
|
||||
# @return [Boolean]
|
||||
attribute(:action_on_update_immediately, equal_to: [true, false], default: false)
|
||||
|
||||
# Run the DSL rewire when the resource object is created.
|
||||
# @api private
|
||||
def initialize(*args)
|
||||
super
|
||||
_rewire_dsl! if node
|
||||
end
|
||||
|
||||
# Application-specific state values used as a way to communicate between
|
||||
# subresources.
|
||||
#
|
||||
# @return [Mash]
|
||||
# @example
|
||||
# if new_resource.parent && new_resource.parent.app_state['gemfile_path']
|
||||
def app_state
|
||||
@app_state ||= Mash.new(environment: environment)
|
||||
end
|
||||
|
||||
# Override Container#register_subresource to add our action_on_update.
|
||||
#
|
||||
# @api private
|
||||
def register_subresource(resource)
|
||||
super.tap do |added|
|
||||
if added && action_on_update
|
||||
Chef::Log.debug("[#{self}] Registering #{action_on_update_immediately ? 'immediate ' : ''}#{action_on_update} notification from #{resource}")
|
||||
resource.notifies action_on_update.to_sym, self, (action_on_update_immediately ? :immediately : :delayed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Find all resources that need to be rewired. This is anything with a
|
||||
# name starting with application_.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
def _rewire_resources
|
||||
if defined?(Chef::DSL::Resources)
|
||||
# Chef >= 12.4.
|
||||
Chef::DSL::Resources.instance_methods
|
||||
else
|
||||
# Chef < 12.4 >= 12.0.
|
||||
Chef::Resource.descendants.map do |klass|
|
||||
klass.node_map.instance_variable_get(:@map).keys + if klass.dsl_name.include?('::')
|
||||
# Probably not valid.
|
||||
# :nocov:
|
||||
[]
|
||||
# :nocov:
|
||||
else
|
||||
# Needed for things that don't call provides().
|
||||
[klass.dsl_name]
|
||||
end
|
||||
end.flatten
|
||||
end.map {|name| name.to_s }.select {|name| name.start_with?('application_') }.uniq
|
||||
end
|
||||
|
||||
# Find all cookbooks that might contain LWRPs matching our name scheme.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
def _rewire_cookbooks
|
||||
# Run context might be unset during test setup.
|
||||
if run_context
|
||||
run_context.cookbook_collection.keys.select {|cookbook_name| cookbook_name.start_with?('application_') }
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
# Build the mapping of new_name => old_name for each resource to rewire.
|
||||
#
|
||||
# @return [Hash<String, String>]
|
||||
def _rewire_map
|
||||
application_cookbooks = _rewire_cookbooks
|
||||
_rewire_resources.inject({}) do |memo, name|
|
||||
# Grab the resource class to check if it is an LWRP.
|
||||
klass = Chef::Resource.resource_for_node(name.to_sym, node)
|
||||
# Find the part to trim. Check for LWRP first, then just application_.
|
||||
trim = if klass < Chef::Resource::LWRPBase
|
||||
application_cookbooks.find {|cookbook_name| name.start_with?(cookbook_name) && name != cookbook_name } || 'application'
|
||||
else
|
||||
# Non-LWRPs are assumed to have a better name.
|
||||
'application'
|
||||
end
|
||||
# Map trimmed to untrimmed.
|
||||
memo[name[trim.length+1..-1]] = name
|
||||
memo
|
||||
end
|
||||
end
|
||||
|
||||
# Build new DSL methods to implement the foo -> application_foo behavior.
|
||||
#
|
||||
# @return [void]
|
||||
def _rewire_dsl!
|
||||
# Generate stub methods for all the rewiring.
|
||||
_rewire_map.each do |new_name, old_name|
|
||||
# This is defined as a singleton method on self so it looks like
|
||||
# the DSL but is scoped to just this context.
|
||||
define_singleton_method(new_name) do |name=nil, *args, &block|
|
||||
# Store the caller to correct the source_line.
|
||||
created_at = caller[0]
|
||||
public_send(old_name, name, *args) do
|
||||
# Set the declared type to be the native name.
|
||||
self.declared_type = self.class.resource_name
|
||||
# Fix the source location. For Chef 12.4 we could do this with the
|
||||
# declared_at parameter on the initial send.
|
||||
self.source_line = created_at
|
||||
# Run the original block.
|
||||
instance_exec(&block) if block
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Provider for `application`.
|
||||
#
|
||||
# @since 5.0.0
|
||||
# @see Resource
|
||||
# @provides application
|
||||
class Provider < Chef::Provider
|
||||
include Poise
|
||||
provides(:application)
|
||||
|
||||
# `deploy` action for `application`. Creates the application base folder.
|
||||
#
|
||||
# @return [void]
|
||||
def action_deploy
|
||||
notifying_block do
|
||||
directory new_resource.path do
|
||||
owner new_resource.owner
|
||||
group new_resource.group
|
||||
mode '755'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# `start` action for `application`. Proxies to subresources.
|
||||
#
|
||||
# @return [void]
|
||||
def action_start
|
||||
proxy_action(:start)
|
||||
end
|
||||
|
||||
# `stop` action for `application`. Proxies to subresources.
|
||||
#
|
||||
# @return [void]
|
||||
def action_stop
|
||||
proxy_action(:stop)
|
||||
end
|
||||
|
||||
# `restart` action for `application`. Proxies to subresources.
|
||||
#
|
||||
# @return [void]
|
||||
def action_restart
|
||||
proxy_action(:restart)
|
||||
end
|
||||
|
||||
# `reload` action for `application`. Proxies to subresources.
|
||||
#
|
||||
# @return [void]
|
||||
def action_reload
|
||||
proxy_action(:reload)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Proxy an action to any subresources that support it.
|
||||
#
|
||||
# @param action [Symbol] Action to proxy.
|
||||
# @return [void]
|
||||
def proxy_action(action)
|
||||
Chef::Log.debug("[#{new_resource} Running proxied #{action} action")
|
||||
new_resource.subresources.each do |r|
|
||||
begin
|
||||
r.run_action(action) if r.allowed_actions.include?(action)
|
||||
rescue Chef::Exceptions::UnsupportedAction
|
||||
# Don't care, just move on.
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,54 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application/app_file_mixin'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
module Resources
|
||||
# (see ApplicationCookbookFile::Resource)
|
||||
# @since 5.1.0
|
||||
module ApplicationCookbookFile
|
||||
# An `application_cookbook_file` resource to manage Chef cookbook_files inside and
|
||||
# Application cookbook deployment.
|
||||
#
|
||||
# @provides application_cookbook_file
|
||||
# @action create
|
||||
# @action create_if_missing
|
||||
# @action delete
|
||||
# @action touch
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# cookbook_file 'myapp.conf' do
|
||||
# source 'myapp.conf'
|
||||
# end
|
||||
# end
|
||||
class Resource < Chef::Resource::CookbookFile
|
||||
include PoiseApplication::AppFileMixin
|
||||
provides(:application_cookbook_file)
|
||||
actions(:create, :create_if_missing, :delete, :touch)
|
||||
subclass_providers!
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
# For older Chef.
|
||||
@resource_name = :application_cookbook_file
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,50 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application/app_file_mixin'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
module Resources
|
||||
# (see ApplicationDirectory::Resource)
|
||||
# @since 5.1.0
|
||||
module ApplicationDirectory
|
||||
# An `application_directory` resource to manage Chef files inside and
|
||||
# Application cookbook deployment.
|
||||
#
|
||||
# @provides application_directory
|
||||
# @action create
|
||||
# @action delete
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# directory 'logs'
|
||||
# end
|
||||
class Resource < Chef::Resource::Directory
|
||||
include PoiseApplication::AppFileMixin
|
||||
provides(:application_directory)
|
||||
actions(:create, :delete)
|
||||
subclass_providers!
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
# For older Chef.
|
||||
@resource_name = :application_directory
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,54 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application/app_file_mixin'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
module Resources
|
||||
# (see ApplicationFile::Resource)
|
||||
# @since 5.1.0
|
||||
module ApplicationFile
|
||||
# An `application_file` resource to manage Chef files inside and
|
||||
# Application cookbook deployment.
|
||||
#
|
||||
# @provides application_file
|
||||
# @action create
|
||||
# @action create_if_missing
|
||||
# @action delete
|
||||
# @action touch
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# file 'myapp.conf' do
|
||||
# source 'myapp.conf.erb'
|
||||
# end
|
||||
# end
|
||||
class Resource < Chef::Resource::File
|
||||
include PoiseApplication::AppFileMixin
|
||||
provides(:application_file)
|
||||
actions(:create, :create_if_missing, :delete, :touch)
|
||||
subclass_providers!
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
# For older Chef.
|
||||
@resource_name = :application_file
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,54 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application/app_file_mixin'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
module Resources
|
||||
# (see ApplicationTemplate::Resource)
|
||||
# @since 5.1.0
|
||||
module ApplicationTemplate
|
||||
# An `application_template` resource to manage Chef templates inside and
|
||||
# Application cookbook deployment.
|
||||
#
|
||||
# @provides application_template
|
||||
# @action create
|
||||
# @action create_if_missing
|
||||
# @action delete
|
||||
# @action touch
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# template 'myapp.conf' do
|
||||
# source 'myapp.conf.erb'
|
||||
# end
|
||||
# end
|
||||
class Resource < Chef::Resource::Template
|
||||
include PoiseApplication::AppFileMixin
|
||||
provides(:application_template)
|
||||
actions(:create, :create_if_missing, :delete, :touch)
|
||||
subclass_providers!
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
# For older Chef.
|
||||
@resource_name = :application_template
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,116 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/resource'
|
||||
require 'chef/provider'
|
||||
require 'poise/utils'
|
||||
require 'poise_service/service_mixin'
|
||||
require 'poise_service/utils'
|
||||
|
||||
require 'poise_application/app_mixin'
|
||||
require 'poise_application/utils'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
# Mixin for application services. This is any resource that will be part of
|
||||
# an application deployment and involves running a persistent service.
|
||||
#
|
||||
# @api public
|
||||
# @since 5.0.0
|
||||
# @example
|
||||
# module MyApp
|
||||
# class Resource < Chef::Resource
|
||||
# include Poise
|
||||
# provides(:my_app)
|
||||
# include PoiseApplication::ServiceMixin
|
||||
# end
|
||||
#
|
||||
# class Provider < Chef::Provider
|
||||
# include Poise
|
||||
# provides(:my_app)
|
||||
# include PoiseApplication::ServiceMixin
|
||||
#
|
||||
# def action_enable
|
||||
# notifying_block do
|
||||
# template '/etc/myapp.conf' do
|
||||
# # ...
|
||||
# end
|
||||
# end
|
||||
# super
|
||||
# end
|
||||
#
|
||||
# def service_options(r)
|
||||
# super
|
||||
# r.command('myapp --serve')
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
module ServiceMixin
|
||||
include Poise::Utils::ResourceProviderMixin
|
||||
|
||||
# Mixin for application service resources.
|
||||
#
|
||||
# @see ServiceMixin
|
||||
module Resource
|
||||
include PoiseService::ServiceMixin::Resource
|
||||
include PoiseApplication::AppMixin::Resource
|
||||
|
||||
module ClassMethods
|
||||
# @api private
|
||||
def included(klass)
|
||||
super
|
||||
klass.extend(ClassMethods)
|
||||
klass.class_exec do
|
||||
attribute(:path, kind_of: String, name_attribute: true)
|
||||
# Redefines from the PoiseService version so we get a better default.
|
||||
attribute(:service_name, kind_of: String, default: lazy { PoiseService::Utils.parse_service_name(path) })
|
||||
attribute(:user, kind_of: [String, Integer], default: lazy { parent ? parent.owner : 'root' })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
extend ClassMethods
|
||||
end
|
||||
|
||||
# Mixin for application service providers.
|
||||
#
|
||||
# @see ServiceMixin
|
||||
module Provider
|
||||
include PoiseService::ServiceMixin::Provider
|
||||
include PoiseApplication::AppMixin::Provider
|
||||
|
||||
private
|
||||
|
||||
# Abstract hook to set parameters on {#service_resource} when it is
|
||||
# created. This is required to set at least `resource.command`.
|
||||
#
|
||||
# @api public
|
||||
# @param resource [Chef::Resource] Resource instance to set parameters on.
|
||||
# @return [void]
|
||||
# @example
|
||||
# def service_options(resource)
|
||||
# super
|
||||
# resource.command('myapp --serve')
|
||||
# end
|
||||
def service_options(resource)
|
||||
super
|
||||
resource.directory(new_resource.path)
|
||||
resource.user(new_resource.user)
|
||||
resource.environment.update(new_resource.app_state_environment) if new_resource.parent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,51 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'etc'
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
# Utility methods for PoiseApplication.
|
||||
#
|
||||
# @api public
|
||||
# @since 5.0.0
|
||||
module Utils
|
||||
# Methods are also available as module-level methods as well as a mixin.
|
||||
extend self
|
||||
|
||||
# Try to find the primary group name for a given user.
|
||||
#
|
||||
# @param user [String, Integer] User to check, if given as an integer this
|
||||
# is used as a UID, otherwise it is the username.
|
||||
# @return [String]
|
||||
# @example
|
||||
# attribute(:group, kind_of: [String, Integer], default: lazy { PoiseApplication::Utils.primary_group_for(user) })
|
||||
def primary_group_for(user)
|
||||
# Force a reload in case any users were created earlier in the run.
|
||||
Etc.endpwent
|
||||
Etc.endgrent
|
||||
user = if user.is_a?(Integer)
|
||||
Etc.getpwuid(user)
|
||||
else
|
||||
Etc.getpwnam(user.to_s)
|
||||
end
|
||||
Etc.getgrgid(user.gid).name
|
||||
rescue ArgumentError
|
||||
# One of the get* calls exploded. ¯\_(ツ)_/¯
|
||||
user.to_s
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseApplication
|
||||
VERSION = '5.2.0'
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
|
||||
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
|
||||
require "poise_application/cheftie"
|
File diff suppressed because one or more lines are too long
|
@ -1,10 +0,0 @@
|
|||
# Application_Git Changelog
|
||||
|
||||
## v1.1.0
|
||||
|
||||
* [#2](https://github.com/poise/application_git/issues/2) – Inherit user and group values from the parent `application` resource.
|
||||
* [#3](https://github.com/poise/application_git/issues/3) – Fix usage with users created during the current Chef run.
|
||||
|
||||
## v1.0.0
|
||||
|
||||
* Initial release.
|
|
@ -1,108 +0,0 @@
|
|||
# Application_Git Cookbook
|
||||
|
||||
[![Build Status](https://img.shields.io/travis/poise/application_git.svg)](https://travis-ci.org/poise/application_git)
|
||||
[![Gem Version](https://img.shields.io/gem/v/poise-application-git.svg)](https://rubygems.org/gems/poise-application-git)
|
||||
[![Cookbook Version](https://img.shields.io/cookbook/v/application_git.svg)](https://supermarket.chef.io/cookbooks/application_git)
|
||||
[![Coverage](https://img.shields.io/codecov/c/github/poise/application_git.svg)](https://codecov.io/github/poise/application_git)
|
||||
[![Gemnasium](https://img.shields.io/gemnasium/poise/application_git.svg)](https://gemnasium.com/poise/application_git)
|
||||
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
A [Chef](https://www.chef.io/) cookbook to handle deploying code from git when
|
||||
using the [application cookbook](https://github.com/poise/application).
|
||||
|
||||
## Quick Start
|
||||
|
||||
To deploy from a private GitHub repository:
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
git 'git@github.com:example/myapp.git' do
|
||||
deploy_key chef_vault_item('deploy_keys', 'myapp')['key']
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
Chef 12 or newer is required.
|
||||
|
||||
## Resources
|
||||
|
||||
### `application_git`
|
||||
|
||||
The `application_git` resource deploys code from git. It extends the core `git`
|
||||
resource to support deploy keys and disabling strict host key verification.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
git 'git@github.com:example/myapp.git'
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
All actions work the same as the core `git` resource.
|
||||
|
||||
* `:sync` – Clone and checkout the requested revision *(default)*
|
||||
* `:checkout` – Checkout the request revision. If the repository isn't already
|
||||
cloned, this action does nothing.
|
||||
* `:export` – Export the repository without the `.git` folder.
|
||||
|
||||
#### Properties
|
||||
|
||||
All properties from the core `git` resource work the same way with the following
|
||||
additions:
|
||||
|
||||
* `deploy_key` – SSH key to use with git. Can be specified either as a path to
|
||||
key file already created or as a string value containing the key directly.
|
||||
* `strict_ssh` – Enable strict SSH host key checking. *(default: false)*
|
||||
|
||||
### DSL Usage
|
||||
|
||||
The `application_git` resource can be used directly as a replacement for the
|
||||
core `git` resource:
|
||||
|
||||
```ruby
|
||||
application_git '/srv/myapp' do
|
||||
repository 'git@github.com:example/myapp.git'
|
||||
deploy_key chef_vault_item('deploy_keys', 'myapp')['key']
|
||||
end
|
||||
```
|
||||
|
||||
Within the `application` resource, a simplified DSL is available. As with other
|
||||
`application` plugins, the default name of the resource if unspecified is the
|
||||
application path. The following two examples are equivalent:
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
git do
|
||||
repository 'git@github.com:example/myapp.git'
|
||||
end
|
||||
end
|
||||
|
||||
application '/srv/myapp' do
|
||||
git 'git@github.com:example/myapp.git'
|
||||
end
|
||||
```
|
||||
|
||||
## Sponsors
|
||||
|
||||
Development sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).
|
||||
|
||||
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2015-2016, Noah Kantrowitz
|
||||
|
||||
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.
|
|
@ -1,17 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application_git'
|
|
@ -1,21 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application_git/resource'
|
||||
|
||||
|
||||
module PoiseApplicationGit
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application_git/resource'
|
|
@ -1,204 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'zlib'
|
||||
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
require 'poise_application/app_mixin'
|
||||
require 'poise_application/resources/application'
|
||||
|
||||
require 'poise_application_git/safe_string'
|
||||
|
||||
|
||||
module PoiseApplicationGit
|
||||
# An `application_git` resource to clone application code from git.
|
||||
#
|
||||
# @since 1.0.0
|
||||
# @provides application_git
|
||||
# @action sync
|
||||
# @action checkout
|
||||
# @action export
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# git 'git@github.com:example/myapp.git' do
|
||||
# deploy_key data_bag_item('deploy_keys', 'myapp')['key']
|
||||
# end
|
||||
# end
|
||||
class Resource < Chef::Resource::Git
|
||||
include PoiseApplication::AppMixin
|
||||
provides(:application_git)
|
||||
|
||||
# @api private
|
||||
def initialize(*args)
|
||||
super
|
||||
# Because the superclass declares this, we have to as well. Should be
|
||||
# removable at some point when Chef makes everything use the provider
|
||||
# resolver system instead.
|
||||
@resource_name = :application_git
|
||||
@provider = PoiseApplicationGit::Provider
|
||||
# Clear defaults in older versions of Chef.
|
||||
remove_instance_variable(:@group) if instance_variable_defined?(:@group)
|
||||
remove_instance_variable(:@user) if instance_variable_defined?(:@user)
|
||||
end
|
||||
|
||||
# @!attribute group
|
||||
# Group to run git as. Defaults to the application group.
|
||||
# @return [String, Integer, nil, false]
|
||||
attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group })
|
||||
# @!attribute strict_ssh
|
||||
# Enable strict SSH host key checking. Defaults to false.
|
||||
# @return [Boolean]
|
||||
attribute(:strict_ssh, equal_to: [true, false], default: false)
|
||||
# @!attribute user
|
||||
# User to run git as. Defaults to the application owner.
|
||||
# @return [String, Integer, nil, false]
|
||||
attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner })
|
||||
|
||||
# @api private
|
||||
def after_created
|
||||
# Allow using the repository as the name in an application block.
|
||||
if parent && !repository
|
||||
destination(parent.path)
|
||||
repository(name)
|
||||
end
|
||||
end
|
||||
|
||||
# @!attribute deploy_key
|
||||
# SSH deploy key as either a string value or a path to a key file.
|
||||
# @return [String]
|
||||
def deploy_key(val=nil)
|
||||
# Use a SafeString for literal deploy keys so they aren't shown.
|
||||
val = SafeString.new(val) if val && !deploy_key_is_local?(val)
|
||||
set_or_return(:deploy_key, val, kind_of: String)
|
||||
end
|
||||
|
||||
# Default SSH wrapper path.
|
||||
#
|
||||
# @api private
|
||||
# @return [String]
|
||||
def ssh_wrapper_path
|
||||
@ssh_wrapper_path ||= ::File.expand_path("~#{user}/.ssh/ssh_wrapper_#{Zlib.crc32(name)}")
|
||||
end
|
||||
|
||||
# Guess if the deploy key is a local path or literal value.
|
||||
#
|
||||
# @api private
|
||||
# @param key [String, nil] Key value to check. Defaults to self.key.
|
||||
# @return [Boolean]
|
||||
def deploy_key_is_local?(key=nil)
|
||||
key ||= deploy_key
|
||||
key && key[0] == '/'
|
||||
end
|
||||
|
||||
# Path to deploy key.
|
||||
#
|
||||
# @api private
|
||||
# @return [String]
|
||||
def deploy_key_path
|
||||
@deploy_key_path ||= if deploy_key_is_local?
|
||||
deploy_key
|
||||
else
|
||||
::File.expand_path("~#{user}/.ssh/id_deploy_#{Zlib.crc32(name)}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Provider for `application_git`.
|
||||
#
|
||||
# @since 1.0.0
|
||||
# @see Resource
|
||||
# @provides application_git
|
||||
class Provider < Chef::Provider::Git
|
||||
include PoiseApplication::AppMixin
|
||||
provides(:application_git)
|
||||
|
||||
# @api private
|
||||
def initialize(*args)
|
||||
super
|
||||
# Set the SSH wrapper path in a late-binding kind of way. This better
|
||||
# supports situations where the user doesn't exist until Chef converges.
|
||||
new_resource.ssh_wrapper(new_resource.ssh_wrapper_path) if new_resource.deploy_key
|
||||
end
|
||||
|
||||
# @api private
|
||||
def whyrun_supported?
|
||||
false # Just not dealing with this right now
|
||||
end
|
||||
|
||||
# Hack our special login in before load_current_resource runs because that
|
||||
# needs access to the git remote.
|
||||
#
|
||||
# @api private
|
||||
def load_current_resource
|
||||
include_recipe('git')
|
||||
notifying_block do
|
||||
create_dotssh
|
||||
write_deploy_key
|
||||
write_ssh_wrapper
|
||||
end if new_resource.deploy_key
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Create a .ssh folder for the user.
|
||||
#
|
||||
# @return [void]
|
||||
def create_dotssh
|
||||
directory ::File.expand_path("~#{new_resource.user}/.ssh") do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '755'
|
||||
end
|
||||
end
|
||||
|
||||
# Copy the deploy key to a file if needed.
|
||||
#
|
||||
# @return [void]
|
||||
def write_deploy_key
|
||||
# Check if we have a local path or some actual content
|
||||
return if new_resource.deploy_key_is_local?
|
||||
file new_resource.deploy_key_path do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '600'
|
||||
content new_resource.deploy_key
|
||||
sensitive true
|
||||
end
|
||||
end
|
||||
|
||||
# Create the SSH wrapper script.
|
||||
#
|
||||
# @return [void]
|
||||
def write_ssh_wrapper
|
||||
# Write out the GIT_SSH script, it should already be enabled above
|
||||
file new_resource.ssh_wrapper_path do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '700'
|
||||
content %Q{#!/bin/sh\n/usr/bin/env ssh #{'-o "StrictHostKeyChecking=no" ' unless new_resource.strict_ssh}-i "#{new_resource.deploy_key_path}" $@\n}
|
||||
end
|
||||
end
|
||||
|
||||
# Patch back in the `#git` from the git provider. This otherwise conflicts
|
||||
# with the `#git` defined by the DSL, which gets included in such a way
|
||||
# that the DSL takes priority.
|
||||
def git(*args, &block)
|
||||
Chef::Provider::Git.instance_method(:git).bind(self).call(*args, &block)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseApplicationGit
|
||||
# A string that won't be shown in Chef error output
|
||||
class SafeString < String
|
||||
def to_text
|
||||
'"suppressed sensitive value"'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseApplicationGit
|
||||
VERSION = '1.1.0'
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2016, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
|
||||
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
|
||||
require "poise_application_git/cheftie"
|
|
@ -1 +0,0 @@
|
|||
{"name":"application_git","version":"1.1.0","description":"A plugin for poise-application to deploy applications from git.","long_description":"# Application_Git Cookbook\n\n[![Build Status](https://img.shields.io/travis/poise/application_git.svg)](https://travis-ci.org/poise/application_git)\n[![Gem Version](https://img.shields.io/gem/v/poise-application-git.svg)](https://rubygems.org/gems/poise-application-git)\n[![Cookbook Version](https://img.shields.io/cookbook/v/application_git.svg)](https://supermarket.chef.io/cookbooks/application_git)\n[![Coverage](https://img.shields.io/codecov/c/github/poise/application_git.svg)](https://codecov.io/github/poise/application_git)\n[![Gemnasium](https://img.shields.io/gemnasium/poise/application_git.svg)](https://gemnasium.com/poise/application_git)\n[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\nA [Chef](https://www.chef.io/) cookbook to handle deploying code from git when\nusing the [application cookbook](https://github.com/poise/application).\n\n## Quick Start\n\nTo deploy from a private GitHub repository:\n\n```ruby\napplication '/srv/myapp' do\n git 'git@github.com:example/myapp.git' do\n deploy_key chef_vault_item('deploy_keys', 'myapp')['key']\n end\nend\n```\n\n## Requirements\n\nChef 12 or newer is required.\n\n## Resources\n\n### `application_git`\n\nThe `application_git` resource deploys code from git. It extends the core `git`\nresource to support deploy keys and disabling strict host key verification.\n\n```ruby\napplication '/srv/myapp' do\n git 'git@github.com:example/myapp.git'\nend\n```\n\n#### Actions\n\nAll actions work the same as the core `git` resource.\n\n* `:sync` – Clone and checkout the requested revision *(default)*\n* `:checkout` – Checkout the request revision. If the repository isn't already\n cloned, this action does nothing.\n* `:export` – Export the repository without the `.git` folder.\n\n#### Properties\n\nAll properties from the core `git` resource work the same way with the following\nadditions:\n\n* `deploy_key` – SSH key to use with git. Can be specified either as a path to\n key file already created or as a string value containing the key directly.\n* `strict_ssh` – Enable strict SSH host key checking. *(default: false)*\n\n### DSL Usage\n\nThe `application_git` resource can be used directly as a replacement for the\ncore `git` resource:\n\n```ruby\napplication_git '/srv/myapp' do\n repository 'git@github.com:example/myapp.git'\n deploy_key chef_vault_item('deploy_keys', 'myapp')['key']\nend\n```\n\nWithin the `application` resource, a simplified DSL is available. As with other\n`application` plugins, the default name of the resource if unspecified is the\napplication path. The following two examples are equivalent:\n\n```ruby\napplication '/srv/myapp' do\n git do\n repository 'git@github.com:example/myapp.git'\n end\nend\n\napplication '/srv/myapp' do\n git 'git@github.com:example/myapp.git'\nend\n```\n\n## Sponsors\n\nDevelopment sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).\n\nThe Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).\n\n## License\n\nCopyright 2015-2016, Noah Kantrowitz\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","maintainer":"Noah Kantrowitz","maintainer_email":"noah@coderanger.net","license":"Apache 2.0","platforms":{},"dependencies":{"git":">= 0.0.0","poise":"~> 2.0","application":"~> 5.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}}
|
|
@ -1,5 +0,0 @@
|
|||
# Application_Javascript Changelog
|
||||
|
||||
## v1.0.0
|
||||
|
||||
Initial release!
|
|
@ -1,132 +0,0 @@
|
|||
# Application_Javascript Cookbook
|
||||
|
||||
[![Build Status](https://img.shields.io/travis/poise/application_javascript.svg)](https://travis-ci.org/poise/application_javascript)
|
||||
[![Gem Version](https://img.shields.io/gem/v/poise-application-javascript.svg)](https://rubygems.org/gems/poise-application-javascript)
|
||||
[![Cookbook Version](https://img.shields.io/cookbook/v/application_javascript.svg)](https://supermarket.chef.io/cookbooks/application_javascript)
|
||||
[![Coverage](https://img.shields.io/codecov/c/github/poise/application_javascript.svg)](https://codecov.io/github/poise/application_javascript)
|
||||
[![Gemnasium](https://img.shields.io/gemnasium/poise/application_javascript.svg)](https://gemnasium.com/poise/application_javascript)
|
||||
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
A [Chef](https://www.chef.io/) cookbook to deploy server-side JavaScript
|
||||
applications using Node.js or io.js.
|
||||
|
||||
## Quick Start
|
||||
|
||||
To deploy an Express application from git:
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
git 'https://github.com/example/myapp.git'
|
||||
npm_install
|
||||
npm_start
|
||||
end
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
Chef 12 or newer is required.
|
||||
|
||||
## Resources
|
||||
|
||||
### `application_javascript`
|
||||
|
||||
The `application_javascript` resource installs a JavaScript runtime for the
|
||||
deployment.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
javascript '3'
|
||||
end
|
||||
```
|
||||
|
||||
All actions and properties are the same as the [`javascript_runtime` resource](https://github.com/poise/poise-javascript#javascript_runtime).
|
||||
|
||||
### `application_javascript_service`
|
||||
|
||||
The `application_javascript_javascript_service` resource creates a service for a
|
||||
JavaScript command.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
javascript_service 'main.js'
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:enable` – Create, enable and start the service. *(default)*
|
||||
* `:disable` – Stop, disable, and destroy the service.
|
||||
* `:start` – Start the service.
|
||||
* `:stop` – Stop the service.
|
||||
* `:restart` – Stop and then start the service.
|
||||
* `:reload` – Send the configured reload signal to the service.
|
||||
|
||||
#### Properties
|
||||
|
||||
* `command` – Command to run. *(name attribute)*
|
||||
* `path` – Base path for the application. *(default: application path)*
|
||||
* `service_name` – Name of the service to create. *(default: auto-detect)*
|
||||
# `user` – User to run the service as. *(default: application owner)*
|
||||
|
||||
### `application_node_package`
|
||||
|
||||
The `application_node_package` resource installs NPM packages for the deployment.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
node_package 'grunt-cli'
|
||||
end
|
||||
```
|
||||
|
||||
All actions and properties are the same as the [`node_package` resource](https://github.com/poise/poise-javascript#node_package),
|
||||
except that the `group` and `user` properties default to the application-level
|
||||
data if not specified.
|
||||
|
||||
### `application_npm_start`
|
||||
|
||||
The `application_npm_start` resource creates a service for a JavaScript
|
||||
application using `npm start`.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
npm_start
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:enable` – Create, enable and start the service. *(default)*
|
||||
* `:disable` – Stop, disable, and destroy the service.
|
||||
* `:start` – Start the service.
|
||||
* `:stop` – Stop the service.
|
||||
* `:restart` – Stop and then start the service.
|
||||
* `:reload` – Send the configured reload signal to the service.
|
||||
|
||||
#### Properties
|
||||
|
||||
* `path` – Base path for the application. *(default: name attribute)*
|
||||
* `command` – NPM subcommand to run. *(default: start)*
|
||||
* `service_name` – Name of the service to create. *(default: auto-detect)*
|
||||
# `user` – User to run the service as. *(default: application owner)*
|
||||
|
||||
## Sponsors
|
||||
|
||||
Development sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).
|
||||
|
||||
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2015, Noah Kantrowitz
|
||||
|
||||
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.
|
|
@ -1,23 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
autoload :AppMixin, 'poise_application_javascript/app_mixin'
|
||||
autoload :Error, 'poise_application_javascript/error'
|
||||
autoload :Resources, 'poise_application_javascript/resources'
|
||||
autoload :VERSION, 'poise_application_javascript/version'
|
||||
end
|
|
@ -1,67 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise/backports'
|
||||
require 'poise/utils'
|
||||
require 'poise_application/app_mixin'
|
||||
require 'poise_javascript/javascript_command_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
# A helper mixin for Javascript application resources and providers.
|
||||
#
|
||||
# @since 4.0.0
|
||||
module AppMixin
|
||||
include Poise::Utils::ResourceProviderMixin
|
||||
|
||||
# A helper mixin for Javascript application resources.
|
||||
module Resource
|
||||
include PoiseApplication::AppMixin::Resource
|
||||
include PoiseJavascript::JavascriptCommandMixin::Resource
|
||||
|
||||
# @!attribute parent_javascript
|
||||
# Override the #parent_javascript from JavascriptCommandMixin to grok the
|
||||
# application level parent as a default value.
|
||||
# @return [PoiseJavascript::Resources::JavascriptRuntime::Resource, nil]
|
||||
parent_attribute(:javascript, type: :javascript_runtime, optional: true, default: lazy { app_state_javascript.equal?(self) ? nil : app_state_javascript })
|
||||
|
||||
# @attribute app_state_javascript
|
||||
# The application-level Javascript parent.
|
||||
# @return [PoiseJavascript::Resources::JavascriptRuntime::Resource, nil]
|
||||
def app_state_javascript(javascript=Poise::NOT_PASSED)
|
||||
unless javascript == Poise::NOT_PASSED
|
||||
app_state[:javascript] = javascript
|
||||
end
|
||||
app_state[:javascript]
|
||||
end
|
||||
|
||||
# A merged hash of environment variables for both the application state
|
||||
# and parent javascript.
|
||||
#
|
||||
# @return [Hash<String, String>]
|
||||
def app_state_environment_javascript
|
||||
env = app_state_environment
|
||||
env = env.merge(parent_javascript.javascript_environment) if parent_javascript
|
||||
env
|
||||
end
|
||||
end
|
||||
|
||||
# A helper mixin for Javascript application providers.
|
||||
module Provider
|
||||
include PoiseApplication::AppMixin::Provider
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application_javascript/resources'
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application/error'
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
# Base exception class for poise-application-javascript errors.
|
||||
#
|
||||
# @since 1.0.0
|
||||
class Error < PoiseApplication::Error
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_application_javascript/resources/javascript'
|
||||
require 'poise_application_javascript/resources/javascript_execute'
|
||||
require 'poise_application_javascript/resources/javascript_service'
|
||||
require 'poise_application_javascript/resources/node_package'
|
||||
require 'poise_application_javascript/resources/npm_install'
|
||||
require 'poise_application_javascript/resources/npm_start'
|
|
@ -1,64 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_javascript/resources/javascript_runtime'
|
||||
|
||||
require 'poise_application_javascript/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
module Resources
|
||||
# (see Javascript::Resource)
|
||||
# @since 1.0.0
|
||||
module Javascript
|
||||
# An `application_javascript` resource to manage Javascript runtimes
|
||||
# inside an Application cookbook deployment.
|
||||
#
|
||||
# @provides application_javascript
|
||||
# @provides application_javascript_runtime
|
||||
# @action install
|
||||
# @action uninstall
|
||||
# @example
|
||||
# application '/app' do
|
||||
# javascript '3'
|
||||
# end
|
||||
class Resource < PoiseJavascript::Resources::JavascriptRuntime::Resource
|
||||
include PoiseApplicationJavascript::AppMixin
|
||||
provides(:application_javascript)
|
||||
# Need the double javascript for application resource rewriting.
|
||||
provides(:application_javascript_runtime)
|
||||
container_default(false)
|
||||
subclass_providers!
|
||||
|
||||
# We want to run the base class version of this, not the one from the
|
||||
# mixin. HULK SMASH.
|
||||
def npm_binary
|
||||
self.class.superclass.instance_method(:npm_binary).bind(self).call
|
||||
end
|
||||
|
||||
# Set this resource as the app_state's parent javascript.
|
||||
#
|
||||
# @api private
|
||||
def after_created
|
||||
super.tap do |val|
|
||||
app_state_javascript(self)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,88 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_javascript/resources/javascript_execute'
|
||||
|
||||
require 'poise_application_javascript/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
module Resources
|
||||
# (see JavascriptExecute::Resource)
|
||||
# @since 1.0.0
|
||||
module JavascriptExecute
|
||||
# An `application_javascript_execute` resource to run Javascript commands inside an
|
||||
# Application cookbook deployment.
|
||||
#
|
||||
# @provides application_javascript_execute
|
||||
# @action run
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# javascript_execute 'setup.py install'
|
||||
# end
|
||||
class Resource < PoiseJavascript::Resources::JavascriptExecute::Resource
|
||||
include PoiseApplicationJavascript::AppMixin
|
||||
provides(:application_javascript_execute)
|
||||
def initialize(*args)
|
||||
super
|
||||
# Clear some instance variables so my defaults work.
|
||||
remove_instance_variable(:@cwd)
|
||||
remove_instance_variable(:@group)
|
||||
remove_instance_variable(:@user)
|
||||
end
|
||||
|
||||
# #!attribute cwd
|
||||
# Override the default directory to be the app path if unspecified.
|
||||
# @return [String]
|
||||
attribute(:cwd, kind_of: [String, NilClass, FalseClass], default: lazy { parent && parent.path })
|
||||
|
||||
# #!attribute group
|
||||
# Override the default group to be the app group if unspecified.
|
||||
# @return [String, Integer]
|
||||
attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group })
|
||||
|
||||
# #!attribute user
|
||||
# Override the default user to be the app owner if unspecified.
|
||||
# @return [String, Integer]
|
||||
attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner })
|
||||
end
|
||||
|
||||
# The default provider for `application_javascript_execute`.
|
||||
#
|
||||
# @see Resource
|
||||
# @provides application_javascript_execute
|
||||
class Provider < PoiseJavascript::Resources::JavascriptExecute::Provider
|
||||
provides(:application_javascript_execute)
|
||||
|
||||
private
|
||||
|
||||
# Override environment to add the application envivonrment instead.
|
||||
#
|
||||
# @return [Hash]
|
||||
def environment
|
||||
super.tap do |environment|
|
||||
# Don't use the app_state_environment_javascript because we already have
|
||||
# those values in place.
|
||||
environment.update(new_resource.app_state_environment)
|
||||
# Re-apply the resource environment for correct ordering.
|
||||
environment.update(new_resource.environment) if new_resource.environment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,59 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
require 'poise'
|
||||
|
||||
require 'poise_application_javascript/service_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
module Resources
|
||||
# (see JavascriptService::Resource)
|
||||
# @since 1.0.0
|
||||
module JavascriptService
|
||||
class Resource < Chef::Resource
|
||||
include PoiseApplicationJavascript::ServiceMixin
|
||||
provides(:application_javascript_service)
|
||||
|
||||
# @!attribute command
|
||||
# Command to run.
|
||||
# @return [String]
|
||||
attribute(:command, kind_of: String, name_attribute: true)
|
||||
# @!attribute path
|
||||
# Override {PoiseApplicationJavascript::ServiceMixin#path} to make it
|
||||
# not the name_attribute.
|
||||
# @return [String]
|
||||
attribute(:path, kind_of: String, default: lazy { parent && parent.path })
|
||||
end
|
||||
|
||||
class Provider < Chef::Provider
|
||||
include PoiseApplicationJavascript::ServiceMixin
|
||||
provides(:application_javascript_service)
|
||||
|
||||
private
|
||||
|
||||
# (see PoiseApplication::ServiceMixin#service_options)
|
||||
def service_options(resource)
|
||||
super
|
||||
resource.javascript_command(new_resource.command)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,63 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_javascript/resources/node_package'
|
||||
|
||||
require 'poise_application_javascript/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
module Resources
|
||||
# (see NodePackage::Resource)
|
||||
# @since 1.0.0
|
||||
module NodePackage
|
||||
# An `application_node_package` resource to install NPM packages inside
|
||||
# an Application cookbook deployment.
|
||||
#
|
||||
# @provides application_node_package
|
||||
# @action install
|
||||
# @action upgrade
|
||||
# @action remove
|
||||
# @example
|
||||
# application '/app' do
|
||||
# node_package %w{grunt-cli gulp}
|
||||
# end
|
||||
class Resource < PoiseJavascript::Resources::NodePackage::Resource
|
||||
include PoiseApplicationJavascript::AppMixin
|
||||
provides(:application_node_package)
|
||||
subclass_providers!
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
# For older Chef.
|
||||
@resource_name = :application_node_package
|
||||
end
|
||||
|
||||
# #!attribute group
|
||||
# Override the default group to be the app group if unspecified.
|
||||
# @return [String, Integer]
|
||||
attribute(:group, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.group })
|
||||
|
||||
# #!attribute user
|
||||
# Override the default user to be the app owner if unspecified.
|
||||
# @return [String, Integer]
|
||||
attribute(:user, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.owner })
|
||||
|
||||
# @todo This should handle relative paths against parent.path.
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,45 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_javascript/resources/npm_install'
|
||||
|
||||
require 'poise_application_javascript/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
module Resources
|
||||
# (see NpmInstall::Resource)
|
||||
# @since 1.0.0
|
||||
module NpmInstall
|
||||
# An `application_npm_install` resource to install package
|
||||
# dependencies inside an Application cookbook deployment.
|
||||
#
|
||||
# @provides application_npm_install
|
||||
# @action install
|
||||
# @example
|
||||
# application '/app' do
|
||||
# npm_install
|
||||
# end
|
||||
class Resource < PoiseJavascript::Resources::NpmInstall::Resource
|
||||
include PoiseApplicationJavascript::AppMixin
|
||||
provides(:application_npm_install)
|
||||
subclass_providers!
|
||||
|
||||
# @todo This should handle relative paths against parent.path.
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,78 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'shellwords'
|
||||
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
require 'poise'
|
||||
|
||||
require 'poise_application_javascript/service_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
module Resources
|
||||
# (see NpmStart::Resource)
|
||||
# @since 1.0.0
|
||||
module NpmStart
|
||||
# An `application_npm_start` resource to create a service for a Javascript
|
||||
# application using `npm start`.
|
||||
#
|
||||
# @provides application_npm_start
|
||||
# @action enable
|
||||
# @action disable
|
||||
# @action start
|
||||
# @action stop
|
||||
# @action restart
|
||||
# @action reload
|
||||
# @example
|
||||
# application '/app' do
|
||||
# npm_start
|
||||
# end
|
||||
class Resource < Chef::Resource
|
||||
include PoiseApplicationJavascript::ServiceMixin
|
||||
provides(:application_npm_start)
|
||||
|
||||
# @!attribute command
|
||||
# NPM sub-command to run. Defaults to `start`.
|
||||
# @return [String, Array<String>]
|
||||
attribute(:command, kind_of: [String, Array], default: 'start')
|
||||
end
|
||||
|
||||
# The default provider for `application_npm_start`.
|
||||
#
|
||||
# @see Resource
|
||||
# @provides application_npm_start
|
||||
class Provider < Chef::Provider
|
||||
include PoiseApplicationJavascript::ServiceMixin
|
||||
provides(:application_npm_start)
|
||||
|
||||
private
|
||||
|
||||
# (see PoiseApplication::ServiceMixin#service_options)
|
||||
def service_options(resource)
|
||||
super
|
||||
npm_cmd = [new_resource.npm_binary] + Array(new_resource.command)
|
||||
resource.javascript_command(Shellwords.join(npm_cmd))
|
||||
# Make sure node is on $PATH because grrr.
|
||||
new_path = [::File.dirname(new_resource.javascript), (new_resource.app_state_environment_javascript['PATH'] || ENV['PATH']).to_s].join(::File::PATH_SEPARATOR)
|
||||
resource.environment['PATH'] = new_path
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,57 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise/utils'
|
||||
require 'poise_application/service_mixin'
|
||||
require 'poise_languages/utils'
|
||||
|
||||
require 'poise_application_javascript/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
# A helper mixin for Javascript service resources and providers.
|
||||
#
|
||||
# @since 1.0.0
|
||||
module ServiceMixin
|
||||
include Poise::Utils::ResourceProviderMixin
|
||||
|
||||
# A helper mixin for Javascript service resources.
|
||||
module Resource
|
||||
include PoiseApplication::ServiceMixin::Resource
|
||||
include PoiseApplicationJavascript::AppMixin::Resource
|
||||
end
|
||||
|
||||
# A helper mixin for Javascript service providers.
|
||||
module Provider
|
||||
include PoiseApplication::ServiceMixin::Provider
|
||||
include PoiseApplicationJavascript::AppMixin::Provider
|
||||
|
||||
# Set up the service for running Javascript stuff.
|
||||
def service_options(resource)
|
||||
super
|
||||
# Closure scoping for #javascript_command below.
|
||||
self_ = self
|
||||
# Create a new singleton method that fills in `node` for you.
|
||||
resource.define_singleton_method(:javascript_command) do |val|
|
||||
resource.command("#{self_.new_resource.javascript} #{PoiseLanguages::Utils.absolute_command(val, path: self_.new_resource.app_state_environment_javascript['PATH'])}")
|
||||
end
|
||||
# Include env vars as needed.
|
||||
resource.environment.update(new_resource.parent_javascript.javascript_environment) if new_resource.parent_javascript
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
module PoiseApplicationJavascript
|
||||
VERSION = '1.0.0'
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
|
||||
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
|
||||
require "poise_application_javascript/cheftie"
|
File diff suppressed because one or more lines are too long
|
@ -1,43 +0,0 @@
|
|||
# Poise-Archive Changelog
|
||||
|
||||
## v1.5.0
|
||||
|
||||
* Support for 7-Zip unpacking archives on drives other than the system root.
|
||||
* Chef 13 support.
|
||||
|
||||
## v1.4.0
|
||||
|
||||
* Added support for using 7-Zip on Windows.
|
||||
* Fixed handling of `.tar.xz` archives on RHEL and CentOS.
|
||||
|
||||
## v1.3.0
|
||||
|
||||
* Add support for unpacking directly from a URL.
|
||||
|
||||
## v1.2.1
|
||||
|
||||
* [#1](https://github.com/poise/poise-archive/issues/1) Restore file permissions
|
||||
for ZIP files.
|
||||
|
||||
## v1.2.0
|
||||
|
||||
* Add back a tar-binary provider called `GnuTar`, used by default on Linux.
|
||||
* Support for ZIP files via RubyZip.
|
||||
* Full Windows support, including with the `user` and `group` properties.
|
||||
|
||||
## v1.1.2
|
||||
|
||||
* Fix compat with older Ruby that doesn't include `Entry#symlink?`.
|
||||
|
||||
## v1.1.1
|
||||
|
||||
* Fix GNU tar longlink extension.
|
||||
|
||||
## v1.1.0
|
||||
|
||||
* Scrap the original tar implementation in favor of a 100% pure-Ruby solution.
|
||||
This should work on all platforms exactly the same. Hopefully.
|
||||
|
||||
## v1.0.0
|
||||
|
||||
* Initial release!
|
|
@ -1,103 +0,0 @@
|
|||
# Poise-Archive Cookbook
|
||||
|
||||
[![Build Status](https://img.shields.io/travis/poise/poise-archive.svg)](https://travis-ci.org/poise/poise-archive)
|
||||
[![Gem Version](https://img.shields.io/gem/v/poise-archive.svg)](https://rubygems.org/gems/poise-archive)
|
||||
[![Cookbook Version](https://img.shields.io/cookbook/v/poise-archive.svg)](https://supermarket.chef.io/cookbooks/poise-archive)
|
||||
[![Coverage](https://img.shields.io/codecov/c/github/poise/poise-archive.svg)](https://codecov.io/github/poise/poise-archive)
|
||||
[![Gemnasium](https://img.shields.io/gemnasium/poise/poise-archive.svg)](https://gemnasium.com/poise/poise-archive)
|
||||
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
A [Chef](https://www.chef.io/) cookbook to unpack file archives.
|
||||
|
||||
It supports `.tar`, `.tar.gz`, `.tar.bz2`, and `.zip` archive files.
|
||||
|
||||
## Quick Start
|
||||
|
||||
To download an unpack and archive:
|
||||
|
||||
```ruby
|
||||
poise_archive 'https://example.com/myapp.tgz' do
|
||||
destination '/opt/myapp'
|
||||
end
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
Chef 12.1 or newer is required.
|
||||
|
||||
## Platforms
|
||||
|
||||
This cookbook supports all platforms (including Windows) but some Unix platforms
|
||||
(Solaris, AIX) may see very slow tar file unpacking when using the pure-Ruby fallback
|
||||
implementation.
|
||||
|
||||
## Resources
|
||||
|
||||
### `poise_archive`
|
||||
|
||||
The `poise_archive` resource unpacks file archives.
|
||||
|
||||
```ruby
|
||||
poise_archive '/tmp/myapp-1.2.0.tar' do
|
||||
destination '/srv/myapp-1.2.0'
|
||||
end
|
||||
```
|
||||
|
||||
A URL can also be passed as the source path, optionally with extra properties to
|
||||
be merged with `source_properties`.
|
||||
|
||||
```ruby
|
||||
poise_archive 'http://example.com/myapp-1.2.0.zip' do
|
||||
destination '/srv/myapp-1.2.0'
|
||||
end
|
||||
|
||||
poise_archive ['http://example.com/myapp-1.2.0.zip', {headers: {'Authentication' => '...'}}] do
|
||||
destination '/srv/myapp-1.2.0'
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:unpack` – Unpack the archive. *(default)*
|
||||
|
||||
#### Properties
|
||||
|
||||
* `path` – Path to the archive. If relative, it is taken as a file inside
|
||||
`Chef::Config[:file_cache_path]`. If a URL, it is downloaded to a cache file
|
||||
first. *(name attribute)*
|
||||
* `destination` – Path to unpack the archive to. If not specified, the path of
|
||||
the archive without the file extension is used. Required when unpacking from
|
||||
a URL. *(default: auto)*
|
||||
* `group` – Group to run the unpack as.
|
||||
* `keep_existing` – Keep existing files in the destination directory when
|
||||
unpacking. *(default: false)*
|
||||
* `source_properties` – Property key/value pairs to be applied to the
|
||||
`remote_file` file resource when downloading a URL. *(default: {retries: 5})*
|
||||
* `strip_components` – Number of intermediary directories to skip when
|
||||
unpacking. Works like GNU tar's `--strip-components`. *(default: 1)*
|
||||
* `user` – User to run the unpack as.
|
||||
|
||||
## Sponsors
|
||||
|
||||
Development sponsored by [Bloomberg](http://www.bloomberg.com/company/technology/).
|
||||
|
||||
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2016-2017, Noah Kantrowitz
|
||||
|
||||
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.
|
||||
|
||||
BZip2 implementation is based on RBzip2. Copyright Sebastian Staudt, Brian Lopez.
|
||||
RBzip2 code used under the terms of the new BSD license.
|
|
@ -1,18 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
default['poise-archive']['seven_zip']['version'] = '16.04'
|
||||
default['poise-archive']['seven_zip']['url'] = 'http://www.7-zip.org/a/7z%{version_tag}%{arch_tag}.exe'
|
|
@ -1,21 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
autoload :Resources, 'poise_archive/resources'
|
||||
autoload :VERSION, 'poise_archive/version'
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/platform/provider_priority_map'
|
||||
|
||||
require 'poise_archive/archive_providers/gnu_tar'
|
||||
require 'poise_archive/archive_providers/seven_zip'
|
||||
require 'poise_archive/archive_providers/tar'
|
||||
require 'poise_archive/archive_providers/zip'
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
# Providers for the poise_archive resource.
|
||||
#
|
||||
# @since 1.0.0
|
||||
module ArchiveProviders
|
||||
# Set up priority maps
|
||||
Chef::Platform::ProviderPriorityMap.instance.priority(:poise_archive, [
|
||||
PoiseArchive::ArchiveProviders::Zip,
|
||||
PoiseArchive::ArchiveProviders::GnuTar,
|
||||
PoiseArchive::ArchiveProviders::SevenZip,
|
||||
PoiseArchive::ArchiveProviders::Tar,
|
||||
])
|
||||
end
|
||||
end
|
|
@ -1,132 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'fileutils'
|
||||
|
||||
require 'chef/provider'
|
||||
require 'poise'
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
module ArchiveProviders
|
||||
# The provider base class for `poise_archive`.
|
||||
#
|
||||
# @see PoiseArchive::Resources::PoiseArchive::Resource
|
||||
# @provides poise_archive
|
||||
class Base < Chef::Provider
|
||||
include Poise
|
||||
|
||||
# Set the file extension this provider will handle.
|
||||
#
|
||||
# @param match [RegExp] Regular expression to match against the archive
|
||||
# file name.
|
||||
# @return [void]
|
||||
# @example
|
||||
# class MyProvider < Base
|
||||
# provides_extension(/\.hqx$/)
|
||||
# end
|
||||
def self.provides_extension(match)
|
||||
provides(:poise_archive)
|
||||
@provides_extension = match
|
||||
end
|
||||
|
||||
# Override normal provider resolution to also check file extension if one
|
||||
# was specified in the provider.
|
||||
#
|
||||
# @api private
|
||||
def self.provides?(node, resource)
|
||||
super && (!@provides_extension || @provides_extension.match(resource.path))
|
||||
end
|
||||
|
||||
# `unpack` action for `poise_archive`.
|
||||
#
|
||||
# @return [void]
|
||||
def action_unpack
|
||||
if new_resource.is_url?
|
||||
download_resource = download_file
|
||||
# Check if the download resource updated, if not don't run the rest
|
||||
# of the unpack for idempotence. I could also check
|
||||
# new_resource.updated? but this seems more future proof.
|
||||
return if !download_resource.updated_by_last_action?
|
||||
end
|
||||
converge_by("unpack archive #{new_resource.path} to #{new_resource.destination}") do
|
||||
notifying_block do
|
||||
create_directory
|
||||
end
|
||||
empty_directory
|
||||
unpack_archive
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Download the source file to a cache path.
|
||||
#
|
||||
# @return [Chef::Resource]
|
||||
def download_file
|
||||
# resource_state used for closure breaking on the notifying block.
|
||||
resource_state = []
|
||||
notifying_block do
|
||||
# TODO handle cookbook:// for cookbook_file "downloads".
|
||||
resource_state << remote_file(new_resource.absolute_path) do
|
||||
source new_resource.path
|
||||
retries 5 # As a default, could be overridden by source_properties.
|
||||
new_resource.merged_source_properties.each do |key, value|
|
||||
send(key, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
# Return the download resource for state tracking.
|
||||
resource_state.first
|
||||
end
|
||||
|
||||
# Make sure the destination directory exists.
|
||||
#
|
||||
# @return [void]
|
||||
def create_directory
|
||||
directory new_resource.destination do
|
||||
group new_resource.group if new_resource.group
|
||||
owner new_resource.user if new_resource.user
|
||||
# There is explicitly no mode being set here. If a non-default mode
|
||||
# is needed, you should manage that outside of poise_archive.
|
||||
end
|
||||
end
|
||||
|
||||
# Remove all existing content from the destination so we can unpack the
|
||||
# new content.
|
||||
#
|
||||
# @return [void]
|
||||
def empty_directory
|
||||
# If you want to keep it, not my problem.
|
||||
return if new_resource.keep_existing
|
||||
dest = new_resource.destination
|
||||
Dir.entries(dest).each do |entry|
|
||||
next if entry == '.' || entry == '..'
|
||||
FileUtils.remove_entry_secure(::File.join(dest, entry))
|
||||
end
|
||||
end
|
||||
|
||||
# Run the provider-specific unpack behavior.
|
||||
#
|
||||
# @abstract
|
||||
# @return [void]
|
||||
def unpack_archive
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,88 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'fileutils'
|
||||
require 'tmpdir'
|
||||
|
||||
require 'poise_archive/archive_providers/base'
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
module ArchiveProviders
|
||||
# The `gnu_tar` provider class for `poise_archive` to install from TAR
|
||||
# archives using GNU's tar executable.
|
||||
#
|
||||
# @see PoiseArchive::Resources::PoiseArchive::Resource
|
||||
# @provides poise_archive
|
||||
class GnuTar < Base
|
||||
provides_extension(/\.t(ar|gz|bz|xz)/)
|
||||
|
||||
# Only use this if we are on Linux. Everyone else gets the slow Ruby code.
|
||||
#
|
||||
# @api private
|
||||
def self.provides?(node, _resource)
|
||||
super && node['os'] == 'linux'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unpack_archive
|
||||
notifying_block do
|
||||
install_prereqs
|
||||
end
|
||||
unpack_tar
|
||||
end
|
||||
|
||||
# Install any needed prereqs.
|
||||
#
|
||||
# @return [void]
|
||||
def install_prereqs
|
||||
utils = ['tar']
|
||||
utils << 'bzip2' if new_resource.absolute_path =~ /\.t?bz/
|
||||
if new_resource.absolute_path =~ /\.t?xz/
|
||||
xz_package = node.value_for_platform_family(
|
||||
debian: 'xz-utils',
|
||||
rhel: 'xz',
|
||||
)
|
||||
utils << xz_package if xz_package
|
||||
end
|
||||
# This is a resource.
|
||||
package utils
|
||||
end
|
||||
|
||||
# Unpack the archive and process `strip_components`.
|
||||
#
|
||||
# @return [void]
|
||||
def unpack_tar
|
||||
# Build the tar command.
|
||||
cmd = %w{tar}
|
||||
cmd << "--strip-components=#{new_resource.strip_components}" if new_resource.strip_components && new_resource.strip_components > 0
|
||||
cmd << if new_resource.absolute_path =~ /\.t?gz/
|
||||
'-xzvf'
|
||||
elsif new_resource.absolute_path =~ /\.t?bz/
|
||||
'-xjvf'
|
||||
elsif new_resource.absolute_path =~ /\.t?xz/
|
||||
'-xJvf'
|
||||
else
|
||||
'-xvf'
|
||||
end
|
||||
cmd << new_resource.absolute_path
|
||||
poise_shell_out!(cmd, cwd: new_resource.destination, group: new_resource.group, user: new_resource.user)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,183 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'fileutils'
|
||||
require 'tmpdir'
|
||||
|
||||
|
||||
require 'poise_archive/archive_providers/base'
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
module ArchiveProviders
|
||||
# The `seven_zip` provider class for `poise_archive` to upack archives
|
||||
# using 7-Zip.
|
||||
#
|
||||
# @since 1.4.0
|
||||
# @see PoiseArchive::Resources::PoiseArchive::Resource
|
||||
# @provides poise_archive
|
||||
class SevenZip < Base
|
||||
provides_extension(/\.(t(ar|gz|bz|xz)|zip|7z)/)
|
||||
|
||||
# Only works on Windows, because use less silly things elsewhere.
|
||||
#
|
||||
# @api private
|
||||
def self.provides?(node, _resource)
|
||||
super && node['platform_family'] == 'windows'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unpack_archive
|
||||
notifying_block do
|
||||
install_seven_zip
|
||||
end
|
||||
# Create a temp directory to unpack in to. Do I want to try and force
|
||||
# this to be on the same filesystem as the target?
|
||||
self.class.mktmpdir do |tmpdir|
|
||||
unpack_using_seven_zip(tmpdir)
|
||||
chown_files(tmpdir) if new_resource.user || new_resource.group
|
||||
move_files(tmpdir)
|
||||
end
|
||||
end
|
||||
|
||||
# Install 7-Zip to a cache folder.
|
||||
#
|
||||
# @api private
|
||||
# @return [void]
|
||||
def install_seven_zip
|
||||
url = seven_zip_url
|
||||
path = "#{Chef::Config[:file_cache_path]}/#{url.split(/\//).last}"
|
||||
|
||||
install = execute "#{windows_path(path)} /S /D=#{seven_zip_home}" do
|
||||
action :nothing
|
||||
end
|
||||
|
||||
remote_file path do
|
||||
source url
|
||||
notifies :run, install, :immediately
|
||||
end
|
||||
end
|
||||
|
||||
# Unpack the whole archive to a temp directory.
|
||||
#
|
||||
# @api private
|
||||
# @param tmpdir [String] Temp directory to unpack to.
|
||||
# @return [void]
|
||||
def unpack_using_seven_zip(tmpdir)
|
||||
if new_resource.absolute_path =~ /\.t(ar\.)?(gz|bz(2)?|xz)$/
|
||||
# 7-Zip doesn't know to unpack both levels of the archive on its own
|
||||
# so we need to handle this more explicitly.
|
||||
shell_out!("#{seven_zip_home}\\7z.exe x -so \"#{windows_path(new_resource.absolute_path)}\" | #{seven_zip_home}\\7z.exe x -si -ttar -o\"#{windows_path(tmpdir)}\"")
|
||||
else
|
||||
shell_out!("#{seven_zip_home}\\7z.exe x -o\"#{windows_path(tmpdir)}\" \"#{windows_path(new_resource.absolute_path)}\"")
|
||||
end
|
||||
end
|
||||
|
||||
# Fix file ownership if requested.
|
||||
#
|
||||
# @api private
|
||||
# @param tmpdir [String] Temp directory to change ownership in.
|
||||
# @return [void]
|
||||
def chown_files(tmpdir)
|
||||
notifying_block do
|
||||
Dir["#{tmpdir}/**/*"].each do |path|
|
||||
declare_resource(::File.directory?(path) ? :directory : :file, path) do
|
||||
owner new_resource.user if new_resource.user
|
||||
group new_resource.group if new_resource.group
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Manual implementation of --strip-components since 7-Zip doesn't support
|
||||
# it internally.
|
||||
#
|
||||
# @api private
|
||||
# @param tmpdir [String] Temp directory to move from.
|
||||
# @return [void]
|
||||
def move_files(tmpdir)
|
||||
entries_at_depth(tmpdir, new_resource.strip_components).each do |source|
|
||||
target = ::File.join(new_resource.destination, ::File.basename(source))
|
||||
FileUtils.mv(source, target, secure: true)
|
||||
end
|
||||
end
|
||||
|
||||
# Compute the URL to download the 7-Zip installer from.
|
||||
#
|
||||
# @api private
|
||||
# @return [String]
|
||||
def seven_zip_url
|
||||
node['poise-archive']['seven_zip']['url'] % {
|
||||
version: node['poise-archive']['seven_zip']['version'],
|
||||
version_tag: node['poise-archive']['seven_zip']['version'].gsub(/\./, ''),
|
||||
arch: node['kernel']['machine'],
|
||||
arch_tag: node['kernel']['machine'] == 'x86_64' ? '-x64' : '',
|
||||
}
|
||||
end
|
||||
|
||||
# Path to install 7-Zip in to.
|
||||
#
|
||||
# @api private
|
||||
# @return [String]
|
||||
def seven_zip_home
|
||||
"#{windows_path(Chef::Config[:file_cache_path])}\\seven_zip_#{node['poise-archive']['seven_zip']['version']}"
|
||||
end
|
||||
|
||||
# Flip the slashes in a path because 7z wants "normal" paths.
|
||||
#
|
||||
# @api private
|
||||
# @param path [String] Path to convert.
|
||||
# @return [String]
|
||||
def windows_path(path)
|
||||
path.gsub(/\//, '\\')
|
||||
end
|
||||
|
||||
# Find the absolute paths for entries under a path at a depth.
|
||||
#
|
||||
# @api private
|
||||
# @param path [String] Base path to search under.
|
||||
# @param depth [Integer] Number of intermediary directories to skip.
|
||||
# @return [Array<String>]
|
||||
def entries_at_depth(path, depth)
|
||||
entries = [path]
|
||||
current_depth = 0
|
||||
while current_depth <= depth
|
||||
entries.map! do |ent|
|
||||
if ::File.directory?(ent)
|
||||
Dir.entries(ent).select {|e| e != '.' && e != '..' }.map {|e| ::File.join(ent, e) }
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
entries.flatten!
|
||||
current_depth += 1
|
||||
end
|
||||
entries
|
||||
end
|
||||
|
||||
# Indirection so I can stub this for testing without breaking RSpec.
|
||||
#
|
||||
# @api private
|
||||
def self.mktmpdir(*args, &block)
|
||||
# :nocov:
|
||||
Dir.mktmpdir(*args, &block)
|
||||
# :nocov:
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,158 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'rubygems/package'
|
||||
require 'zlib'
|
||||
|
||||
require 'poise_archive/archive_providers/base'
|
||||
require 'poise_archive/bzip2'
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
module ArchiveProviders
|
||||
# The `tar` provider class for `poise_archive` to install from tar archives.
|
||||
#
|
||||
# @see PoiseArchive::Resources::PoiseArchive::Resource
|
||||
# @provides poise_archive
|
||||
class Tar < Base
|
||||
provides_extension(/\.t(ar|gz|bz)/)
|
||||
|
||||
# Hack that GNU tar uses for paths over 100 bytes.
|
||||
#
|
||||
# @api private
|
||||
# @see #unpack_tar
|
||||
TAR_LONGLINK = '././@LongLink'
|
||||
|
||||
private
|
||||
|
||||
def unpack_archive
|
||||
unpack_tar
|
||||
chown_entries if new_resource.user || new_resource.group
|
||||
end
|
||||
|
||||
# Unpack the archive.
|
||||
#
|
||||
# @return [void]
|
||||
def unpack_tar
|
||||
@tar_entry_paths = []
|
||||
tar_each_with_longlink do |entry|
|
||||
entry_name = entry.full_name.split(/\//).drop(new_resource.strip_components).join('/')
|
||||
# If strip_components wiped out the name, don't process this entry.
|
||||
next if entry_name.empty?
|
||||
dest = ::File.join(new_resource.destination, entry_name)
|
||||
if entry.directory?
|
||||
Dir.mkdir(dest, entry.header.mode)
|
||||
@tar_entry_paths << [:directory, dest]
|
||||
elsif entry.file?
|
||||
::File.open(dest, 'wb', entry.header.mode) do |dest_f|
|
||||
while buf = entry.read(4096)
|
||||
dest_f.write(buf)
|
||||
end
|
||||
end
|
||||
@tar_entry_paths << [:file, dest]
|
||||
elsif entry.header.typeflag == '2' # symlink? is new in Ruby 2.0, apparently.
|
||||
::File.symlink(entry.header.linkname, dest)
|
||||
@tar_entry_paths << [:link, dest]
|
||||
else
|
||||
raise RuntimeError.new("Unknown tar entry type #{entry.header.typeflag.inspect} in #{new_resource.path}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tar_each_with_longlink(&block)
|
||||
entry_name = nil
|
||||
tar_each do |entry|
|
||||
if entry.full_name == TAR_LONGLINK
|
||||
# Stash the longlink name so it will be used for the next entry.
|
||||
entry_name = entry.read.strip
|
||||
# And then skip forward because this isn't a real block.
|
||||
next
|
||||
end
|
||||
# For entries not preceded by a longlink block, use the normal name.
|
||||
entry_name ||= entry.full_name
|
||||
# Make the entry return the correct name.
|
||||
entry.define_singleton_method(:full_name) { entry_name }
|
||||
block.call(entry)
|
||||
# Reset entry_name for the next entry.
|
||||
entry_name = nil
|
||||
end
|
||||
end
|
||||
|
||||
# Sequence the opening, iteration, and closing.
|
||||
#
|
||||
# @param block [Proc] Block to process each tar entry.
|
||||
# @return [void]
|
||||
def tar_each(&block)
|
||||
# In case of extreme weirdness where this happens twice.
|
||||
close_file!
|
||||
open_file!
|
||||
@tar_reader.each(&block)
|
||||
ensure
|
||||
close_file!
|
||||
end
|
||||
|
||||
# Open a file handle of the correct flavor.
|
||||
#
|
||||
# @return [void]
|
||||
def open_file!
|
||||
@raw_file = ::File.open(new_resource.absolute_path, 'rb')
|
||||
@file = case new_resource.absolute_path
|
||||
when /\.tar$/
|
||||
nil # So it uses @raw_file instead.
|
||||
when /\.t?gz/
|
||||
Zlib::GzipReader.wrap(@raw_file)
|
||||
when /\.t?bz/
|
||||
# This can't take a block, hence the gross non-block forms for everything.
|
||||
PoiseArchive::Bzip2::Decompressor.new(@raw_file)
|
||||
else
|
||||
raise RuntimeError.new("Unknown or unsupported file extension for #{new_resource.path}")
|
||||
end
|
||||
@tar_reader = Gem::Package::TarReader.new(@file || @raw_file)
|
||||
end
|
||||
|
||||
# Close all the various file handles.
|
||||
#
|
||||
# @return [void]
|
||||
def close_file!
|
||||
if @tar_reader
|
||||
@tar_reader.close
|
||||
@tar_reader = nil
|
||||
end
|
||||
if @file
|
||||
@file.close
|
||||
@file = nil
|
||||
end
|
||||
if @raw_file
|
||||
@raw_file.close unless @raw_file.closed?
|
||||
@raw_file = nil
|
||||
end
|
||||
end
|
||||
|
||||
def chown_entries
|
||||
paths = @tar_entry_paths
|
||||
notifying_block do
|
||||
paths.each do |type, path|
|
||||
send(type, path) do
|
||||
group new_resource.group
|
||||
owner new_resource.user
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,97 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_archive/archive_providers/base'
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
module ArchiveProviders
|
||||
# The `zip` provider class for `poise_archive` to install from ZIP archives.
|
||||
#
|
||||
# @see PoiseArchive::Resources::PoiseArchive::Resource
|
||||
# @provides poise_archive
|
||||
class Zip < Base
|
||||
provides_extension(/\.zip$/)
|
||||
|
||||
private
|
||||
|
||||
def unpack_archive
|
||||
check_rubyzip
|
||||
unpack_zip
|
||||
chown_entries if new_resource.user || new_resource.group
|
||||
end
|
||||
|
||||
def check_rubyzip
|
||||
require 'zip'
|
||||
rescue LoadError
|
||||
notifying_block do
|
||||
install_rubyzip
|
||||
end
|
||||
require 'zip'
|
||||
end
|
||||
|
||||
def install_rubyzip
|
||||
chef_gem 'rubyzip'
|
||||
end
|
||||
|
||||
def unpack_zip
|
||||
@zip_entry_paths = []
|
||||
::Zip::File.open(new_resource.absolute_path) do |zip_file|
|
||||
zip_file.each do |entry|
|
||||
entry_name = entry.name.split(/\//).drop(new_resource.strip_components).join('/')
|
||||
# If strip_components wiped out the name, don't process this entry.
|
||||
next if entry_name.empty?
|
||||
entry_path = ::File.join(new_resource.destination, entry_name)
|
||||
# Ensure parent directories exist because some ZIP files don't
|
||||
# include those for some reason.
|
||||
ensure_directory(entry_path)
|
||||
entry.extract(entry_path)
|
||||
# Make sure we restore file permissions. RubyZip won't do this
|
||||
# unless we also turn on UID/GID restoration, which we don't want.
|
||||
# Mask filters out setuid and setgid bits because no.
|
||||
::File.chmod(entry.unix_perms & 01777, entry_path) if !node.platform_family?('windows') && entry.unix_perms
|
||||
@zip_entry_paths << [entry.directory? ? :directory : entry.file? ? :file : :link, entry_path]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Make sure all enclosing directories exist before writing a path.
|
||||
#
|
||||
# @param oath [String] Path to check.
|
||||
def ensure_directory(path)
|
||||
base = ::File.dirname(path)
|
||||
unless ::File.exist?(base)
|
||||
ensure_directory(base)
|
||||
Dir.mkdir(base)
|
||||
@zip_entry_paths << [:directory, base]
|
||||
end
|
||||
end
|
||||
|
||||
def chown_entries
|
||||
paths = @zip_entry_paths
|
||||
notifying_block do
|
||||
paths.each do |type, path|
|
||||
send(type, path) do
|
||||
group new_resource.group
|
||||
owner new_resource.user
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
# This code is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the new BSD License.
|
||||
#
|
||||
# Copyright (c) 2013, Sebastian Staudt
|
||||
|
||||
|
||||
module PoiseArchive::Bzip2
|
||||
|
||||
autoload :CRC, 'poise_archive/bzip2/crc'
|
||||
autoload :Constants, 'poise_archive/bzip2/constants'
|
||||
autoload :Decompressor, 'poise_archive/bzip2/decompressor'
|
||||
autoload :IO, 'poise_archive/bzip2/io'
|
||||
autoload :InputData, 'poise_archive/bzip2/input_data'
|
||||
autoload :OutputData, 'poise_archive/bzip2/output_data'
|
||||
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
Copyright (c) 2011, Sebastian Staudt
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,83 +0,0 @@
|
|||
# This code is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the new BSD License.
|
||||
#
|
||||
# Copyright (c) 2011-2013, Sebastian Staudt
|
||||
|
||||
|
||||
module PoiseArchive::Bzip2::Constants
|
||||
|
||||
BASEBLOCKSIZE = 100000
|
||||
MAX_ALPHA_SIZE = 258
|
||||
MAX_CODE_LEN = 23
|
||||
RUNA = 0
|
||||
RUNB = 1
|
||||
N_GROUPS = 6
|
||||
G_SIZE = 50
|
||||
N_ITERS = 4
|
||||
MAX_SELECTORS = (2 + (900000 / G_SIZE))
|
||||
NUM_OVERSHOOT_BYTES = 20
|
||||
|
||||
EOF = 0
|
||||
START_BLOCK_STATE = 1
|
||||
RAND_PART_A_STATE = 2
|
||||
RAND_PART_B_STATE = 3
|
||||
RAND_PART_C_STATE = 4
|
||||
NO_RAND_PART_A_STATE = 5
|
||||
NO_RAND_PART_B_STATE = 6
|
||||
NO_RAND_PART_C_STATE = 7
|
||||
|
||||
RNUMS = [
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 985, 724, 205, 454, 863,
|
||||
491, 741, 242, 949, 214, 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 878, 465, 811, 169, 869,
|
||||
675, 611, 697, 867, 561, 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||
150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 170, 607, 520, 932, 727,
|
||||
476, 693, 425, 174, 647, 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||
909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 641, 801, 220, 162, 819,
|
||||
984, 589, 513, 495, 799, 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||
382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 98, 553, 163, 354, 666,
|
||||
933, 424, 341, 533, 870, 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||
469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 184, 943, 795, 384, 383,
|
||||
461, 404, 758, 839, 887, 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||
951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 652, 934, 970, 447, 318,
|
||||
353, 859, 672, 112, 785, 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||
609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 653, 282, 762, 623, 680,
|
||||
81, 927, 626, 789, 125, 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||
170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 857, 956, 358, 619, 580,
|
||||
124, 737, 594, 701, 612, 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||
944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 344, 805, 988, 739, 511,
|
||||
655, 814, 334, 249, 515, 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||
433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 686, 754, 806, 760, 493,
|
||||
403, 415, 394, 687, 700, 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||
978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 680, 879, 194, 572, 640,
|
||||
724, 926, 56, 204, 700, 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||
297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 134, 108, 571, 364, 631,
|
||||
212, 174, 643, 304, 329, 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||
140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 170, 514, 364, 692, 829,
|
||||
82, 855, 953, 676, 246, 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||
804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 896, 831, 547, 261, 524,
|
||||
462, 293, 465, 502, 56, 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||
768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 61, 688, 793, 644, 986,
|
||||
403, 106, 366, 905, 644, 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||
780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 920, 176, 193, 713, 857,
|
||||
265, 203, 50, 668, 108, 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
936, 638
|
||||
]
|
||||
|
||||
MIN_BLOCK_SIZE = 1
|
||||
MAX_BLOCK_SIZE = 9
|
||||
SETMASK = (1 << 21)
|
||||
CLEARMASK = (~SETMASK)
|
||||
GREATER_ICOST = 15
|
||||
LESSER_ICOST = 0
|
||||
SMALL_THRESH = 20
|
||||
DEPTH_THRESH = 10
|
||||
WORK_FACTOR = 30
|
||||
QSORT_STACK_SIZE = 1000
|
||||
|
||||
INCS = [
|
||||
1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161,
|
||||
2391484
|
||||
]
|
||||
|
||||
end
|
|
@ -1,73 +0,0 @@
|
|||
# This code is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the new BSD License.
|
||||
#
|
||||
# Copyright (c) 2011-2013, Sebastian Staudt
|
||||
|
||||
|
||||
class PoiseArchive::Bzip2::CRC
|
||||
|
||||
CRC32_TABLE = [
|
||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
|
||||
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
||||
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
|
||||
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
||||
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
|
||||
0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
|
||||
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
|
||||
0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
||||
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
|
||||
0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
|
||||
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
|
||||
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
||||
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
|
||||
0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
|
||||
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
|
||||
0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
||||
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
|
||||
0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
|
||||
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
|
||||
0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
||||
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
|
||||
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
|
||||
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
|
||||
0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
||||
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
|
||||
0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
|
||||
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
|
||||
0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
||||
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
|
||||
0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
|
||||
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
|
||||
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
||||
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
|
||||
0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
|
||||
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
|
||||
0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
||||
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
|
||||
0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
|
||||
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
|
||||
0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
||||
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
|
||||
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
|
||||
]
|
||||
|
||||
attr_accessor :global_crc
|
||||
|
||||
def initialize
|
||||
initialize_crc
|
||||
end
|
||||
|
||||
def initialize_crc
|
||||
@global_crc = 0xffffffff
|
||||
end
|
||||
|
||||
def final_crc
|
||||
@global_crc ^ 0xffffffff
|
||||
end
|
||||
|
||||
def update_crc(in_ch)
|
||||
@global_crc = ((@global_crc << 8) & 0xffffffff) ^ CRC32_TABLE[(@global_crc >> 24) ^ in_ch]
|
||||
end
|
||||
|
||||
end
|
|
@ -1,704 +0,0 @@
|
|||
# This code is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the new BSD License.
|
||||
#
|
||||
# Copyright (c) 2011-2013, Sebastian Staudt
|
||||
|
||||
|
||||
class PoiseArchive::Bzip2::Decompressor
|
||||
|
||||
include PoiseArchive::Bzip2::Constants
|
||||
|
||||
def initialize(io)
|
||||
@buff = 0
|
||||
@bytes_read = 0
|
||||
@computed_combined_crc = 0
|
||||
@crc = PoiseArchive::Bzip2::CRC.new
|
||||
@current_char = -1
|
||||
@io = io
|
||||
@live = 0
|
||||
@stored_combined_crc = 0
|
||||
@su_t_pos = 0
|
||||
init
|
||||
end
|
||||
|
||||
def count(read)
|
||||
@bytes_read += read if read != -1
|
||||
end
|
||||
|
||||
# ADDED METHODS
|
||||
def pos
|
||||
@bytes_read
|
||||
end
|
||||
|
||||
def eof?
|
||||
@current_state == EOF
|
||||
end
|
||||
# /ADDED METHODS
|
||||
|
||||
def read(length = nil)
|
||||
raise 'stream closed' if @io.nil?
|
||||
|
||||
if length == 1
|
||||
r = read0
|
||||
count (r < 0 ? -1 : 1)
|
||||
r
|
||||
else
|
||||
r = ''
|
||||
if length == nil
|
||||
while true do
|
||||
b = read0
|
||||
break if b < 0
|
||||
r << b.chr
|
||||
end
|
||||
count r.size # ADDED LINE
|
||||
elsif length > 0
|
||||
length.times do
|
||||
b = read0
|
||||
break if b < 0
|
||||
r << b.chr
|
||||
end
|
||||
count r.size
|
||||
end
|
||||
r
|
||||
end
|
||||
end
|
||||
|
||||
def read0
|
||||
ret_char = @current_char
|
||||
|
||||
if @current_state == RAND_PART_B_STATE
|
||||
setup_rand_part_b
|
||||
elsif @current_state == NO_RAND_PART_B_STATE
|
||||
setup_no_rand_part_b
|
||||
elsif @current_state == RAND_PART_C_STATE
|
||||
setup_rand_part_c
|
||||
elsif @current_state == NO_RAND_PART_C_STATE
|
||||
setup_no_rand_part_c
|
||||
elsif @current_state == EOF
|
||||
return -1
|
||||
else
|
||||
raise 'illegal state'
|
||||
end
|
||||
|
||||
ret_char
|
||||
end
|
||||
|
||||
def make_maps
|
||||
in_use = @data.in_use
|
||||
seq_to_unseq = @data.seq_to_unseq
|
||||
|
||||
n_in_use_shadow = 0
|
||||
|
||||
256.times do |i|
|
||||
if in_use[i]
|
||||
seq_to_unseq[n_in_use_shadow] = i
|
||||
n_in_use_shadow += 1
|
||||
end
|
||||
end
|
||||
|
||||
@n_in_use = n_in_use_shadow
|
||||
end
|
||||
|
||||
def init
|
||||
check_magic
|
||||
|
||||
block_size = @io.read(1).to_i
|
||||
raise 'Illegal block size.' if block_size < 1 || block_size > 9
|
||||
@block_size = block_size
|
||||
|
||||
init_block
|
||||
setup_block
|
||||
end
|
||||
|
||||
def check_magic
|
||||
raise 'Magic number does not match "BZh".' unless @io.read(3) == 'BZh'
|
||||
end
|
||||
|
||||
def init_block
|
||||
magic = [ubyte, ubyte, ubyte, ubyte, ubyte, ubyte]
|
||||
|
||||
if magic == [0x17, 0x72, 0x45, 0x38, 0x50, 0x90]
|
||||
complete
|
||||
elsif magic != [0x31, 0x41, 0x59, 0x26, 0x53, 0x59]
|
||||
@current_state = EOF
|
||||
|
||||
raise 'Bad block header.'
|
||||
else
|
||||
@stored_block_crc = int
|
||||
@block_randomised = bit
|
||||
|
||||
@data = PoiseArchive::Bzip2::InputData.new @block_size if @data.nil?
|
||||
|
||||
get_and_move_to_front_decode
|
||||
|
||||
@crc.initialize_crc
|
||||
@current_state = START_BLOCK_STATE
|
||||
end
|
||||
end
|
||||
|
||||
def end_block
|
||||
@computed_block_crc = @crc.final_crc
|
||||
|
||||
if @stored_block_crc != @computed_block_crc
|
||||
@computed_combined_crc = (@stored_combined_crc << 1) | (@stored_combined_crc >> 31)
|
||||
@computed_combined_crc ^= @stored_block_crc
|
||||
|
||||
raise 'BZip2 CRC error'
|
||||
end
|
||||
|
||||
@computed_combined_crc = (@computed_combined_crc << 1) | (@computed_combined_crc >> 31)
|
||||
@computed_combined_crc ^= @computed_block_crc
|
||||
end
|
||||
|
||||
def complete
|
||||
@stored_combined_crc = int
|
||||
@current_state = EOF
|
||||
@data = nil
|
||||
|
||||
raise 'BZip2 CRC error' if @stored_combined_crc != @computed_combined_crc
|
||||
end
|
||||
|
||||
def close
|
||||
if @io != $stdin
|
||||
@io = nil
|
||||
@data = nil
|
||||
end
|
||||
end
|
||||
|
||||
def r(n)
|
||||
live_shadow = @live
|
||||
buff_shadow = @buff
|
||||
|
||||
if live_shadow < n
|
||||
begin
|
||||
thech = @io.readbyte
|
||||
|
||||
raise 'unexpected end of stream' if thech < 0
|
||||
|
||||
buff_shadow = (buff_shadow << 8) | thech
|
||||
live_shadow += 8
|
||||
end while live_shadow < n
|
||||
|
||||
@buff = buff_shadow
|
||||
end
|
||||
|
||||
@live = live_shadow - n
|
||||
|
||||
(buff_shadow >> (live_shadow - n)) & ((1 << n) - 1)
|
||||
end
|
||||
|
||||
def bit
|
||||
r(1) != 0
|
||||
end
|
||||
|
||||
def ubyte
|
||||
r 8
|
||||
end
|
||||
|
||||
def int
|
||||
(((((r(8) << 8) | r(8)) << 8) | r(8)) << 8) | r(8)
|
||||
end
|
||||
|
||||
def create_decode_tables(limit, base, perm, length, min_len, max_len, alpha_size)
|
||||
pp = 0
|
||||
(min_len..max_len).each do |i|
|
||||
alpha_size.times do |j|
|
||||
if length[j] == i
|
||||
perm[pp] = j
|
||||
pp += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
MAX_CODE_LEN.downto 1 do |i|
|
||||
base[i] = 0
|
||||
limit[i] = 0
|
||||
end
|
||||
|
||||
alpha_size.times do |i|
|
||||
base[length[i] + 1] += 1
|
||||
end
|
||||
|
||||
b = 0
|
||||
1.upto(MAX_CODE_LEN - 1) do |i|
|
||||
b += base[i]
|
||||
base[i] = b
|
||||
end
|
||||
|
||||
vec = 0
|
||||
min_len.upto(max_len) do |i|
|
||||
b = base[i]
|
||||
nb = base[i + 1]
|
||||
vec += nb - b
|
||||
b = nb
|
||||
limit[i] = vec - 1
|
||||
vec = vec << 1
|
||||
end
|
||||
|
||||
(min_len + 1).upto(max_len) do |i|
|
||||
base[i] = ((limit[i - 1] + 1) << 1) - base[i]
|
||||
end
|
||||
end
|
||||
|
||||
def receive_decoding_tables
|
||||
in_use = @data.in_use
|
||||
pos = @data.receive_decoding_tables_pos
|
||||
selector = @data.selector
|
||||
selector_mtf = @data.selector_mtf
|
||||
|
||||
in_use16 = 0
|
||||
|
||||
16.times do |i|
|
||||
in_use16 |= 1 << i if bit
|
||||
end
|
||||
|
||||
255.downto(0) do |i|
|
||||
in_use[i] = false
|
||||
end
|
||||
|
||||
16.times do |i|
|
||||
if (in_use16 & (1 << i)) != 0
|
||||
i16 = i << 4
|
||||
16.times do |j|
|
||||
in_use[i16 + j] = true if bit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
make_maps
|
||||
alpha_size = @n_in_use + 2
|
||||
|
||||
groups = r 3
|
||||
selectors = r 15
|
||||
|
||||
selectors.times do |i|
|
||||
j = 0
|
||||
while bit
|
||||
j += 1
|
||||
end
|
||||
selector_mtf[i] = j
|
||||
end
|
||||
|
||||
groups.downto(0) do |v|
|
||||
pos[v] = v
|
||||
end
|
||||
|
||||
selectors.times do |i|
|
||||
v = selector_mtf[i] & 0xff
|
||||
tmp = pos[v]
|
||||
|
||||
while v > 0 do
|
||||
pos[v] = pos[v -= 1]
|
||||
end
|
||||
|
||||
pos[0] = tmp
|
||||
selector[i] = tmp
|
||||
end
|
||||
|
||||
len = @data.temp_char_array_2d
|
||||
|
||||
groups.times do |t|
|
||||
curr = r 5
|
||||
len_t = len[t]
|
||||
alpha_size.times do |i|
|
||||
while bit
|
||||
curr += bit ? -1 : 1
|
||||
end
|
||||
len_t[i] = curr
|
||||
end
|
||||
@data.temp_char_array_2d[t] = len_t
|
||||
end
|
||||
|
||||
create_huffman_decoding_tables alpha_size, groups
|
||||
end
|
||||
|
||||
def create_huffman_decoding_tables(alpha_size, groups)
|
||||
len = @data.temp_char_array_2d
|
||||
min_lens = @data.min_lens
|
||||
limit = @data.limit
|
||||
base = @data.base
|
||||
perm = @data.perm
|
||||
|
||||
groups.times do |t|
|
||||
min_len = 32
|
||||
max_len = 0
|
||||
len_t = len[t]
|
||||
|
||||
(alpha_size - 1).downto 0 do |i|
|
||||
lent = len_t[i]
|
||||
max_len = lent if lent > max_len
|
||||
min_len = lent if lent < min_len
|
||||
end
|
||||
|
||||
create_decode_tables limit[t], base[t], perm[t], len[t], min_len, max_len, alpha_size
|
||||
min_lens[t] = min_len
|
||||
end
|
||||
end
|
||||
|
||||
def get_and_move_to_front_decode
|
||||
@orig_ptr = r 24
|
||||
receive_decoding_tables
|
||||
|
||||
ll8 = @data.ll8
|
||||
unzftab = @data.unzftab
|
||||
selector = @data.selector
|
||||
seq_to_unseq = @data.seq_to_unseq
|
||||
yy = @data.get_and_move_to_front_decode_yy
|
||||
min_lens = @data.min_lens
|
||||
limit = @data.limit
|
||||
base = @data.base
|
||||
perm = @data.perm
|
||||
limit_last = @block_size * BASEBLOCKSIZE
|
||||
|
||||
256.downto(0) do |i|
|
||||
yy[i] = i
|
||||
unzftab[i] = 0
|
||||
end
|
||||
|
||||
group_no = 0
|
||||
group_pos = G_SIZE - 1
|
||||
eob = @n_in_use + 1
|
||||
next_sym = get_and_move_to_front_decode0 0
|
||||
buff_shadow = @buff
|
||||
live_shadow = @live
|
||||
last_shadow = -1
|
||||
zt = selector[group_no] & 0xff
|
||||
base_zt = base[zt]
|
||||
limit_zt = limit[zt]
|
||||
perm_zt = perm[zt]
|
||||
min_lens_zt = min_lens[zt]
|
||||
|
||||
while next_sym != eob
|
||||
if (next_sym == RUNA) || (next_sym == RUNB)
|
||||
s = -1
|
||||
|
||||
n = 1
|
||||
while true do
|
||||
if next_sym == RUNA
|
||||
s += n
|
||||
elsif next_sym == RUNB
|
||||
s += n << 1
|
||||
else
|
||||
break
|
||||
end
|
||||
|
||||
if group_pos == 0
|
||||
group_pos = G_SIZE - 1
|
||||
group_no += 1
|
||||
zt = selector[group_no] & 0xff
|
||||
base_zt = base[zt]
|
||||
limit_zt = limit[zt]
|
||||
perm_zt = perm[zt]
|
||||
min_lens_zt = min_lens[zt]
|
||||
else
|
||||
group_pos -= 1
|
||||
end
|
||||
|
||||
zn = min_lens_zt
|
||||
|
||||
while live_shadow < zn
|
||||
thech = @io.readbyte
|
||||
|
||||
raise 'unexpected end of stream' if thech < 0
|
||||
|
||||
buff_shadow = ((buff_shadow << 8) & 0xffffffff) | thech
|
||||
live_shadow += 8
|
||||
end
|
||||
|
||||
zvec = ((buff_shadow >> (live_shadow - zn)) & 0xffffffff) & ((1 << zn) - 1)
|
||||
live_shadow -= zn
|
||||
|
||||
while zvec > limit_zt[zn]
|
||||
zn += 1
|
||||
|
||||
while live_shadow < 1
|
||||
thech = @io.readbyte
|
||||
|
||||
raise 'unexpected end of stream' if thech < 0
|
||||
|
||||
buff_shadow = ((buff_shadow << 8) & 0xffffffff) | thech
|
||||
live_shadow += 8
|
||||
end
|
||||
|
||||
live_shadow -= 1
|
||||
zvec = (zvec << 1) | ((buff_shadow >> live_shadow) & 1)
|
||||
end
|
||||
|
||||
next_sym = perm_zt[zvec - base_zt[zn]]
|
||||
|
||||
n = n << 1
|
||||
end
|
||||
|
||||
ch = seq_to_unseq[yy[0]]
|
||||
unzftab[ch & 0xff] += s + 1
|
||||
|
||||
while s >= 0
|
||||
last_shadow += 1
|
||||
ll8[last_shadow] = ch
|
||||
s -= 1
|
||||
end
|
||||
|
||||
raise 'block overrun' if last_shadow >= limit_last
|
||||
else
|
||||
last_shadow += 1
|
||||
raise 'block overrun' if last_shadow >= limit_last
|
||||
|
||||
tmp = yy[next_sym - 1]
|
||||
unzftab[seq_to_unseq[tmp] & 0xff] += 1
|
||||
ll8[last_shadow] = seq_to_unseq[tmp]
|
||||
|
||||
yy[1, next_sym - 1] = yy[0, next_sym - 1]
|
||||
yy[0] = tmp
|
||||
|
||||
if group_pos == 0
|
||||
group_pos = G_SIZE - 1
|
||||
group_no += 1
|
||||
zt = selector[group_no] & 0xff
|
||||
base_zt = base[zt]
|
||||
limit_zt = limit[zt]
|
||||
perm_zt = perm[zt]
|
||||
min_lens_zt = min_lens[zt]
|
||||
else
|
||||
group_pos -= 1
|
||||
end
|
||||
|
||||
zn = min_lens_zt
|
||||
|
||||
while live_shadow < zn
|
||||
thech = @io.readbyte
|
||||
|
||||
raise 'unexpected end of stream' if thech < 0
|
||||
|
||||
buff_shadow = ((buff_shadow << 8) & 0xffffffff) | thech
|
||||
live_shadow += 8
|
||||
end
|
||||
zvec = (buff_shadow >> (live_shadow - zn)) & ((1 << zn) - 1)
|
||||
live_shadow -= zn
|
||||
|
||||
while zvec > limit_zt[zn]
|
||||
zn += 1
|
||||
while live_shadow < 1
|
||||
thech = @io.readbyte
|
||||
|
||||
raise 'unexpected end of stream' if thech < 0
|
||||
|
||||
buff_shadow = ((buff_shadow << 8) & 0xffffffff) | thech
|
||||
live_shadow += 8
|
||||
end
|
||||
live_shadow -= 1
|
||||
zvec = (zvec << 1) | ((buff_shadow >> live_shadow) & 1)
|
||||
end
|
||||
|
||||
next_sym = perm_zt[zvec - base_zt[zn]]
|
||||
end
|
||||
end
|
||||
|
||||
@last = last_shadow
|
||||
@live = live_shadow
|
||||
@buff = buff_shadow
|
||||
end
|
||||
|
||||
def get_and_move_to_front_decode0(group_no)
|
||||
zt = @data.selector[group_no] & 0xff
|
||||
limit_zt = @data.limit[zt]
|
||||
zn = @data.min_lens[zt]
|
||||
zvec = r zn
|
||||
live_shadow = @live
|
||||
buff_shadow = @buff
|
||||
|
||||
while zvec > limit_zt[zn]
|
||||
zn += 1
|
||||
|
||||
while live_shadow < 1
|
||||
thech = @io.readbyte
|
||||
|
||||
raise 'unexpected end of stream' if thech < 0
|
||||
|
||||
buff_shadow = ((buff_shadow << 8) & 0xffffffff) | thech
|
||||
live_shadow += 8
|
||||
end
|
||||
|
||||
live_shadow -=1
|
||||
zvec = (zvec << 1) | ((buff_shadow >> live_shadow) & 1)
|
||||
end
|
||||
|
||||
@live = live_shadow
|
||||
@buff = buff_shadow
|
||||
|
||||
@data.perm[zt][zvec - @data.base[zt][zn]]
|
||||
end
|
||||
|
||||
def setup_block
|
||||
return if @data.nil?
|
||||
|
||||
cftab = @data.cftab
|
||||
tt = @data.init_tt @last + 1
|
||||
ll8 = @data.ll8
|
||||
cftab[0] = 0
|
||||
cftab[1, 256] = @data.unzftab[0, 256]
|
||||
|
||||
c = cftab[0]
|
||||
1.upto(256) do |i|
|
||||
c += cftab[i]
|
||||
cftab[i] = c
|
||||
end
|
||||
|
||||
last_shadow = @last
|
||||
(last_shadow + 1).times do |i|
|
||||
cftab_i = ll8[i] & 0xff
|
||||
tt[cftab[cftab_i]] = i
|
||||
cftab[cftab_i] += 1
|
||||
end
|
||||
|
||||
raise 'stream corrupted' if @orig_ptr < 0 || @orig_ptr >= tt.size
|
||||
|
||||
@su_t_pos = tt[@orig_ptr]
|
||||
@su_count = 0
|
||||
@su_i2 = 0
|
||||
@su_ch2 = 256
|
||||
|
||||
if @block_randomised
|
||||
@su_r_n_to_go = 0
|
||||
@su_r_t_pos = 0
|
||||
|
||||
setup_rand_part_a
|
||||
else
|
||||
setup_no_rand_part_a
|
||||
end
|
||||
end
|
||||
|
||||
def setup_rand_part_a
|
||||
if @su_i2 <= @last
|
||||
@su_ch_prev = @su_ch2
|
||||
su_ch2_shadow = @data.ll8[@su_t_pos] & 0xff
|
||||
@su_t_pos = @data.tt[@su_t_pos]
|
||||
|
||||
if @su_r_n_to_go == 0
|
||||
@su_r_n_to_go = RNUMS[@su_r_t_pos] - 1
|
||||
@su_r_t_pos += 1
|
||||
@su_r_t_pos = 0 if @su_r_t_pos == 512
|
||||
else
|
||||
@su_r_n_to_go -= 1
|
||||
end
|
||||
|
||||
@su_ch2 = su_ch2_shadow ^= (@su_r_n_to_go == 1) ? 1 : 0
|
||||
@su_i2 += 1
|
||||
@current_char = su_ch2_shadow
|
||||
@current_state = RAND_PART_B_STATE
|
||||
@crc.update_crc su_ch2_shadow
|
||||
else
|
||||
end_block
|
||||
init_block
|
||||
setup_block
|
||||
end
|
||||
end
|
||||
|
||||
def setup_no_rand_part_a
|
||||
if @su_i2 <= @last
|
||||
@su_ch_prev = @su_ch2
|
||||
su_ch2_shadow = @data.ll8[@su_t_pos] & 0xff
|
||||
@su_ch2 = su_ch2_shadow
|
||||
@su_t_pos = @data.tt[@su_t_pos]
|
||||
@su_i2 += 1
|
||||
@current_char = su_ch2_shadow
|
||||
@current_state = NO_RAND_PART_B_STATE
|
||||
@crc.update_crc su_ch2_shadow
|
||||
else
|
||||
@current_state = NO_RAND_PART_A_STATE
|
||||
end_block
|
||||
init_block
|
||||
setup_block
|
||||
end
|
||||
end
|
||||
|
||||
def setup_rand_part_b
|
||||
if @su_ch2 != @su_ch_prev
|
||||
@current_state = RAND_PART_A_STATE
|
||||
@su_count = 1
|
||||
setup_rand_part_a
|
||||
else
|
||||
@su_count += 1
|
||||
if @su_count >= 4
|
||||
@su_z = @data.ll8[@su_t_pos] & 0xff
|
||||
@su_t_pos = @data.tt[@su_t_pos]
|
||||
|
||||
if @su_r_n_to_go == 0
|
||||
@su_r_n_to_go = RNUMS[@su_r_t_pos] - 1
|
||||
@su_r_t_pos += 1
|
||||
@su_r_t_pos = 0 if @su_r_t_pos == 512
|
||||
else
|
||||
@su_r_n_to_go -= 1
|
||||
end
|
||||
|
||||
@su_j2 = 0
|
||||
@current_state = RAND_PART_C_STATE
|
||||
@su_z ^= 1 if @su_r_n_to_go == 1
|
||||
setup_rand_part_c
|
||||
else
|
||||
@current_state = RAND_PART_A_STATE
|
||||
setup_rand_part_a
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup_rand_part_c
|
||||
if @su_j2 < @su_z
|
||||
@current_char = @su_ch2
|
||||
@crc.update_crc @su_ch2
|
||||
@su_j2 += 1
|
||||
else
|
||||
@current_state = RAND_PART_A_STATE
|
||||
@su_i2 += 1
|
||||
@su_count = 0
|
||||
setup_rand_part_a
|
||||
end
|
||||
end
|
||||
|
||||
def setup_no_rand_part_b
|
||||
if @su_ch2 != @su_ch_prev
|
||||
@su_count = 1
|
||||
setup_no_rand_part_a
|
||||
else
|
||||
@su_count += 1
|
||||
if @su_count >= 4
|
||||
@su_z = @data.ll8[@su_t_pos] & 0xff
|
||||
@su_t_pos = @data.tt[@su_t_pos]
|
||||
@su_j2 = 0
|
||||
setup_no_rand_part_c
|
||||
else
|
||||
setup_no_rand_part_a
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup_no_rand_part_c
|
||||
if @su_j2 < @su_z
|
||||
su_ch2_shadow = @su_ch2
|
||||
@current_char = su_ch2_shadow
|
||||
@crc.update_crc su_ch2_shadow
|
||||
@su_j2 += 1
|
||||
@current_state = NO_RAND_PART_C_STATE
|
||||
else
|
||||
@su_i2 += 1
|
||||
@su_count = 0
|
||||
setup_no_rand_part_a
|
||||
end
|
||||
end
|
||||
|
||||
def size
|
||||
if @io.is_a? StringIO
|
||||
@io.size
|
||||
elsif @io.is_a? File
|
||||
@io.stat.size
|
||||
end
|
||||
end
|
||||
|
||||
def uncompressed
|
||||
@last + 1
|
||||
end
|
||||
|
||||
def inspect
|
||||
"#<#{self.class}: @io=#{@io.inspect} size=#{size} uncompressed=#{uncompressed}>"
|
||||
end
|
||||
|
||||
end
|
|
@ -1,43 +0,0 @@
|
|||
# This code is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the new BSD License.
|
||||
#
|
||||
# Copyright (c) 2011-2013, Sebastian Staudt
|
||||
|
||||
|
||||
class PoiseArchive::Bzip2::InputData
|
||||
|
||||
include PoiseArchive::Bzip2::Constants
|
||||
|
||||
attr_reader :base, :cftab, :get_and_move_to_front_decode_yy, :in_use,
|
||||
:limit, :ll8, :min_lens, :perm, :receive_decoding_tables_pos,
|
||||
:selector, :selector_mtf, :seq_to_unseq, :temp_char_array_2d,
|
||||
:unzftab, :tt
|
||||
|
||||
def initialize(block_size)
|
||||
@in_use = Array.new 256, false
|
||||
|
||||
@seq_to_unseq = Array.new 256, 0
|
||||
@selector = Array.new MAX_SELECTORS, 0
|
||||
@selector_mtf = Array.new MAX_SELECTORS, 0
|
||||
|
||||
@unzftab = Array.new 256, 0
|
||||
|
||||
@base = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
|
||||
@limit = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
|
||||
@perm = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
|
||||
@min_lens = Array.new N_GROUPS, 0
|
||||
|
||||
@cftab = Array.new 257, 0
|
||||
@get_and_move_to_front_decode_yy = Array.new 256
|
||||
@temp_char_array_2d = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
|
||||
@receive_decoding_tables_pos = Array.new N_GROUPS, 0
|
||||
|
||||
@ll8 = Array.new block_size * BASEBLOCKSIZE
|
||||
end
|
||||
|
||||
def init_tt(size)
|
||||
@tt = Array.new(size) if @tt.nil? || @tt.size < size
|
||||
@tt
|
||||
end
|
||||
|
||||
end
|
|
@ -1,57 +0,0 @@
|
|||
# This code is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the new BSD License.
|
||||
#
|
||||
# Copyright (c) 2011-2013, Sebastian Staudt
|
||||
|
||||
|
||||
class PoiseArchive::Bzip2::OutputData
|
||||
|
||||
include PoiseArchive::Bzip2::Constants
|
||||
|
||||
attr_reader :block, :ftab, :fmap, :generate_mtf_values_yy, :heap, :in_use,
|
||||
:main_sort_big_done, :main_sort_copy, :main_sort_running_order,
|
||||
:mtf_freq, :parent, :quadrant, :selector, :selector_mtf,
|
||||
:send_mtf_values_code, :send_mtf_values_cost,
|
||||
:send_mtf_values_fave, :send_mtf_values_len,
|
||||
:send_mtf_values_rfreq, :send_mtf_values2_pos,
|
||||
:send_mtf_values4_in_use_16, :sfmap, :stack_dd, :stack_hh,
|
||||
:stack_ll, :unseq_to_seq, :weight
|
||||
|
||||
def initialize(block_size)
|
||||
n = block_size * BASEBLOCKSIZE
|
||||
@block = Array.new n + 1 + NUM_OVERSHOOT_BYTES, 0
|
||||
@fmap = Array.new n, 0
|
||||
@selector = Array.new MAX_SELECTORS
|
||||
@selector_mtf = Array.new MAX_SELECTORS
|
||||
@sfmap = Array.new 2 * n
|
||||
@quadrant = @sfmap
|
||||
|
||||
@in_use = Array.new 256
|
||||
@mtf_freq = Array.new MAX_ALPHA_SIZE, 0
|
||||
@unseq_to_seq = Array.new 256
|
||||
|
||||
@generate_mtf_values_yy = Array.new 256
|
||||
@send_mtf_values_code = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
|
||||
@send_mtf_values_cost = Array.new N_GROUPS
|
||||
@send_mtf_values_fave = Array.new N_GROUPS
|
||||
@send_mtf_values_len = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
|
||||
@send_mtf_values_rfreq = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
|
||||
@send_mtf_values2_pos = Array.new N_GROUPS
|
||||
@send_mtf_values4_in_use_16 = Array.new 16
|
||||
|
||||
@stack_dd = Array.new QSORT_STACK_SIZE
|
||||
@stack_hh = Array.new QSORT_STACK_SIZE
|
||||
@stack_ll = Array.new QSORT_STACK_SIZE
|
||||
|
||||
@main_sort_big_done = Array.new 256
|
||||
@main_sort_copy = Array.new 256
|
||||
@main_sort_running_order = Array.new 256
|
||||
|
||||
@heap = Array.new MAX_ALPHA_SIZE + 2
|
||||
@parent = Array.new MAX_ALPHA_SIZE + 2
|
||||
@weight = Array.new MAX_ALPHA_SIZE + 2
|
||||
|
||||
@ftab = Array.new 65537
|
||||
end
|
||||
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_archive/resources'
|
||||
require 'poise_archive/archive_providers'
|
|
@ -1,26 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_archive/resources/poise_archive'
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
# Chef resources and providers for poise-archive.
|
||||
#
|
||||
# @since 1.0.0
|
||||
module Resources
|
||||
end
|
||||
end
|
|
@ -1,151 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'base64'
|
||||
require 'uri'
|
||||
|
||||
require 'chef/resource'
|
||||
require 'poise'
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
module Resources
|
||||
# (see PoiseArchive::Resource)
|
||||
# @since 1.0.0
|
||||
module PoiseArchive
|
||||
# A `poise_archive` resource to unpack archives.
|
||||
#
|
||||
# @provides poise_archive
|
||||
# @action unpack
|
||||
# @example
|
||||
# poise_archive '/opt/myapp.tgz'
|
||||
# @example Downloading from a URL with options
|
||||
# poise_archive ['http://example.com/myapp.zip', {headers: {'Authentication' => '...'}}] do
|
||||
# destination '/opt/myapp'
|
||||
# end
|
||||
class Resource < Chef::Resource
|
||||
include Poise
|
||||
provides(:poise_archive)
|
||||
actions(:unpack)
|
||||
|
||||
# @!attribute path
|
||||
# Path to the archive. If relative, it is taken as a file inside
|
||||
# `Chef::Config[:file_cache_path]`. Can also be a URL to download the
|
||||
# archive from.
|
||||
# @return [String, Array]
|
||||
attribute(:path, kind_of: String, default: lazy { @raw_name.is_a?(Array) ? @raw_name[0] : name }, required: true)
|
||||
# @!attribute destination
|
||||
# Path to unpack the archive to. If not specified, the path of the
|
||||
# archive without the file extension is used.
|
||||
# @return [String, nil, false]
|
||||
attribute(:destination, kind_of: [String, NilClass, FalseClass], default: lazy { default_destination })
|
||||
# @!attribute group
|
||||
# Group to run the unpack as.
|
||||
# @return [String, Integer, nil, false]
|
||||
attribute(:group, kind_of: [String, Integer, NilClass, FalseClass])
|
||||
# @!attribute keep_existing
|
||||
# Keep existing files in the destination directory when unpacking.
|
||||
# @return [Boolean]
|
||||
attribute(:keep_existing, equal_to: [true, false], default: false)
|
||||
# @!attribute source_properties
|
||||
# Properties to pass through to the underlying download resource if
|
||||
# using one. Merged with the array form of {#name}.
|
||||
# @return [Hash]
|
||||
attribute(:source_properties, option_collector: true, forced_keys: %i{retries})
|
||||
# @!attribute strip_components
|
||||
# Number of intermediary directories to skip when unpacking. Works
|
||||
# like GNU tar's --strip-components.
|
||||
# @return [Integer]
|
||||
attribute(:strip_components, kind_of: Integer, default: 1)
|
||||
# @!attribute user
|
||||
# User to run the unpack as.
|
||||
# @return [String, Integer, nil, false]
|
||||
attribute(:user, kind_of: [String, Integer, NilClass, FalseClass])
|
||||
|
||||
# Alias for the forgetful.
|
||||
# @api private
|
||||
alias_method :owner, :user
|
||||
|
||||
def initialize(name, run_context)
|
||||
@raw_name = name # Capture this before it gets coerced to a string.
|
||||
super
|
||||
end
|
||||
|
||||
# Regexp for URL-like paths.
|
||||
# @api private
|
||||
URL_PATHS = %r{^(\w+:)?//}
|
||||
|
||||
# Check if the source path is a URL.
|
||||
#
|
||||
# @api private
|
||||
# @return [Boolean]
|
||||
def is_url?
|
||||
path =~ URL_PATHS
|
||||
end
|
||||
|
||||
# Expand a relative file path against `Chef::Config[:file_cache_path]`.
|
||||
# For URLs it returns the cache file path.
|
||||
#
|
||||
# @api private
|
||||
# @return [String]
|
||||
def absolute_path
|
||||
if is_url?
|
||||
# Use the last path component without the query string plus the name
|
||||
# of the resource in Base64. This should be both mildly readable and
|
||||
# also unique per invocation.
|
||||
url_part = URI(path).path.split(/\//).last
|
||||
base64_name = Base64.strict_encode64(name).gsub(/\=/, '')
|
||||
::File.join(Chef::Config[:file_cache_path], "#{base64_name}_#{url_part}")
|
||||
else
|
||||
::File.expand_path(path, Chef::Config[:file_cache_path])
|
||||
end
|
||||
end
|
||||
|
||||
# Merge the explicit source properties with the array form of the name.
|
||||
#
|
||||
# @api private
|
||||
# @return [Hash]
|
||||
def merged_source_properties
|
||||
if @raw_name.is_a?(Array) && @raw_name[1]
|
||||
source_properties.merge(@raw_name[1])
|
||||
else
|
||||
source_properties
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Filename components to ignore.
|
||||
# @api private
|
||||
BASENAME_IGNORE = /(\.(t?(ar|gz|bz2?|xz)|zip))+$/
|
||||
|
||||
# Default value for the {#destination} property
|
||||
#
|
||||
# @api private
|
||||
# @return [String]
|
||||
def default_destination
|
||||
if is_url?
|
||||
raise ValueError.new("Destination for URL-based archive #{self} must be specified explicitly")
|
||||
else
|
||||
::File.join(::File.dirname(absolute_path), ::File.basename(path).gsub(BASENAME_IGNORE, ''))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Providers can be found in archive_providers/.
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseArchive
|
||||
VERSION = '1.5.0'
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
#
|
||||
# Copyright 2016-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
|
||||
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
|
||||
require "poise_archive/cheftie"
|
|
@ -1 +0,0 @@
|
|||
{"name":"poise-archive","version":"1.5.0","description":"A Chef cookbook for unpacking file archives like tar and zip.","long_description":"# Poise-Archive Cookbook\n\n[![Build Status](https://img.shields.io/travis/poise/poise-archive.svg)](https://travis-ci.org/poise/poise-archive)\n[![Gem Version](https://img.shields.io/gem/v/poise-archive.svg)](https://rubygems.org/gems/poise-archive)\n[![Cookbook Version](https://img.shields.io/cookbook/v/poise-archive.svg)](https://supermarket.chef.io/cookbooks/poise-archive)\n[![Coverage](https://img.shields.io/codecov/c/github/poise/poise-archive.svg)](https://codecov.io/github/poise/poise-archive)\n[![Gemnasium](https://img.shields.io/gemnasium/poise/poise-archive.svg)](https://gemnasium.com/poise/poise-archive)\n[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\nA [Chef](https://www.chef.io/) cookbook to unpack file archives.\n\nIt supports `.tar`, `.tar.gz`, `.tar.bz2`, and `.zip` archive files.\n\n## Quick Start\n\nTo download an unpack and archive:\n\n```ruby\npoise_archive 'https://example.com/myapp.tgz' do\n destination '/opt/myapp'\nend\n```\n\n## Requirements\n\nChef 12.1 or newer is required.\n\n## Platforms\n\nThis cookbook supports all platforms (including Windows) but some Unix platforms\n(Solaris, AIX) may see very slow tar file unpacking when using the pure-Ruby fallback\nimplementation.\n\n## Resources\n\n### `poise_archive`\n\nThe `poise_archive` resource unpacks file archives.\n\n```ruby\npoise_archive '/tmp/myapp-1.2.0.tar' do\n destination '/srv/myapp-1.2.0'\nend\n```\n\nA URL can also be passed as the source path, optionally with extra properties to\nbe merged with `source_properties`.\n\n```ruby\npoise_archive 'http://example.com/myapp-1.2.0.zip' do\n destination '/srv/myapp-1.2.0'\nend\n\npoise_archive ['http://example.com/myapp-1.2.0.zip', {headers: {'Authentication' => '...'}}] do\n destination '/srv/myapp-1.2.0'\nend\n```\n\n#### Actions\n\n* `:unpack` – Unpack the archive. *(default)*\n\n#### Properties\n\n* `path` – Path to the archive. If relative, it is taken as a file inside\n `Chef::Config[:file_cache_path]`. If a URL, it is downloaded to a cache file\n first. *(name attribute)*\n* `destination` – Path to unpack the archive to. If not specified, the path of\n the archive without the file extension is used. Required when unpacking from\n a URL. *(default: auto)*\n* `group` – Group to run the unpack as.\n* `keep_existing` – Keep existing files in the destination directory when\n unpacking. *(default: false)*\n* `source_properties` – Property key/value pairs to be applied to the\n `remote_file` file resource when downloading a URL. *(default: {retries: 5})*\n* `strip_components` – Number of intermediary directories to skip when\n unpacking. Works like GNU tar's `--strip-components`. *(default: 1)*\n* `user` – User to run the unpack as.\n\n## Sponsors\n\nDevelopment sponsored by [Bloomberg](http://www.bloomberg.com/company/technology/).\n\nThe Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).\n\n## License\n\nCopyright 2016-2017, Noah Kantrowitz\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\nBZip2 implementation is based on RBzip2. Copyright Sebastian Staudt, Brian Lopez.\nRBzip2 code used under the terms of the new BSD license.\n","maintainer":"Noah Kantrowitz","maintainer_email":"noah@coderanger.net","license":"Apache 2.0","platforms":{},"dependencies":{"poise":"~> 2.6"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/poise/poise-archive","issues_url":"https://github.com/poise/poise-archive/issues","chef_version":[["< 14",">= 12.1"]],"ohai_version":[]}
|
|
@ -1,5 +0,0 @@
|
|||
# Poise-Build-Essential Changelog
|
||||
|
||||
## v1.0.0
|
||||
|
||||
* Initial release!
|
|
@ -1,85 +0,0 @@
|
|||
# Poise-Build-Essential Cookbook
|
||||
|
||||
[![Build Status](https://img.shields.io/travis/poise/poise-build-essential.svg)](https://travis-ci.org/poise/poise-build-essential)
|
||||
[![Gem Version](https://img.shields.io/gem/v/poise-build-essential.svg)](https://rubygems.org/gems/poise-build-essential)
|
||||
[![Cookbook Version](https://img.shields.io/cookbook/v/poise-build-essential.svg)](https://supermarket.chef.io/cookbooks/poise-build-essential)
|
||||
[![Coverage](https://img.shields.io/codecov/c/github/poise/poise-build-essential.svg)](https://codecov.io/github/poise/poise-build-essential)
|
||||
[![Gemnasium](https://img.shields.io/gemnasium/poise/poise-build-essential.svg)](https://gemnasium.com/poise/poise-build-essential)
|
||||
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
A [Chef](https://www.chef.io/) cookbook to install a C compiler and build tools..
|
||||
|
||||
## Quick Start
|
||||
|
||||
To install a C compiler:
|
||||
|
||||
```ruby
|
||||
include_recipe 'poise-build-essential'
|
||||
```
|
||||
|
||||
Or to install using a resource and at compile time:
|
||||
|
||||
```ruby
|
||||
poise_build_essential 'build_essential' do
|
||||
action :nothing
|
||||
end.run_action(:install)
|
||||
```
|
||||
|
||||
## Recipes
|
||||
|
||||
* `poise-build-essential::default` – Install a C compiler and build tools.
|
||||
|
||||
## Attributes
|
||||
|
||||
* `node['poise-build-essential']['action']` – Action to use. One of install,
|
||||
upgrade, or remove. *(default: install)*
|
||||
* `node['poise-build-essential']['allow_unsupported_platform']` – Whether or not
|
||||
to raise an error on unsupported platforms. *(default: false)*
|
||||
|
||||
## Resources
|
||||
|
||||
### `poise_build_essential`
|
||||
|
||||
The `poise_build_essential` resource installs a C compiler and build tools.
|
||||
|
||||
```ruby
|
||||
poise_build_essential 'build_essential' do
|
||||
allow_unsupported_platform true
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:install` – Install a C compiler. *(default)*
|
||||
* `:upgrade` – Install a C compiler using `package action :ugprade` rules.
|
||||
* `:remove` – Remove a C compiler.
|
||||
|
||||
#### Properties
|
||||
|
||||
* `allow_unsupported_platform` – Whether or not to raise an error on unsupported
|
||||
platforms. *(default: false)*
|
||||
|
||||
## Sponsors
|
||||
|
||||
Development sponsored by [SAP](https://www.sap.com/).
|
||||
|
||||
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
|
||||
|
||||
## License
|
||||
|
||||
Some code copyright 2008-2017, Chef Software, Inc. Used under the terms of the
|
||||
Apache License, Version 2.0.
|
||||
|
||||
Copyright 2017, Noah Kantrowitz
|
||||
|
||||
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.
|
|
@ -1,21 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# Action to use. One of install, upgrade, or remove.
|
||||
default['poise-build-essential']['action'] = 'install'
|
||||
|
||||
# Whether or not to raise an error on unsupported platforms.
|
||||
default['poise-build-essential']['allow_unsupported_platform'] = false
|
|
@ -1,22 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
autoload :BuildEssentialProviders, 'poise_build_essential/build_essential_providers'
|
||||
autoload :Resources, 'poise_build_essential/resources'
|
||||
autoload :VERSION, 'poise_build_essential/version'
|
||||
end
|
|
@ -1,49 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/platform/provider_priority_map'
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/debian'
|
||||
require 'poise_build_essential/build_essential_providers/freebsd'
|
||||
require 'poise_build_essential/build_essential_providers/mac_os_x'
|
||||
require 'poise_build_essential/build_essential_providers/omnios'
|
||||
require 'poise_build_essential/build_essential_providers/rhel'
|
||||
require 'poise_build_essential/build_essential_providers/smartos'
|
||||
require 'poise_build_essential/build_essential_providers/solaris'
|
||||
require 'poise_build_essential/build_essential_providers/suse'
|
||||
# require 'poise_build_essential/build_essential_providers/windows'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
# Inversion providers for the poise_build_essential resource.
|
||||
#
|
||||
# @since 1.0.0
|
||||
module BuildEssentialProviders
|
||||
# Set up priority maps
|
||||
Chef::Platform::ProviderPriorityMap.instance.priority(:poise_build_essential, [
|
||||
PoiseBuildEssential::BuildEssentialProviders::Debian,
|
||||
PoiseBuildEssential::BuildEssentialProviders::FreeBSD,
|
||||
PoiseBuildEssential::BuildEssentialProviders::MacOSX,
|
||||
PoiseBuildEssential::BuildEssentialProviders::OmniOS,
|
||||
PoiseBuildEssential::BuildEssentialProviders::RHEL,
|
||||
PoiseBuildEssential::BuildEssentialProviders::SmartOS,
|
||||
PoiseBuildEssential::BuildEssentialProviders::Solaris,
|
||||
PoiseBuildEssential::BuildEssentialProviders::SUSE,
|
||||
# PoiseBuildEssential::BuildEssentialProviders::Windows,
|
||||
PoiseBuildEssential::BuildEssentialProviders::Base,
|
||||
])
|
||||
end
|
||||
end
|
|
@ -1,103 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/provider'
|
||||
require 'poise'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# The provider base class for `poise_build_essential`.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class Base < Chef::Provider
|
||||
include Poise
|
||||
provides(:poise_build_essential)
|
||||
|
||||
# The `install` action for the `poise_build_essential` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_install
|
||||
notifying_block do
|
||||
install_build_essential
|
||||
end
|
||||
end
|
||||
|
||||
# The `upgrade` action for the `poise_build_essential` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_upgrade
|
||||
notifying_block do
|
||||
upgrade_build_essential
|
||||
end
|
||||
end
|
||||
|
||||
# The `remove` action for the `poise_build_essential` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_remove
|
||||
notifying_block do
|
||||
remove_build_essential
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Install C compiler and build tools. Must be implemented by subclasses.
|
||||
#
|
||||
# @abstract
|
||||
def install_build_essential
|
||||
unsupported_platform("Unknown platform for poise_build_eseential: #{node['platform']} (#{node['platform_family']})")
|
||||
# Return an array so upgrade/remove also work.
|
||||
[]
|
||||
end
|
||||
|
||||
# Upgrade C compiler and build tools. Must be implemented by subclasses.
|
||||
#
|
||||
# @abstract
|
||||
def upgrade_build_essential
|
||||
install_build_essential.tap do |installed|
|
||||
Array(installed).each {|r| r.action(:upgrade) }
|
||||
end
|
||||
end
|
||||
|
||||
# Uninstall C compiler and build tools. Must be implemented by subclasses.
|
||||
#
|
||||
# @abstract
|
||||
def remove_build_essential
|
||||
install_build_essential.tap do |installed|
|
||||
Array(installed).each {|r| r.action(:remove) }
|
||||
end
|
||||
end
|
||||
|
||||
# Helper method for either warning about an unsupported platform or raising
|
||||
# an exception.
|
||||
#
|
||||
# @api private
|
||||
# @param msg [String] Error message to display.
|
||||
# @return [void]
|
||||
def unsupported_platform(msg)
|
||||
if new_resource.allow_unsupported_platform
|
||||
Chef::Log.warn(msg)
|
||||
else
|
||||
raise RuntimeError.new(msg)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,41 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on Debian platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class Debian < Base
|
||||
provides(:poise_build_essential, platform_family: 'debian')
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
package %w{autoconf binutils-doc bison build-essential flex gettext ncurses-dev}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on FreeBSD platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class FreeBSD < Base
|
||||
provides(:poise_build_essential, platform_family: 'freebsd')
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
pkgs = %w{devel/gmake devel/autoconf devel/m4 devel/gettext}
|
||||
# Only install gcc on freebsd 9.x - 10 uses clang.
|
||||
if node['platform_version'].to_i <= 9
|
||||
pkgs << 'lang/gcc49'
|
||||
end
|
||||
pkgs.map {|name| package name }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on macOS platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class MacOSX < Base
|
||||
provides(:poise_build_essential, platform_family: 'mac_os_x')
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
# This script was graciously borrowed and modified from Tim Sutton's
|
||||
# osx-vm-templates at https://github.com/timsutton/osx-vm-templates/blob/b001475df54a9808d3d56d06e71b8fa3001fff42/scripts/xcode-cli-tools.sh
|
||||
execute 'install XCode Command Line tools' do
|
||||
command <<-EOH
|
||||
# create the placeholder file that's checked by CLI updates' .dist code
|
||||
# in Apple's SUS catalog
|
||||
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
|
||||
# find the CLI Tools update
|
||||
PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
|
||||
# install it
|
||||
softwareupdate -i "$PROD" --verbose
|
||||
# Remove the placeholder to prevent perpetual appearance in the update utility
|
||||
rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
|
||||
EOH
|
||||
not_if 'pkgutil --pkgs=com.apple.pkg.CLTools_Executables'
|
||||
end
|
||||
end
|
||||
|
||||
# (see Base#upgrade_build_essential)
|
||||
def upgrade_build_essential
|
||||
# Make upgrade the same as install on Mac.
|
||||
install_build_essential
|
||||
end
|
||||
|
||||
# (see Base#remove_build_essential)
|
||||
def remove_build_essential
|
||||
# Not sure how to do this, ignoring for now.
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,46 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on OmniOS platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class OmniOS < Base
|
||||
provides(:poise_build_essential, platform_family: 'omnios')
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
# Per OmniOS documentation, the gcc bin dir isn't in the default
|
||||
# $PATH, so add it to the running process environment.
|
||||
# http://omnios.omniti.com/wiki.php/DevEnv
|
||||
ENV['PATH'] = "#{ENV['PATH']}:/opt/gcc-4.7.2/bin"
|
||||
|
||||
%w{developer/gcc48 developer/object-file developer/linker
|
||||
developer/library/lint developer/build/gnu-make system/header
|
||||
system/library/math/header-math}.map {|name| package name }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,46 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on RedHat and Fedora platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class RHEL < Base
|
||||
provides(:poise_build_essential, platform_family: %w{rhel fedora})
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
pkgs = %w{autoconf bison flex gcc gcc-c++ gettext kernel-devel make m4 ncurses-devel patch}
|
||||
# Ensure GCC 4 is available on older pre-6 EL
|
||||
if node['platform_family'] == 'rhel' && node['platform_version'].to_i < 6
|
||||
pkgs += %w{gcc44 gcc44-c++}
|
||||
end
|
||||
package pkgs
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on SmartOS platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class SmartOS < Base
|
||||
provides(:poise_build_essential, platform_family: 'smartos')
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
%w{autoconf binutils build-essential gcc47 gmake pkg-config}.map {|name| package name }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,47 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on Solaris platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class Solaris < Base
|
||||
provides(:poise_build_essential, platform_family: 'solaris2')
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
if node['platform_version'].to_f < 5.11
|
||||
unsupported_platform('poise_build_essential does not support Solaris before 11. You will need to install SUNWbison, SUNWgcc, SUNWggrp, SUNWgmake, and SUNWgtar from the Solaris DVD')
|
||||
return []
|
||||
end
|
||||
|
||||
# lock because we don't use gcc 5 yet.
|
||||
[package('gcc') { version '4.8.2'} ] + \
|
||||
%w{autoconf automake bison gnu-coreutils flex gcc-3 gnu-grep gnu-make
|
||||
gnu-patch gnu-tar make pkg-config ucb}.map {|name| package name }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,43 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on SUSE platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class SUSE < Base
|
||||
provides(:poise_build_essential, platform_family: 'suse')
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
pkgs = %w{autoconf bison flex gcc gcc-c++ kernel-default-devel make m4}
|
||||
if node['platform_version'].to_i < 12
|
||||
pkgs += %w{gcc48 gcc48-c++}
|
||||
end
|
||||
package pkgs
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,68 +0,0 @@
|
|||
#
|
||||
# Copyright 2008-2017, Chef Software, Inc.
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/build_essential_providers/base'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module BuildEssentialProviders
|
||||
# A provider for `poise_build_essential` to install on Windows platforms.
|
||||
#
|
||||
# @see PoiseBuildEssential::Resources::PoiseBuildEssential::Resource
|
||||
# @provides poise_build_essential
|
||||
class Windows < Base
|
||||
provides(:poise_build_essential, platform_family: 'windows')
|
||||
|
||||
private
|
||||
|
||||
# (see Base#install_build_essential)
|
||||
def install_build_essential
|
||||
install_build_essential_packages
|
||||
end
|
||||
|
||||
# (see Base#upgrade_build_essential)
|
||||
def upgrade_build_essential
|
||||
# Upgrade and install are the same on Windows. (?)
|
||||
install_build_essential
|
||||
end
|
||||
|
||||
# (see Base#remove_build_essential)
|
||||
def remove_build_essential
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
# Install MSYS2 packages needed for the build environment.
|
||||
#
|
||||
# @api private
|
||||
# @return [Array<Chef::Resource>]
|
||||
def install_build_essential_packages
|
||||
# TODO This probably won't work on 32-bit right now, fix that.
|
||||
[
|
||||
'base-devel', # Brings down msys based bash/make/awk/patch/stuff.
|
||||
'mingw-w64-x86_64-toolchain', # Puts 64-bit SEH mingw toolchain in msys2\mingw64.
|
||||
'mingw-w64-i686-toolchain' # Puts 32-bit DW2 mingw toolchain in msys2\ming32.
|
||||
].map do |pkg_group|
|
||||
# The pacman package provider doesn't support groups, so going old-school.
|
||||
poise_msys2_execute "pacman --sync #{pkg_group}" do
|
||||
command ['pacman', '--sync', '--noconfirm', '--noprogressbar', '--needed', pkg_group]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/resources'
|
||||
require 'poise_build_essential/build_essential_providers'
|
|
@ -1,26 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_build_essential/resources/poise_build_essential'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
# Chef resources and providers for poise-build-essential.
|
||||
#
|
||||
# @since 1.0.0
|
||||
module Resources
|
||||
end
|
||||
end
|
|
@ -1,48 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/resource'
|
||||
require 'poise'
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
module Resources
|
||||
# (see PoiseBuildEssential::Resource)
|
||||
# @since 1.0.0
|
||||
module PoiseBuildEssential
|
||||
# A `poise_build_essential` resource to install a C compiler and build tools.
|
||||
#
|
||||
# @provides poise_build_essential
|
||||
# @action install
|
||||
# @action upgrade
|
||||
# @action uninstall
|
||||
# @example
|
||||
# poise_build_essential 'build-essential'
|
||||
class Resource < Chef::Resource
|
||||
include Poise
|
||||
provides(:poise_build_essential)
|
||||
actions(:install, :upgrade, :remove)
|
||||
|
||||
# @!attribute allow_unsupported_platform
|
||||
# Whether or not to raise an error on unsupported platforms.
|
||||
# @return [Boolean]
|
||||
attribute(:allow_unsupported_platform, kind_of: [TrueClass, FalseClass], default: lazy { node['poise-build-essential']['allow_unsupported_platform'] })
|
||||
end
|
||||
|
||||
# Providers can be found under build_essential_providers/.
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseBuildEssential
|
||||
VERSION = '1.0.0'
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
|
||||
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
|
||||
require "poise_build_essential/cheftie"
|
|
@ -1 +0,0 @@
|
|||
{"name":"poise-build-essential","version":"1.0.0","description":"A Chef cookbook to install a C compiler and build tools.","long_description":"# Poise-Build-Essential Cookbook\n\n[![Build Status](https://img.shields.io/travis/poise/poise-build-essential.svg)](https://travis-ci.org/poise/poise-build-essential)\n[![Gem Version](https://img.shields.io/gem/v/poise-build-essential.svg)](https://rubygems.org/gems/poise-build-essential)\n[![Cookbook Version](https://img.shields.io/cookbook/v/poise-build-essential.svg)](https://supermarket.chef.io/cookbooks/poise-build-essential)\n[![Coverage](https://img.shields.io/codecov/c/github/poise/poise-build-essential.svg)](https://codecov.io/github/poise/poise-build-essential)\n[![Gemnasium](https://img.shields.io/gemnasium/poise/poise-build-essential.svg)](https://gemnasium.com/poise/poise-build-essential)\n[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\nA [Chef](https://www.chef.io/) cookbook to install a C compiler and build tools..\n\n## Quick Start\n\nTo install a C compiler:\n\n```ruby\ninclude_recipe 'poise-build-essential'\n```\n\nOr to install using a resource and at compile time:\n\n```ruby\npoise_build_essential 'build_essential' do\n action :nothing\nend.run_action(:install)\n```\n\n## Recipes\n\n* `poise-build-essential::default` – Install a C compiler and build tools.\n\n## Attributes\n\n* `node['poise-build-essential']['action']` – Action to use. One of install,\n upgrade, or remove. *(default: install)*\n* `node['poise-build-essential']['allow_unsupported_platform']` – Whether or not\n to raise an error on unsupported platforms. *(default: false)*\n\n## Resources\n\n### `poise_build_essential`\n\nThe `poise_build_essential` resource installs a C compiler and build tools.\n\n```ruby\npoise_build_essential 'build_essential' do\n allow_unsupported_platform true\nend\n```\n\n#### Actions\n\n* `:install` – Install a C compiler. *(default)*\n* `:upgrade` – Install a C compiler using `package action :ugprade` rules.\n* `:remove` – Remove a C compiler.\n\n#### Properties\n\n* `allow_unsupported_platform` – Whether or not to raise an error on unsupported\n platforms. *(default: false)*\n\n## Sponsors\n\nDevelopment sponsored by [SAP](https://www.sap.com/).\n\nThe Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).\n\n## License\n\nSome code copyright 2008-2017, Chef Software, Inc. Used under the terms of the\nApache License, Version 2.0.\n\nCopyright 2017, Noah Kantrowitz\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","maintainer":"Noah Kantrowitz","maintainer_email":"noah@coderanger.net","license":"Apache 2.0","platforms":{},"dependencies":{"poise":"~> 2.6"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/poise/poise-build-essential","issues_url":"https://github.com/poise/poise-build-essential/issues","chef_version":[["< 14",">= 12.1"]],"ohai_version":[]}
|
|
@ -1,19 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
poise_build_essential 'build_essential' do
|
||||
action node['poise-build-essential']['action'].to_sym
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
# Poise-Git Changelog
|
||||
|
||||
## v1.0.0
|
||||
|
||||
* Initial release!
|
|
@ -1,151 +0,0 @@
|
|||
# Poise-Git Cookbook
|
||||
|
||||
[![Build Status](https://img.shields.io/travis/poise/poise-git.svg)](https://travis-ci.org/poise/poise-git)
|
||||
[![Gem Version](https://img.shields.io/gem/v/poise-git.svg)](https://rubygems.org/gems/poise-git)
|
||||
[![Cookbook Version](https://img.shields.io/cookbook/v/poise-git.svg)](https://supermarket.chef.io/cookbooks/poise-git)
|
||||
[![Coverage](https://img.shields.io/codecov/c/github/poise/poise-git.svg)](https://codecov.io/github/poise/poise-git)
|
||||
[![Gemnasium](https://img.shields.io/gemnasium/poise/poise-git.svg)](https://gemnasium.com/poise/poise-git)
|
||||
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
A [Chef](https://www.chef.io/) cookbook to manage [Git](https://git-scm.com/).
|
||||
|
||||
## Quick Start
|
||||
|
||||
To install Git and clone a repository using a deploy key from a data bag:
|
||||
|
||||
```ruby
|
||||
poise_git '/srv/myapp' do
|
||||
repository 'git@github.com:example/myapp.git'
|
||||
deploy_key data_bag_item('keys', 'myapp')['key']
|
||||
end
|
||||
```
|
||||
|
||||
To install Git and clone a repository using a deploy key that already exists on
|
||||
disk:
|
||||
|
||||
```ruby
|
||||
poise_git '/srv/myapp' do
|
||||
repository 'git@github.com:example/myapp.git'
|
||||
deploy_key '/path/to/mykey.pem'
|
||||
end
|
||||
```
|
||||
|
||||
## Recipes
|
||||
|
||||
* `poise-git::default` – Install Git.
|
||||
|
||||
## Attributes
|
||||
|
||||
* `node['poise-git']['default_recipe']` – Recipe used by `poise_git` to install
|
||||
Git if not already available. *(default: poise-git)*
|
||||
* `node['poise-git']['provider']` – Default provider for `poise_git_client` resource
|
||||
instances. *(default: auto)*
|
||||
* `node['poise-git']['recipe'][*]` – All subkeys of `'recipe'` will be passed
|
||||
as properties to the `poise_git_client` resource before installation when using
|
||||
the `poise-git::default` recipe.
|
||||
|
||||
## Resources
|
||||
|
||||
### `poise_git`
|
||||
|
||||
The `poise_git` resource extends the core `git` resource, adding a `deploy_key`
|
||||
property to use SSH deploy keys automatically.
|
||||
|
||||
```ruby
|
||||
poise_git '/srv/myapp' do
|
||||
repository 'git@github.com:example/myapp.git'
|
||||
deploy_key 'mysecretkey'
|
||||
end
|
||||
```
|
||||
|
||||
The `poise_git` resource supports all the same actions and properties as the
|
||||
core `git` resource.
|
||||
|
||||
The `deploy_key` property can either be passed the absolute path to an existing
|
||||
SSH key file, or the raw SSH private key text.
|
||||
|
||||
### `poise_git_client`
|
||||
|
||||
The `poise_git_client` resource installs Git.
|
||||
|
||||
```ruby
|
||||
poise_git_client 'git'
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:install` – Install Git. *(default)*
|
||||
* `:uninstall` – Uninstall Git.
|
||||
|
||||
#### Properties
|
||||
|
||||
* `version` – Version of Git to install. If a partial version is given, use the
|
||||
latest available version matching that prefix. *(name property)*
|
||||
|
||||
#### Provider Options
|
||||
|
||||
The `poise_git_client` resource uses provide options for per-provider configuration. See
|
||||
[the poise-service documentation](https://github.com/poise/poise-service#service-options)
|
||||
for more information on using provider options.
|
||||
|
||||
## Git Client Providers
|
||||
|
||||
### `system`
|
||||
|
||||
The `system` provider installs Git using system packages. This is currently
|
||||
only tested on platforms using `apt-get` and `yum` (Debian, Ubuntu, RHEL, CentOS
|
||||
Amazon Linux, and Fedora) and is a default provider on those platforms. It may
|
||||
work on other platforms but is untested.
|
||||
|
||||
```ruby
|
||||
poise_git_client 'git' do
|
||||
provider :system
|
||||
end
|
||||
```
|
||||
|
||||
#### Options
|
||||
|
||||
* `package_name` – Override auto-detection of the package name.
|
||||
* `package_upgrade` – Install using action `:upgrade`. *(default: false)*
|
||||
* `package_version` – Override auto-detection of the package version.
|
||||
|
||||
### `dummy`
|
||||
|
||||
The `dummy` provider supports using the `poise_git_client` resource with ChefSpec
|
||||
or other testing frameworks to not actually install Git. It is used by default under
|
||||
ChefSpec. It can also be used to manage the Git installation externally from
|
||||
this cookbook.
|
||||
|
||||
```ruby
|
||||
poise_git_client 'git' do
|
||||
provider :dummy
|
||||
options git_binary: '/path/to/git'
|
||||
end
|
||||
```
|
||||
|
||||
#### Provider Options
|
||||
|
||||
* `git_binary` – Path to the `git` executable. *(default: /git)*
|
||||
* `git_environment` – Hash of environment variables to use with this Git. *(default: {})*
|
||||
|
||||
## Sponsors
|
||||
|
||||
Development sponsored by [SAP](https://www.sap.com/).
|
||||
|
||||
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2015-2017, Noah Kantrowitz
|
||||
|
||||
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.
|
|
@ -1,26 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# Default recipe to use to install git.
|
||||
default['poise-git']['default_recipe'] = 'poise-git'
|
||||
|
||||
# Default inversion options.
|
||||
default['poise-git']['provider'] = 'auto'
|
||||
default['poise-git']['options'] = {}
|
||||
|
||||
# Attributes for recipe[poise-git]. All values are nil because the actual
|
||||
# defaults live in the resource.
|
||||
default['poise-git']['recipe']['version'] = nil
|
|
@ -1,24 +0,0 @@
|
|||
#
|
||||
# Copyright 2015-2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
module PoiseGit
|
||||
autoload :GitClientProviders, 'poise_git/git_client_providers'
|
||||
autoload :GitCommandMixin, 'poise_git/git_command_mixin'
|
||||
autoload :Resources, 'poise_git/resources'
|
||||
autoload :SafeString, 'poise_git/safe_string'
|
||||
autoload :VERSION, 'poise_git/version'
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_git/resources'
|
||||
require 'poise_git/git_client_providers'
|
|
@ -1,36 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/platform/provider_priority_map'
|
||||
|
||||
require 'poise_git/git_client_providers/dummy'
|
||||
require 'poise_git/git_client_providers/system'
|
||||
|
||||
|
||||
module PoiseGit
|
||||
# Inversion providers for the poise_git resource.
|
||||
#
|
||||
# @since 1.0.0
|
||||
module GitClientProviders
|
||||
autoload :Base, 'poise_git/git_client_providers/base'
|
||||
|
||||
# Set up priority maps
|
||||
Chef::Platform::ProviderPriorityMap.instance.priority(:poise_git_client, [
|
||||
PoiseGit::GitClientProviders::Dummy,
|
||||
PoiseGit::GitClientProviders::System,
|
||||
])
|
||||
end
|
||||
end
|
|
@ -1,93 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'chef/provider'
|
||||
require 'poise'
|
||||
|
||||
|
||||
module PoiseGit
|
||||
module GitClientProviders
|
||||
# The provider base class for `poise_git_client`.
|
||||
#
|
||||
# @see PoiseGit::Resources::PoiseGitClient::Resource
|
||||
# @provides poise_git_client
|
||||
class Base < Chef::Provider
|
||||
include Poise(inversion: :poise_git_client)
|
||||
provides(:poise_git_client)
|
||||
|
||||
# Set default inversion options.
|
||||
#
|
||||
# @api private
|
||||
def self.default_inversion_options(node, new_resource)
|
||||
super.merge({
|
||||
version: new_resource.version,
|
||||
})
|
||||
end
|
||||
|
||||
# The `install` action for the `poise_git_client` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_install
|
||||
notifying_block do
|
||||
install_git
|
||||
end
|
||||
end
|
||||
|
||||
# The `uninstall` action for the `poise_git_client` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_uninstall
|
||||
notifying_block do
|
||||
uninstall_git
|
||||
end
|
||||
end
|
||||
|
||||
# The path to the `git` binary. This is an output property.
|
||||
#
|
||||
# @abstract
|
||||
# @return [String]
|
||||
def git_binary
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
# The environment variables for this Git. This is an output property.
|
||||
#
|
||||
# @return [Hash<String, String>]
|
||||
def git_environment
|
||||
{}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Install git.
|
||||
#
|
||||
# @abstract
|
||||
# @return [void]
|
||||
def install_git
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
# Uninstall git.
|
||||
#
|
||||
# @abstract
|
||||
# @return [void]
|
||||
def uninstall_git
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,79 +0,0 @@
|
|||
#
|
||||
# Copyright 2017, Noah Kantrowitz
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'poise_git/git_client_providers/base'
|
||||
|
||||
|
||||
module PoiseGit
|
||||
module GitClientProviders
|
||||
# Inversion provider for the `poise_git_client` resource to use a fake Git,
|
||||
# for use in unit tests.
|
||||
#
|
||||
# @since 1.0.0
|
||||
# @see PoiseGit::Resources::PoiseGitClient::Resource
|
||||
# @provides poise_git_client
|
||||
class Dummy < Base
|
||||
provides(:dummy)
|
||||
|
||||
# Enable by default on ChefSpec.
|
||||
#
|
||||
# @api private
|
||||
def self.provides_auto?(node, _resource)
|
||||
node.platform?('chefspec')
|
||||
end
|
||||
|
||||
# Manual overrides for dummy data.
|
||||
#
|
||||
# @api private
|
||||
def self.default_inversion_options(node, resource)
|
||||
super.merge({
|
||||
git_binary: '/git',
|
||||
git_environment: nil,
|
||||
})
|
||||
end
|
||||
|
||||
# The `install` action for the `poise_git_client` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_install
|
||||
# This space left intentionally blank.
|
||||
end
|
||||
|
||||
# The `uninstall` action for the `poise_git_client` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_uninstall
|
||||
# This space left intentionally blank.
|
||||
end
|
||||
|
||||
# Path to the non-existent Git.
|
||||
#
|
||||
# @return [String]
|
||||
def git_binary
|
||||
options['git_binary']
|
||||
end
|
||||
|
||||
# Environment for the non-existent Git.
|
||||
#
|
||||
# @return [String]
|
||||
def git_environment
|
||||
options['git_environment'] || super
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue