kitchen_hooks 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/etc/commit.json +1 -1
- data/lib/kitchen_hooks/app.rb +6 -14
- data/lib/kitchen_hooks/helpers.rb +50 -11
- data/lib/kitchen_hooks/main.rb +3 -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: 0fcd91cc1571abd32219e6c42c434d363ecdd6b6
|
4
|
+
data.tar.gz: 2ecee3e126267b8886eafa3913aab9d2b8bb1bdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcbff46645c76cec5afd65ffe4af351fb54907eeebdd473b2ba3085d0f049c8ecd0c6cf006cdb315167656de967086fc28e185f9a9f8fa17a6502f99f594cc2b
|
7
|
+
data.tar.gz: d67edc3b6818bdd3dc6524b1a672dbac2a7687b6351022a1584ad52d602315bfe887dd6c2eb156a521f6a921846bfbf2476eb6c2b43cf518d7cd7e3bf4e98806
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.4
|
data/etc/commit.json
CHANGED
data/lib/kitchen_hooks/app.rb
CHANGED
@@ -117,14 +117,6 @@ module KitchenHooks
|
|
117
117
|
end
|
118
118
|
|
119
119
|
|
120
|
-
def err_out e, msg
|
121
|
-
logger.error msg
|
122
|
-
logger.error e.message
|
123
|
-
logger.error e.backtrace.inspect
|
124
|
-
msg
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
120
|
def process event
|
129
121
|
if event.nil? # JSON parse failed
|
130
122
|
mark event, 'failure', 'Could not parse WebHook payload'
|
@@ -133,9 +125,9 @@ module KitchenHooks
|
|
133
125
|
|
134
126
|
if commit_to_kitchen?(event)
|
135
127
|
possible_error = begin
|
136
|
-
perform_kitchen_upload
|
128
|
+
perform_kitchen_upload event, knives
|
137
129
|
rescue Exception => e
|
138
|
-
|
130
|
+
report_error e, 'Could not perform kitchen upload'
|
139
131
|
end
|
140
132
|
mark event, 'kitchen upload', possible_error
|
141
133
|
end
|
@@ -143,9 +135,9 @@ module KitchenHooks
|
|
143
135
|
if tagged_commit_to_cookbook?(event) &&
|
144
136
|
tag_name(event) =~ /^v\d+/ # Cookbooks tagged with a version
|
145
137
|
possible_error = begin
|
146
|
-
perform_cookbook_upload
|
138
|
+
perform_cookbook_upload event, knives
|
147
139
|
rescue Exception => e
|
148
|
-
|
140
|
+
report_error e, 'Could not perform cookbook upload'
|
149
141
|
end
|
150
142
|
mark event, 'cookbook upload', possible_error
|
151
143
|
end
|
@@ -153,9 +145,9 @@ module KitchenHooks
|
|
153
145
|
if tagged_commit_to_realm?(event) &&
|
154
146
|
tag_name(event) =~ /^bjn_/ # Realms tagged with an environment
|
155
147
|
possible_error = begin
|
156
|
-
perform_constraint_application
|
148
|
+
perform_constraint_application event, knives
|
157
149
|
rescue Exception => e
|
158
|
-
|
150
|
+
report_error e, 'Could not apply constraints'
|
159
151
|
end
|
160
152
|
mark event, 'constraint application', possible_error
|
161
153
|
end
|
@@ -13,7 +13,19 @@ Berkshelf.logger = Logger.new $stdout
|
|
13
13
|
module KitchenHooks
|
14
14
|
module Helpers
|
15
15
|
|
16
|
+
def report_error e, msg=nil
|
17
|
+
msg = e.message if msg.nil?
|
18
|
+
logger.error msg
|
19
|
+
logger.error e.message
|
20
|
+
logger.error e.backtrace.inspect
|
21
|
+
msg
|
22
|
+
end
|
23
|
+
|
24
|
+
|
16
25
|
def perform_constraint_application event, knives
|
26
|
+
logger.debug 'started perform_constraint_application event=%s, knives=%s' % [
|
27
|
+
event.inspect, knives.inspect
|
28
|
+
]
|
17
29
|
tmp_clone event, :tagged_commit do |clone|
|
18
30
|
Dir.chdir clone do
|
19
31
|
logger.info 'Applying constraints'
|
@@ -25,13 +37,16 @@ module KitchenHooks
|
|
25
37
|
end
|
26
38
|
end
|
27
39
|
|
28
|
-
logger.
|
29
|
-
return
|
40
|
+
logger.debug "finished perform_constraint_application: #{event['after']}"
|
41
|
+
return # no error
|
30
42
|
end
|
31
43
|
|
32
44
|
|
33
45
|
def perform_kitchen_upload event, knives
|
34
46
|
return false unless commit_to_master?(event)
|
47
|
+
logger.debug 'started perform_kitchen_upload event=%s, knives=%s' % [
|
48
|
+
event.inspect, knives.inspect
|
49
|
+
]
|
35
50
|
|
36
51
|
tmp_clone event, :latest_commit do |clone|
|
37
52
|
Dir.chdir clone do
|
@@ -50,12 +65,16 @@ module KitchenHooks
|
|
50
65
|
end
|
51
66
|
end
|
52
67
|
|
53
|
-
logger.
|
54
|
-
return
|
68
|
+
logger.debug "finished perform_kitchen_upload: #{event['after']}"
|
69
|
+
return # no error
|
55
70
|
end
|
56
71
|
|
57
72
|
|
58
73
|
def perform_cookbook_upload event, knives
|
74
|
+
logger.debug 'started perform_cookbook_upload event=%s, knives=%s' % [
|
75
|
+
event.inspect, knives.inspect
|
76
|
+
]
|
77
|
+
|
59
78
|
tmp_clone event, :tagged_commit do |clone|
|
60
79
|
Dir.chdir clone do
|
61
80
|
tagged_version = tag_name(event).delete('v')
|
@@ -79,12 +98,15 @@ module KitchenHooks
|
|
79
98
|
end
|
80
99
|
end
|
81
100
|
|
82
|
-
logger.
|
83
|
-
return
|
101
|
+
logger.debug "finished cookbook_upload: #{event['after']}"
|
102
|
+
return # no error
|
84
103
|
end
|
85
104
|
|
86
105
|
|
87
106
|
def berks_upload berksfile, knife, options={}
|
107
|
+
logger.debug 'started berks_upload berksfile=%s, knife=%s' % [
|
108
|
+
berksfile.inspect, knife.inspect
|
109
|
+
]
|
88
110
|
ridley = Ridley::from_chef_config knife
|
89
111
|
options.merge! \
|
90
112
|
berksfile: berksfile,
|
@@ -97,24 +119,31 @@ module KitchenHooks
|
|
97
119
|
berksfile = Berkshelf::Berksfile.from_options(options)
|
98
120
|
berksfile.install
|
99
121
|
berksfile.upload [], options
|
122
|
+
logger.debug 'finished berks_upload: %s' % berksfile
|
100
123
|
end
|
101
124
|
|
102
125
|
|
103
126
|
def tmp_clone event, commit_method, &block
|
127
|
+
logger.debug 'started tmp_clone event=%s, commit_method=%s' % [
|
128
|
+
event.inspect, commit_method.inspect
|
129
|
+
]
|
104
130
|
Dir.mktmpdir do |tmp|
|
105
|
-
dir = File::join tmp, cookbook_name(event)
|
131
|
+
dir = File::join tmp, Time.now.to_f.to_s, cookbook_name(event)
|
132
|
+
FileUtils.mkdir_p dir
|
106
133
|
repo = Git.clone git_daemon_style_url(event), dir, log: $stdout
|
107
134
|
commit = self.send(commit_method, event)
|
108
135
|
repo.checkout commit
|
109
136
|
yield dir
|
110
|
-
FileUtils.rm_rf dir
|
111
137
|
end
|
138
|
+
logger.debug 'finished tmp_clone'
|
112
139
|
end
|
113
140
|
|
114
141
|
|
115
142
|
def with_each_knife command, knives
|
116
143
|
knives.map do |k|
|
117
|
-
|
144
|
+
cmd = "knife #{command} --config #{Shellwords::escape k}"
|
145
|
+
logger.debug 'with_each_knife: %s' % cmd
|
146
|
+
`#{cmd}`
|
118
147
|
end
|
119
148
|
end
|
120
149
|
|
@@ -123,12 +152,16 @@ module KitchenHooks
|
|
123
152
|
# Ripped from Berkshelf::Cli::apply and Berkshelf::Lockfile::apply
|
124
153
|
# https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/cli.rb
|
125
154
|
# https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/lockfile.rb
|
155
|
+
logger.debug 'started apply_constraints constraints=%s, environment=%s, knife=%s' % [
|
156
|
+
constraints.inspect, environment.inspect, knife.inspect
|
157
|
+
]
|
126
158
|
Celluloid.logger = nil
|
127
159
|
ridley = Ridley::from_chef_config knife
|
128
160
|
chef_environment = ridley.environment.find(environment)
|
129
|
-
raise if chef_environment.nil?
|
161
|
+
raise 'Could not find environment "%s"' % environment if chef_environment.nil?
|
130
162
|
chef_environment.cookbook_versions = constraints
|
131
163
|
chef_environment.save
|
164
|
+
logger.debug 'finished apply_constraints: %s' % environment
|
132
165
|
end
|
133
166
|
|
134
167
|
|
@@ -137,14 +170,19 @@ module KitchenHooks
|
|
137
170
|
# https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/cli.rb
|
138
171
|
# https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/lockfile.rb
|
139
172
|
lockfile = Berkshelf::Lockfile.from_file lockfile_path
|
140
|
-
lockfile.graph.locks.inject({}) do |hash, (name, dependency)|
|
173
|
+
constraints = lockfile.graph.locks.inject({}) do |hash, (name, dependency)|
|
141
174
|
hash[name] = "= #{dependency.locked_version.to_s}"
|
142
175
|
hash
|
143
176
|
end
|
177
|
+
logger.debug 'constraints: %s -> %s' % [ lockfile_path, constraints ]
|
178
|
+
return constraints
|
144
179
|
end
|
145
180
|
|
146
181
|
|
147
182
|
def upload_environment environment, knife
|
183
|
+
logger.debug 'started upload_environment environment=%s, knife=%s' % [
|
184
|
+
environment.inspect, knife.inspect
|
185
|
+
]
|
148
186
|
# Load the local environment from a JSON file
|
149
187
|
local_environment = JSON::parse File.read(environment)
|
150
188
|
local_environment.delete 'chef_type'
|
@@ -168,6 +206,7 @@ module KitchenHooks
|
|
168
206
|
|
169
207
|
# Make it so!
|
170
208
|
chef_environment.save
|
209
|
+
logger.debug 'finished upload_environment: %s' % environment
|
171
210
|
end
|
172
211
|
|
173
212
|
|
data/lib/kitchen_hooks/main.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
require 'thor'
|
2
4
|
|
3
5
|
require_relative 'app'
|
@@ -62,6 +64,7 @@ module KitchenHooks
|
|
62
64
|
App.set :raise_errors, true
|
63
65
|
App.set :dump_errors, true
|
64
66
|
App.set :show_exceptions, true
|
67
|
+
App.set :logging, ::Logger::DEBUG
|
65
68
|
App.run!
|
66
69
|
|
67
70
|
at_exit do
|