Vendor the external cookbooks
Knife-Zero doesn't include Berkshelf support, so vendoring everything in the repo is convenient again
This commit is contained in:
5
cookbooks/poise-git/CHANGELOG.md
Normal file
5
cookbooks/poise-git/CHANGELOG.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Poise-Git Changelog
|
||||
|
||||
## v1.0.0
|
||||
|
||||
* Initial release!
|
||||
151
cookbooks/poise-git/README.md
Normal file
151
cookbooks/poise-git/README.md
Normal file
@@ -0,0 +1,151 @@
|
||||
# Poise-Git Cookbook
|
||||
|
||||
[](https://travis-ci.org/poise/poise-git)
|
||||
[](https://rubygems.org/gems/poise-git)
|
||||
[](https://supermarket.chef.io/cookbooks/poise-git)
|
||||
[](https://codecov.io/github/poise/poise-git)
|
||||
[](https://gemnasium.com/poise/poise-git)
|
||||
[](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.
|
||||
26
cookbooks/poise-git/attributes/default.rb
Normal file
26
cookbooks/poise-git/attributes/default.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# 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
|
||||
24
cookbooks/poise-git/files/halite_gem/poise_git.rb
Normal file
24
cookbooks/poise-git/files/halite_gem/poise_git.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# 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
|
||||
18
cookbooks/poise-git/files/halite_gem/poise_git/cheftie.rb
Normal file
18
cookbooks/poise-git/files/halite_gem/poise_git/cheftie.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# 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'
|
||||
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# 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
|
||||
@@ -0,0 +1,93 @@
|
||||
#
|
||||
# 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
|
||||
@@ -0,0 +1,79 @@
|
||||
#
|
||||
# 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
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#
|
||||
# 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_languages'
|
||||
|
||||
require 'poise_git/git_client_providers/base'
|
||||
|
||||
|
||||
module PoiseGit
|
||||
module GitClientProviders
|
||||
# A provider for `poise_git_client` to install from distro packages.
|
||||
#
|
||||
# @since 1.0.0
|
||||
# @see PoiseGit::Resources::PoiseGitClient::Resource
|
||||
# @provides poise_git_client
|
||||
class System < Base
|
||||
include PoiseLanguages::System::Mixin
|
||||
provides(:system)
|
||||
packages('git', {
|
||||
omnios: {default: %w{developer/versioning/git}},
|
||||
smartos: {default: %w{scmgit}},
|
||||
})
|
||||
|
||||
# Output value for the Git binary we are installing.
|
||||
def git_binary
|
||||
# What should this be for OmniOS and SmartOS?
|
||||
"/usr/bin/git"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Install git from system packages.
|
||||
#
|
||||
# @return [void]
|
||||
def install_git
|
||||
install_system_packages do
|
||||
# Unlike language-ish packages, we don't need a headers package.
|
||||
dev_package false
|
||||
end
|
||||
end
|
||||
|
||||
# Remove git from system packages.
|
||||
#
|
||||
# @return [void]
|
||||
def uninstall_git
|
||||
uninstall_system_packages do
|
||||
# Unlike language-ish packages, we don't need a headers package.
|
||||
dev_package false
|
||||
end
|
||||
end
|
||||
|
||||
def system_package_candidates(version)
|
||||
# This is kind of silly, could use a refactor in the mixin but just
|
||||
# moving on for right now.
|
||||
node.value_for_platform(self.class.packages) || %w{git}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# 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/utils'
|
||||
require 'poise_languages'
|
||||
|
||||
|
||||
module PoiseGit
|
||||
# Mixin for resources and providers which run Git commands.
|
||||
#
|
||||
# @since 1.0.0
|
||||
module GitCommandMixin
|
||||
include Poise::Utils::ResourceProviderMixin
|
||||
|
||||
# Mixin for resources which run Git commands.
|
||||
module Resource
|
||||
include PoiseLanguages::Command::Mixin::Resource(:git, runtime: :poise_git_client)
|
||||
end
|
||||
|
||||
module Provider
|
||||
include PoiseLanguages::Command::Mixin::Provider(:git)
|
||||
end
|
||||
end
|
||||
end
|
||||
27
cookbooks/poise-git/files/halite_gem/poise_git/resources.rb
Normal file
27
cookbooks/poise-git/files/halite_gem/poise_git/resources.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# 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/poise_git_client'
|
||||
require 'poise_git/resources/poise_git'
|
||||
|
||||
|
||||
module PoiseGit
|
||||
# Chef resources and providers for poise-git.
|
||||
#
|
||||
# @since 1.0.0
|
||||
module Resources
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,252 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
require 'shellwords'
|
||||
require 'zlib'
|
||||
|
||||
require 'chef/provider/git'
|
||||
require 'chef/resource/git'
|
||||
require 'poise'
|
||||
|
||||
require 'poise_git/git_command_mixin'
|
||||
require 'poise_git/safe_string'
|
||||
|
||||
|
||||
module PoiseGit
|
||||
module Resources
|
||||
# (see PoiseGit::Resource)
|
||||
# @since 1.0.0
|
||||
module PoiseGit
|
||||
# A `poise_git` resource to manage Python installations using pip.
|
||||
#
|
||||
# @provides poise_git
|
||||
# @action checkout
|
||||
# @action export
|
||||
# @action sync
|
||||
# @example
|
||||
# poise_git '/srv/myapp' do
|
||||
# repository 'https://...'
|
||||
# deploy_key data_bag_item('deploy_keys', 'myapp')['key']
|
||||
# end
|
||||
class Resource < Chef::Resource::Git
|
||||
include Poise
|
||||
include ::PoiseGit::GitCommandMixin
|
||||
provides(:poise_git)
|
||||
# Manually create matchers because #actions is unreliable.
|
||||
%i{checkout export sync}.each do |action|
|
||||
Poise::Helpers::ChefspecMatchers.create_matcher(:poise_git, action)
|
||||
end
|
||||
|
||||
# @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 = :poise_git if defined?(@resource_name) && @resource_name
|
||||
@provider = ::PoiseGit::Resources::PoiseGit::Provider if defined?(@provider) && @provider
|
||||
end
|
||||
|
||||
# @!attribute strict_ssh
|
||||
# Enable strict SSH host key checking. Defaults to false.
|
||||
# @return [Boolean]
|
||||
attribute(:strict_ssh, equal_to: [true, false], default: false)
|
||||
|
||||
# @!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 ||= "#{Chef::Config[:file_cache_path]}/poise_git_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
|
||||
# Try to be mindful of Windows-y paths here even though they almost
|
||||
# certainly won't actually work later on with ssh.
|
||||
key && key =~ /\A(\/|[a-zA-Z]:)/
|
||||
end
|
||||
|
||||
# Path to deploy key.
|
||||
#
|
||||
# @api private
|
||||
# @return [String]
|
||||
def deploy_key_path
|
||||
@deploy_key_path ||= if deploy_key_is_local?
|
||||
deploy_key
|
||||
else
|
||||
"#{Chef::Config[:file_cache_path]}/poise_git_deploy_#{Zlib.crc32(name)}"
|
||||
end
|
||||
end
|
||||
|
||||
# Hook to force the git install via recipe if needed.
|
||||
def after_created
|
||||
if !parent_git && node['poise-git']['default_recipe']
|
||||
# Use the default recipe to give us a parent the next time we ask.
|
||||
run_context.include_recipe(node['poise-git']['default_recipe'])
|
||||
# Force it to re-expand the cache next time.
|
||||
@parent_git = nil
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# The default provider for the `poise_git` resource.
|
||||
#
|
||||
# @see Resource
|
||||
class Provider < Chef::Provider::Git
|
||||
include Poise
|
||||
include ::PoiseGit::GitCommandMixin
|
||||
provides(:poise_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
|
||||
|
||||
# Hack our special login in before load_current_resource runs because that
|
||||
# needs access to the git remote.
|
||||
#
|
||||
# @api private
|
||||
def load_current_resource
|
||||
create_deploy_key if new_resource.deploy_key
|
||||
super
|
||||
end
|
||||
|
||||
# Like {#load_current_resource}, make sure git is installed since we might
|
||||
# need it depending on the version of Chef.
|
||||
#
|
||||
# @api private
|
||||
def define_resource_requirements
|
||||
create_deploy_key if new_resource.deploy_key
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Install git and set up the deploy key if needed. Safe to call multiple
|
||||
# times if needed.
|
||||
#
|
||||
# @api private
|
||||
# @return [void]
|
||||
def create_deploy_key
|
||||
return if @create_deploy_key
|
||||
Chef::Log.debug("[#{new_resource}] Creating deploy key")
|
||||
old_why_run = Chef::Config[:why_run]
|
||||
begin
|
||||
# Forcibly disable why run support so these will always run, since
|
||||
# we need to be able to talk to the git remote even just for the
|
||||
# whyrun checks.
|
||||
Chef::Config[:why_run] = false
|
||||
notifying_block do
|
||||
write_deploy_key
|
||||
write_ssh_wrapper
|
||||
end
|
||||
ensure
|
||||
Chef::Config[:why_run] = old_why_run
|
||||
end
|
||||
@create_deploy_key = true
|
||||
end
|
||||
|
||||
# Copy the deploy key to a file if needed.
|
||||
#
|
||||
# @api private
|
||||
# @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.
|
||||
#
|
||||
# @api private
|
||||
# @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.
|
||||
#
|
||||
# @api private
|
||||
def git(*args, &block)
|
||||
self.class.superclass.instance_method(:git).bind(self).call(*args, &block)
|
||||
end
|
||||
|
||||
# Trick all shell_out related things in the base class in to using
|
||||
# my git_shell_out instead.
|
||||
#
|
||||
# @api private
|
||||
def shell_out(*cmd, **options)
|
||||
if @shell_out_hack_inner
|
||||
# This is the real call.
|
||||
super
|
||||
else
|
||||
# This ia call we want to intercept and send to our method.
|
||||
begin
|
||||
@shell_out_hack_inner = true
|
||||
# Remove nils and flatten for compat with how core uses this method.
|
||||
cmd.compact!
|
||||
cmd.flatten!
|
||||
# Reparse the command to get a clean array.
|
||||
cmd = Shellwords.split(cmd.join(' '))
|
||||
# We'll add the git command back in ourselves.
|
||||
cmd.shift if cmd.first == 'git'
|
||||
# Push the yak stack.
|
||||
git_shell_out(*cmd, **options)
|
||||
ensure
|
||||
@shell_out_hack_inner = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,82 @@
|
||||
#
|
||||
# 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 PoiseGit
|
||||
module Resources
|
||||
# (see PoiseGitClient::Resource)
|
||||
# @since 1.0.0
|
||||
module PoiseGitClient
|
||||
# A `poise_git_client` resource to install a C compiler and build tools.
|
||||
#
|
||||
# @provides poise_git_client
|
||||
# @action install
|
||||
# @action uninstall
|
||||
# @example
|
||||
# poise_git_client 'git'
|
||||
class Resource < Chef::Resource
|
||||
include Poise(inversion: true, container: true)
|
||||
provides(:poise_git_client)
|
||||
actions(:install, :uninstall)
|
||||
|
||||
# @!attribute version
|
||||
# Version of Git to install. The version is prefix-matched so `'2'`
|
||||
# will install the most recent Git 2.x, and so on.
|
||||
# @return [String]
|
||||
# @example Install any version
|
||||
# poise_git_client 'any' do
|
||||
# version ''
|
||||
# end
|
||||
# @example Install Git 2
|
||||
# poise_git_client '2'
|
||||
attribute(:version, kind_of: String, default: lazy { default_version })
|
||||
|
||||
# The path to the `git` binary for this Git installation. This is
|
||||
# an output property.
|
||||
#
|
||||
# @return [String]
|
||||
# @example
|
||||
# execute "#{resources('poise_git_client[git]').git_binary} init"
|
||||
def git_binary
|
||||
provider_for_action(:git_binary).git_binary
|
||||
end
|
||||
|
||||
# The environment variables for this Git installation. This is an
|
||||
# output property.
|
||||
#
|
||||
# @return [Hash<String, String>]
|
||||
def git_environment
|
||||
provider_for_action(:git_environment).git_environment
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Default value for the version property. Trims an optional `git-` from
|
||||
# the resource name.
|
||||
#
|
||||
# @return [String]
|
||||
def default_version
|
||||
name[/^(git-?)?(.*)$/, 2] || ''
|
||||
end
|
||||
end
|
||||
|
||||
# Providers can be found under git_client_providers/.
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# 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
|
||||
# A string that won't be shown in Chef error output
|
||||
class SafeString < String
|
||||
def to_text
|
||||
'"suppressed sensitive value"'
|
||||
end
|
||||
end
|
||||
end
|
||||
20
cookbooks/poise-git/files/halite_gem/poise_git/version.rb
Normal file
20
cookbooks/poise-git/files/halite_gem/poise_git/version.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# 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
|
||||
VERSION = '1.0.0'
|
||||
end
|
||||
19
cookbooks/poise-git/libraries/default.rb
Normal file
19
cookbooks/poise-git/libraries/default.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
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_git/cheftie"
|
||||
1
cookbooks/poise-git/metadata.json
Normal file
1
cookbooks/poise-git/metadata.json
Normal file
File diff suppressed because one or more lines are too long
22
cookbooks/poise-git/recipes/default.rb
Normal file
22
cookbooks/poise-git/recipes/default.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# 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_git_client 'git' do
|
||||
node['poise-git']['recipe'].each do |key, value|
|
||||
# Skip nils, use false if you want to disable something.
|
||||
send(key, value) unless value.nil?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user