poise-application-git 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.kitchen.travis.yml +9 -0
- data/.kitchen.yml +8 -0
- data/.travis.yml +23 -0
- data/.yardopts +4 -0
- data/Berksfile +29 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +34 -0
- data/LICENSE +201 -0
- data/README.md +108 -0
- data/Rakefile +17 -0
- data/SUPPORTERS.md +81 -0
- data/lib/poise-application-git.rb +17 -0
- data/lib/poise_application_git.rb +21 -0
- data/lib/poise_application_git/cheftie.rb +17 -0
- data/lib/poise_application_git/resource.rb +189 -0
- data/lib/poise_application_git/safe_string.rb +25 -0
- data/lib/poise_application_git/version.rb +20 -0
- data/poise-application-git.gemspec +44 -0
- data/test/cookbooks/application_git_test/metadata.rb +18 -0
- data/test/cookbooks/application_git_test/recipes/default.rb +69 -0
- data/test/gemfiles/chef-12.gemfile +19 -0
- data/test/gemfiles/master.gemfile +24 -0
- data/test/integration/default/serverspec/default_spec.rb +42 -0
- data/test/spec/resource_spec.rb +97 -0
- data/test/spec/spec_helper.rb +18 -0
- metadata +140 -0
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_boiler/rakefile'
|
data/SUPPORTERS.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Supporters
|
2
|
+
|
3
|
+
This cookbook wouldn't have been possible without the generous support of my
|
4
|
+
Kickstarter backers. Thanks so much to every one of you!
|
5
|
+
|
6
|
+
* @kcunning
|
7
|
+
* Alberto Lorenzo Pulido
|
8
|
+
* Alex Gaynor
|
9
|
+
* Alexander Myasnikov
|
10
|
+
* Brooke Schreier Ganz
|
11
|
+
* Bryan McLellan
|
12
|
+
* Charles Johnson
|
13
|
+
* Chef Software, Inc.
|
14
|
+
* Chris Adams
|
15
|
+
* Christopher Petrilli
|
16
|
+
* David Thornton
|
17
|
+
* Derek Murawsky
|
18
|
+
* Fast Robot, LLC
|
19
|
+
* Fatty McAwesome Pants (Kate Heddleston)
|
20
|
+
* Greg Albrecht
|
21
|
+
* JD Harrington
|
22
|
+
* Jake Plimack
|
23
|
+
* Jason Cook
|
24
|
+
* Jeff Byrnes
|
25
|
+
* Jeff Forcier
|
26
|
+
* Jeff Lindsay
|
27
|
+
* Jennifer Davis
|
28
|
+
* John Fitch
|
29
|
+
* Jon Stacks
|
30
|
+
* Joshua SS Miller
|
31
|
+
* Julian Dunn
|
32
|
+
* Julien Phalip
|
33
|
+
* Kennon Kwok
|
34
|
+
* Kevin Duane
|
35
|
+
* Krzysztof Wilczynski
|
36
|
+
* Linda Goldstein
|
37
|
+
* Manny Toledo
|
38
|
+
* Marco A Morales
|
39
|
+
* Marcus Morris
|
40
|
+
* Mark Luntzel
|
41
|
+
* Martin B. Smith
|
42
|
+
* Mathieu Sauve-Frankel
|
43
|
+
* Matt Good
|
44
|
+
* Matt Juszczak
|
45
|
+
* Matt Ray
|
46
|
+
* Matt Stratton
|
47
|
+
* Michael Burns
|
48
|
+
* Miguel Landaeta
|
49
|
+
* Mike Schueler
|
50
|
+
* Nathan L Smith
|
51
|
+
* Nathen Harvey
|
52
|
+
* Paul Welch
|
53
|
+
* Peter Kropf
|
54
|
+
* Phil Mocek
|
55
|
+
* Practice Fusion Inc
|
56
|
+
* Ranjib
|
57
|
+
* Richard Jones
|
58
|
+
* Robert J. Berger
|
59
|
+
* Robin Levin
|
60
|
+
* Roland Moriz
|
61
|
+
* Ruben Orduz
|
62
|
+
* Russell Keith-Magee
|
63
|
+
* Ryan Hass
|
64
|
+
* Sam Clements
|
65
|
+
* Sean OMeara
|
66
|
+
* Seva Feldman
|
67
|
+
* Soo Choi
|
68
|
+
* Steven Danna
|
69
|
+
* Symonds & Son
|
70
|
+
* Todd Michael Bushnell
|
71
|
+
* Tracy Osborn
|
72
|
+
* Troy Ready
|
73
|
+
* Tyler Ball
|
74
|
+
* Vicky Tuite
|
75
|
+
* Ying Li
|
76
|
+
* Yvo van Doorn
|
77
|
+
* Zac Stevens
|
78
|
+
* lvh
|
79
|
+
* oolongtea
|
80
|
+
* smeuser
|
81
|
+
* tmonk42
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_application_git'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_application_git/resource'
|
18
|
+
|
19
|
+
|
20
|
+
module PoiseApplicationGit
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_application_git/resource'
|
@@ -0,0 +1,189 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'zlib'
|
18
|
+
|
19
|
+
require 'chef/provider'
|
20
|
+
require 'chef/resource'
|
21
|
+
require 'poise_application/app_mixin'
|
22
|
+
require 'poise_application/resources/application'
|
23
|
+
|
24
|
+
require 'poise_application_git/safe_string'
|
25
|
+
|
26
|
+
|
27
|
+
module PoiseApplicationGit
|
28
|
+
# An `application_git` resource to clone application code from git.
|
29
|
+
#
|
30
|
+
# @since 1.0.0
|
31
|
+
# @provides application_git
|
32
|
+
# @action sync
|
33
|
+
# @action checkout
|
34
|
+
# @action export
|
35
|
+
# @example
|
36
|
+
# application '/srv/myapp' do
|
37
|
+
# git 'git@github.com:example/myapp.git' do
|
38
|
+
# deploy_key data_bag_item('deploy_keys', 'myapp')['key']
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
class Resource < Chef::Resource::Git
|
42
|
+
include PoiseApplication::AppMixin
|
43
|
+
provides(:application_git)
|
44
|
+
|
45
|
+
# @api private
|
46
|
+
def initialize(*args)
|
47
|
+
super
|
48
|
+
# Because the superclass declares this, we have to as well. Should be
|
49
|
+
# removable at some point when Chef makes everything use the provider
|
50
|
+
# resolver system instead.
|
51
|
+
@resource_name = :application_git
|
52
|
+
@provider = PoiseApplicationGit::Provider
|
53
|
+
end
|
54
|
+
|
55
|
+
# @!attribute strict_ssh
|
56
|
+
# Enable strict SSH host key checking. Defaults to false.
|
57
|
+
# @return [Boolean]
|
58
|
+
attribute(:strict_ssh, equal_to: [true, false], default: false)
|
59
|
+
|
60
|
+
# @api private
|
61
|
+
def after_created
|
62
|
+
# Allow using the repository as the name in an application block.
|
63
|
+
if parent && !repository
|
64
|
+
destination(parent.path)
|
65
|
+
repository(name)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# @!attribute deploy_key
|
70
|
+
# SSH deploy key as either a string value or a path to a key file.
|
71
|
+
# @return [String]
|
72
|
+
def deploy_key(val=nil)
|
73
|
+
if val
|
74
|
+
# Set the wrapper script if we have a deploy key.
|
75
|
+
ssh_wrapper(ssh_wrapper_path) if !ssh_wrapper
|
76
|
+
# Also use a SafeString for literal deploy keys so they aren't shown.
|
77
|
+
val = SafeString.new(val) unless deploy_key_is_local?(val)
|
78
|
+
end
|
79
|
+
set_or_return(:deploy_key, val, kind_of: String)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Default SSH wrapper path.
|
83
|
+
#
|
84
|
+
# @api private
|
85
|
+
# @return [String]
|
86
|
+
def ssh_wrapper_path
|
87
|
+
@ssh_wrapper_path ||= ::File.expand_path("~#{user}/.ssh/ssh_wrapper_#{Zlib.crc32(name)}")
|
88
|
+
end
|
89
|
+
|
90
|
+
# Guess if the deploy key is a local path or literal value.
|
91
|
+
#
|
92
|
+
# @api private
|
93
|
+
# @param key [String, nil] Key value to check. Defaults to self.key.
|
94
|
+
# @return [Boolean]
|
95
|
+
def deploy_key_is_local?(key=nil)
|
96
|
+
key ||= deploy_key
|
97
|
+
key && key[0] == '/'
|
98
|
+
end
|
99
|
+
|
100
|
+
# Path to deploy key.
|
101
|
+
#
|
102
|
+
# @api private
|
103
|
+
# @return [String]
|
104
|
+
def deploy_key_path
|
105
|
+
@deploy_key_path ||= if deploy_key_is_local?
|
106
|
+
deploy_key
|
107
|
+
else
|
108
|
+
::File.expand_path("~#{user}/.ssh/id_deploy_#{Zlib.crc32(name)}")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Provider for `application_git`.
|
114
|
+
#
|
115
|
+
# @since 1.0.0
|
116
|
+
# @see Resource
|
117
|
+
# @provides application_git
|
118
|
+
class Provider < Chef::Provider::Git
|
119
|
+
include PoiseApplication::AppMixin
|
120
|
+
provides(:application_git)
|
121
|
+
|
122
|
+
# @api private
|
123
|
+
def whyrun_supported?
|
124
|
+
false # Just not dealing with this right now
|
125
|
+
end
|
126
|
+
|
127
|
+
# Hack our special login in before load_current_resource runs because that
|
128
|
+
# needs access to the git remote.
|
129
|
+
#
|
130
|
+
# @api private
|
131
|
+
def load_current_resource
|
132
|
+
include_recipe('git')
|
133
|
+
notifying_block do
|
134
|
+
create_dotssh
|
135
|
+
write_deploy_key
|
136
|
+
write_ssh_wrapper
|
137
|
+
end if new_resource.deploy_key
|
138
|
+
super
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
# Create a .ssh folder for the user.
|
144
|
+
#
|
145
|
+
# @return [void]
|
146
|
+
def create_dotssh
|
147
|
+
directory ::File.expand_path("~#{new_resource.user}/.ssh") do
|
148
|
+
owner new_resource.user
|
149
|
+
group new_resource.group
|
150
|
+
mode '755'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Copy the deploy key to a file if needed.
|
155
|
+
#
|
156
|
+
# @return [void]
|
157
|
+
def write_deploy_key
|
158
|
+
# Check if we have a local path or some actual content
|
159
|
+
return if new_resource.deploy_key_is_local?
|
160
|
+
file new_resource.deploy_key_path do
|
161
|
+
owner new_resource.user
|
162
|
+
group new_resource.group
|
163
|
+
mode '600'
|
164
|
+
content new_resource.deploy_key
|
165
|
+
sensitive true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Create the SSH wrapper script.
|
170
|
+
#
|
171
|
+
# @return [void]
|
172
|
+
def write_ssh_wrapper
|
173
|
+
# Write out the GIT_SSH script, it should already be enabled above
|
174
|
+
file new_resource.ssh_wrapper_path do
|
175
|
+
owner new_resource.user
|
176
|
+
group new_resource.group
|
177
|
+
mode '700'
|
178
|
+
content %Q{#!/bin/sh\n/usr/bin/env ssh #{'-o "StrictHostKeyChecking=no" ' unless new_resource.strict_ssh}-i "#{new_resource.deploy_key_path}" $@\n}
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# Patch back in the `#git` from the git provider. This otherwise conflicts
|
183
|
+
# with the `#git` defined by the DSL, which gets included in such a way
|
184
|
+
# that the DSL takes priority.
|
185
|
+
def git(*args, &block)
|
186
|
+
Chef::Provider::Git.instance_method(:git).bind(self).call(*args, &block)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
|
18
|
+
module PoiseApplicationGit
|
19
|
+
# A string that won't be shown in Chef error output
|
20
|
+
class SafeString < String
|
21
|
+
def to_text
|
22
|
+
'"suppressed sensitive value"'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
|
18
|
+
module PoiseApplicationGit
|
19
|
+
VERSION = '1.0.0'
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
lib = File.expand_path('../lib', __FILE__)
|
18
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
19
|
+
require 'poise_application_git/version'
|
20
|
+
|
21
|
+
Gem::Specification.new do |spec|
|
22
|
+
spec.name = 'poise-application-git'
|
23
|
+
spec.version = PoiseApplicationGit::VERSION
|
24
|
+
spec.authors = ['Noah Kantrowitz']
|
25
|
+
spec.email = %w{noah@coderanger.net}
|
26
|
+
spec.description = 'A plugin for poise-application to deploy applications from git.'
|
27
|
+
spec.summary = spec.description
|
28
|
+
spec.homepage = 'https://github.com/poise/application_git'
|
29
|
+
spec.license = 'Apache 2.0'
|
30
|
+
spec.metadata['halite_name'] = 'application_git'
|
31
|
+
|
32
|
+
spec.files = `git ls-files`.split($/)
|
33
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
34
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
35
|
+
spec.require_paths = %w{lib}
|
36
|
+
|
37
|
+
spec.add_dependency 'halite', '~> 1.0'
|
38
|
+
spec.add_dependency 'poise', '~> 2.0'
|
39
|
+
spec.add_dependency 'poise-application', '~> 5.0'
|
40
|
+
|
41
|
+
spec.add_development_dependency 'poise-boiler', '~> 1.0'
|
42
|
+
|
43
|
+
spec.metadata['halite_dependencies'] = 'git'
|
44
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
name 'application_git_test'
|
18
|
+
depends 'application_git'
|