kitchen_hooks 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/kitchen_hooks/app.rb +8 -7
- data/lib/kitchen_hooks/helpers.rb +50 -18
- data/lib/kitchen_hooks/main.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de9b45ecc75ea9db7978e4a39238acc8b640b723
|
4
|
+
data.tar.gz: 8e95dd39e38199cba2024dd230249f0043795683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2950c8af1f35ec2ab5c27eef6d1e7f17704e51d3eb966d4ee6067b55a710669ca07f3e298303b2ea5f1a505474b2f60d88dd4b2bce921f72dab476bf80e2ab4
|
7
|
+
data.tar.gz: 3db27dfd022ed749f4c6f09104d33140c1b85cf51d3a897fbc026f7e12d7844d71933bb69c215d4331dd4142ec1d125fdc5ca953978e9c64d841bb8d0231c140
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.5
|
data/lib/kitchen_hooks/app.rb
CHANGED
@@ -22,9 +22,9 @@ module KitchenHooks
|
|
22
22
|
@@db = Daybreak::DB.new path
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.
|
26
|
-
|
27
|
-
end
|
25
|
+
def self.tmp! dir ; @@tmp = dir end
|
26
|
+
|
27
|
+
def self.close! ; @@db.close end
|
28
28
|
|
29
29
|
def self.config! config
|
30
30
|
@@hipchat = nil
|
@@ -71,6 +71,7 @@ module KitchenHooks
|
|
71
71
|
|
72
72
|
|
73
73
|
private
|
74
|
+
def tmp ; @@tmp ||= '/tmp' end
|
74
75
|
|
75
76
|
def knives ; @@knives ||= [] end
|
76
77
|
|
@@ -119,7 +120,7 @@ module KitchenHooks
|
|
119
120
|
|
120
121
|
def process event
|
121
122
|
if event.nil? # JSON parse failed
|
122
|
-
mark event, 'failure', 'Could not parse WebHook payload'
|
123
|
+
mark event, 'failure', 'Could not parse WebHook payload'
|
123
124
|
return
|
124
125
|
end
|
125
126
|
|
@@ -127,7 +128,7 @@ module KitchenHooks
|
|
127
128
|
possible_error = begin
|
128
129
|
perform_kitchen_upload event, knives
|
129
130
|
rescue Exception => e
|
130
|
-
report_error e, 'Could not perform kitchen upload'
|
131
|
+
report_error e, 'Could not perform kitchen upload: <i>%s</i>' % e.message
|
131
132
|
end
|
132
133
|
mark event, 'kitchen upload', possible_error
|
133
134
|
end
|
@@ -137,7 +138,7 @@ module KitchenHooks
|
|
137
138
|
possible_error = begin
|
138
139
|
perform_cookbook_upload event, knives
|
139
140
|
rescue Exception => e
|
140
|
-
report_error e, 'Could not perform cookbook upload'
|
141
|
+
report_error e, 'Could not perform cookbook upload: <i>%s</i>' % e.message
|
141
142
|
end
|
142
143
|
mark event, 'cookbook upload', possible_error
|
143
144
|
end
|
@@ -147,7 +148,7 @@ module KitchenHooks
|
|
147
148
|
possible_error = begin
|
148
149
|
perform_constraint_application event, knives
|
149
150
|
rescue Exception => e
|
150
|
-
report_error e, 'Could not apply constraints'
|
151
|
+
report_error e, 'Could not apply constraints: <i>%s</i>' % e.message
|
151
152
|
end
|
152
153
|
mark event, 'constraint application', possible_error
|
153
154
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'securerandom'
|
1
2
|
require 'shellwords'
|
2
3
|
require 'fileutils'
|
3
4
|
require 'tempfile'
|
@@ -8,6 +9,7 @@ require 'ridley'
|
|
8
9
|
require 'berkshelf'
|
9
10
|
|
10
11
|
|
12
|
+
Celluloid.logger = nil
|
11
13
|
Berkshelf.logger = Logger.new $stdout
|
12
14
|
|
13
15
|
module KitchenHooks
|
@@ -24,16 +26,20 @@ module KitchenHooks
|
|
24
26
|
|
25
27
|
def perform_constraint_application event, knives
|
26
28
|
logger.debug 'started perform_constraint_application event=%s, knives=%s' % [
|
27
|
-
event
|
29
|
+
event['after'], knives.inspect
|
28
30
|
]
|
31
|
+
|
29
32
|
tmp_clone event, :tagged_commit do |clone|
|
30
33
|
Dir.chdir clone do
|
34
|
+
|
31
35
|
logger.info 'Applying constraints'
|
32
36
|
constraints = lockfile_constraints 'Berksfile.lock'
|
33
37
|
environment = tag_name event
|
34
38
|
knives.each do |k|
|
35
39
|
apply_constraints constraints, environment, k
|
40
|
+
verify_constraints constraints, environment, k
|
36
41
|
end
|
42
|
+
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
@@ -45,7 +51,7 @@ module KitchenHooks
|
|
45
51
|
def perform_kitchen_upload event, knives
|
46
52
|
return false unless commit_to_master?(event)
|
47
53
|
logger.debug 'started perform_kitchen_upload event=%s, knives=%s' % [
|
48
|
-
event
|
54
|
+
event['after'], knives.inspect
|
49
55
|
]
|
50
56
|
|
51
57
|
tmp_clone event, :latest_commit do |clone|
|
@@ -72,7 +78,7 @@ module KitchenHooks
|
|
72
78
|
|
73
79
|
def perform_cookbook_upload event, knives
|
74
80
|
logger.debug 'started perform_cookbook_upload event=%s, knives=%s' % [
|
75
|
-
event
|
81
|
+
event['after'], knives.inspect
|
76
82
|
]
|
77
83
|
|
78
84
|
tmp_clone event, :tagged_commit do |clone|
|
@@ -124,17 +130,27 @@ module KitchenHooks
|
|
124
130
|
|
125
131
|
|
126
132
|
def tmp_clone event, commit_method, &block
|
127
|
-
logger.debug '
|
128
|
-
event
|
133
|
+
logger.debug 'starting tmp_clone event=%s, commit_method=%s' % [
|
134
|
+
event['after'], commit_method.inspect
|
129
135
|
]
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
136
|
+
|
137
|
+
root = File::join tmp, SecureRandom.hex
|
138
|
+
dir = File::join root, Time.now.to_f.to_s, cookbook_name(event)
|
139
|
+
FileUtils.mkdir_p dir
|
140
|
+
|
141
|
+
repo = Git.clone git_daemon_style_url(event), dir, log: $stdout
|
142
|
+
|
143
|
+
commit = self.send(commit_method, event)
|
144
|
+
|
145
|
+
logger.debug 'creating tmp_clone dir=%s, commit=%s' % [
|
146
|
+
dir.inspect, commit.inspect
|
147
|
+
]
|
148
|
+
|
149
|
+
repo.checkout commit
|
150
|
+
|
151
|
+
yield dir
|
152
|
+
|
153
|
+
FileUtils.rm_rf root
|
138
154
|
logger.debug 'finished tmp_clone'
|
139
155
|
end
|
140
156
|
|
@@ -148,16 +164,32 @@ module KitchenHooks
|
|
148
164
|
end
|
149
165
|
|
150
166
|
|
167
|
+
def get_environment environment, knife
|
168
|
+
ridley = Ridley::from_chef_config knife
|
169
|
+
ridley.environment.find environment
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
def verify_constraints constraints, environment, knife
|
174
|
+
logger.debug 'started verify_constraints environment=%s, knife=%s' % [
|
175
|
+
environment.inspect, knife.inspect
|
176
|
+
]
|
177
|
+
chef_environment = get_environment environment, knife
|
178
|
+
unless constraints == chef_environment.cookbook_versions
|
179
|
+
raise 'Environment did not match constraints'
|
180
|
+
end
|
181
|
+
logger.debug 'finished verify_constraints: %s' % environment
|
182
|
+
end
|
183
|
+
|
184
|
+
|
151
185
|
def apply_constraints constraints, environment, knife
|
152
186
|
# Ripped from Berkshelf::Cli::apply and Berkshelf::Lockfile::apply
|
153
187
|
# https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/cli.rb
|
154
188
|
# https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/lockfile.rb
|
155
|
-
logger.debug 'started apply_constraints
|
156
|
-
|
189
|
+
logger.debug 'started apply_constraints environment=%s, knife=%s' % [
|
190
|
+
environment.inspect, knife.inspect
|
157
191
|
]
|
158
|
-
|
159
|
-
ridley = Ridley::from_chef_config knife
|
160
|
-
chef_environment = ridley.environment.find(environment)
|
192
|
+
chef_environment = get_environment environment, knife
|
161
193
|
raise 'Could not find environment "%s"' % environment if chef_environment.nil?
|
162
194
|
chef_environment.cookbook_versions = constraints
|
163
195
|
chef_environment.save
|
data/lib/kitchen_hooks/main.rb
CHANGED
@@ -55,8 +55,14 @@ module KitchenHooks
|
|
55
55
|
aliases: %w[ -d ],
|
56
56
|
desc: 'Location of application database',
|
57
57
|
default: '/etc/kitchen_hooks/app.db'
|
58
|
+
option :tmpdir, \
|
59
|
+
type: :string,
|
60
|
+
aliases: %w[ -t ],
|
61
|
+
desc: 'Location of temporary directory',
|
62
|
+
default: '/tmp'
|
58
63
|
def server
|
59
64
|
App.db! options.database
|
65
|
+
App.tmp! options.tmpdir
|
60
66
|
App.config! JSON::parse(File.read(options.config))
|
61
67
|
App.set :environment, options.environment
|
62
68
|
App.set :port, options.port
|