kitchen_hooks 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 760843807d63eaef7ed7404f29a3753a31bf87cb
4
+ data.tar.gz: b4f84ca3eb75f8186a98aaf18627861fba741218
5
+ SHA512:
6
+ metadata.gz: 94fc3e2fa4ecdd92622de6bcd529572b18d4f75ed72cf98dd236d80fa09643291f41cebc1fb76ecb95523d5696e12c28d1382f097bab71f009168e7cfb0ab14e
7
+ data.tar.gz: 51951023a68f5fc43cd22cae3989e43d6f937f8d069ef5dad4ae8c4ea545ce5c8b7840d591344f4a12088c39466a0297b6b663fb3ee6ba1805dfad7d16c8f293
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *~
2
+ *.db
3
+ *.deb
4
+ *.gem
5
+ *.log
6
+ *.out
7
+ *.pid
8
+ *.swp
9
+ *.pem
10
+ *.pub
11
+ *.priv
12
+ .DS_Store
13
+ .yardoc
14
+ doc
15
+ pkg
16
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'fpm'
7
+ gem 'pry'
8
+ gem 'rake'
9
+ gem 'yard'
10
+ gem 'thin'
11
+ gem 'version'
12
+ gem 'rubygems-tasks'
13
+ end
14
+
15
+ group :test do
16
+ gem 'minitest'
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,214 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kitchen_hooks (1.2.0)
5
+ berkshelf (~> 3)
6
+ chef (~> 11.16.4)
7
+ daybreak (~> 0.3)
8
+ git (~> 1.2)
9
+ mime-types (~> 1)
10
+ retryable (~> 1)
11
+ ridley (~> 4.1)
12
+ sinatra (~> 1.4)
13
+ thor (~> 0)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ addressable (2.3.6)
19
+ arr-pm (0.0.9)
20
+ cabin (> 0)
21
+ backports (3.6.4)
22
+ berkshelf (3.2.1)
23
+ addressable (~> 2.3.4)
24
+ berkshelf-api-client (~> 1.2)
25
+ buff-config (~> 1.0)
26
+ buff-extensions (~> 1.0)
27
+ buff-shell_out (~> 0.1)
28
+ celluloid (~> 0.16.0)
29
+ celluloid-io (~> 0.16.1)
30
+ cleanroom (~> 1.0)
31
+ faraday (~> 0.9.0)
32
+ minitar (~> 0.5.4)
33
+ octokit (~> 3.0)
34
+ retryable (~> 1.3.3)
35
+ ridley (~> 4.0)
36
+ solve (~> 1.1)
37
+ thor (~> 0.19)
38
+ berkshelf-api-client (1.2.0)
39
+ faraday (~> 0.9.0)
40
+ buff-config (1.0.1)
41
+ buff-extensions (~> 1.0)
42
+ varia_model (~> 0.4)
43
+ buff-extensions (1.0.0)
44
+ buff-ignore (1.1.1)
45
+ buff-ruby_engine (0.1.0)
46
+ buff-shell_out (0.2.0)
47
+ buff-ruby_engine (~> 0.1.0)
48
+ cabin (0.6.1)
49
+ celluloid (0.16.0)
50
+ timers (~> 4.0.0)
51
+ celluloid-io (0.16.1)
52
+ celluloid (>= 0.16.0)
53
+ nio4r (>= 1.0.0)
54
+ chef (11.16.4)
55
+ chef-zero (~> 2.1, >= 2.1.4)
56
+ diff-lcs (~> 1.2, >= 1.2.4)
57
+ erubis (~> 2.7)
58
+ ffi-yajl (~> 1.0)
59
+ highline (~> 1.6, >= 1.6.9)
60
+ mime-types (~> 1.16)
61
+ mixlib-authentication (~> 1.3)
62
+ mixlib-cli (~> 1.4)
63
+ mixlib-config (~> 2.0)
64
+ mixlib-log (~> 1.3)
65
+ mixlib-shellout (~> 1.4)
66
+ net-ssh (~> 2.6)
67
+ net-ssh-multi (~> 1.1)
68
+ ohai (~> 7.4)
69
+ plist (~> 3.1.0)
70
+ pry (~> 0.9)
71
+ rest-client (>= 1.0.4, <= 1.6.7)
72
+ chef-zero (2.2.1)
73
+ ffi-yajl (~> 1.1)
74
+ hashie (~> 2.0)
75
+ mixlib-log (~> 1.3)
76
+ rack
77
+ childprocess (0.5.5)
78
+ ffi (~> 1.0, >= 1.0.11)
79
+ clamp (0.6.3)
80
+ cleanroom (1.0.0)
81
+ coderay (1.1.0)
82
+ daemons (1.1.9)
83
+ daybreak (0.3.0)
84
+ dep-selector-libgecode (1.0.2)
85
+ dep_selector (1.0.3)
86
+ dep-selector-libgecode (~> 1.0)
87
+ ffi (~> 1.9)
88
+ diff-lcs (1.2.5)
89
+ erubis (2.7.0)
90
+ eventmachine (1.0.3)
91
+ faraday (0.9.0)
92
+ multipart-post (>= 1.2, < 3)
93
+ ffi (1.9.6)
94
+ ffi-yajl (1.3.1)
95
+ ffi (~> 1.5)
96
+ libyajl2 (~> 1.2)
97
+ fpm (1.3.2)
98
+ arr-pm (~> 0.0.9)
99
+ backports (>= 2.6.2)
100
+ cabin (>= 0.6.0)
101
+ childprocess
102
+ clamp (~> 0.6)
103
+ ffi
104
+ json (>= 1.7.7)
105
+ git (1.2.8)
106
+ hashie (2.1.2)
107
+ highline (1.6.21)
108
+ hitimes (1.2.2)
109
+ ipaddress (0.8.0)
110
+ json (1.8.1)
111
+ libyajl2 (1.2.0)
112
+ method_source (0.8.2)
113
+ mime-types (1.25.1)
114
+ minitar (0.5.4)
115
+ minitest (5.4.3)
116
+ mixlib-authentication (1.3.0)
117
+ mixlib-log
118
+ mixlib-cli (1.5.0)
119
+ mixlib-config (2.1.0)
120
+ mixlib-log (1.6.0)
121
+ mixlib-shellout (1.6.1)
122
+ multipart-post (2.0.0)
123
+ net-http-persistent (2.9.4)
124
+ net-ssh (2.9.1)
125
+ net-ssh-gateway (1.2.0)
126
+ net-ssh (>= 2.6.5)
127
+ net-ssh-multi (1.2.0)
128
+ net-ssh (>= 2.6.5)
129
+ net-ssh-gateway (>= 1.2.0)
130
+ nio4r (1.0.1)
131
+ octokit (3.7.0)
132
+ sawyer (~> 0.6.0, >= 0.5.3)
133
+ ohai (7.4.0)
134
+ ffi (~> 1.9)
135
+ ffi-yajl (~> 1.0)
136
+ ipaddress
137
+ mime-types (~> 1.16)
138
+ mixlib-cli
139
+ mixlib-config (~> 2.0)
140
+ mixlib-log
141
+ mixlib-shellout (~> 1.2)
142
+ systemu (~> 2.6.4)
143
+ wmi-lite (~> 1.0)
144
+ plist (3.1.0)
145
+ pry (0.10.1)
146
+ coderay (~> 1.1.0)
147
+ method_source (~> 0.8.1)
148
+ slop (~> 3.4)
149
+ rack (1.5.2)
150
+ rack-protection (1.5.3)
151
+ rack
152
+ rake (10.4.2)
153
+ rest-client (1.6.7)
154
+ mime-types (>= 1.16)
155
+ retryable (1.3.6)
156
+ ridley (4.1.0)
157
+ addressable
158
+ buff-config (~> 1.0)
159
+ buff-extensions (~> 1.0)
160
+ buff-ignore (~> 1.1)
161
+ buff-shell_out (~> 0.1)
162
+ celluloid (~> 0.16.0)
163
+ celluloid-io (~> 0.16.1)
164
+ erubis
165
+ faraday (~> 0.9.0)
166
+ hashie (>= 2.0.2, < 3.0.0)
167
+ json (>= 1.7.7)
168
+ mixlib-authentication (>= 1.3.0)
169
+ net-http-persistent (>= 2.8)
170
+ retryable
171
+ semverse (~> 1.1)
172
+ varia_model (~> 0.4)
173
+ rubygems-tasks (0.2.4)
174
+ sawyer (0.6.0)
175
+ addressable (~> 2.3.5)
176
+ faraday (~> 0.8, < 0.10)
177
+ semverse (1.2.1)
178
+ sinatra (1.4.5)
179
+ rack (~> 1.4)
180
+ rack-protection (~> 1.4)
181
+ tilt (~> 1.3, >= 1.3.4)
182
+ slop (3.6.0)
183
+ solve (1.2.1)
184
+ dep_selector (~> 1.0)
185
+ semverse (~> 1.1)
186
+ systemu (2.6.4)
187
+ thin (1.6.3)
188
+ daemons (~> 1.0, >= 1.0.9)
189
+ eventmachine (~> 1.0)
190
+ rack (~> 1.0)
191
+ thor (0.19.1)
192
+ tilt (1.4.1)
193
+ timers (4.0.1)
194
+ hitimes
195
+ varia_model (0.4.0)
196
+ buff-extensions (~> 1.0)
197
+ hashie (>= 2.0.2, < 3.0.0)
198
+ version (1.0.0)
199
+ wmi-lite (1.0.0)
200
+ yard (0.8.7.6)
201
+
202
+ PLATFORMS
203
+ ruby
204
+
205
+ DEPENDENCIES
206
+ fpm
207
+ kitchen_hooks!
208
+ minitest
209
+ pry
210
+ rake
211
+ rubygems-tasks
212
+ thin
213
+ version
214
+ yard
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2014 Blue Jeans Network
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'shellwords'
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ require 'rake'
5
+
6
+
7
+ # "rake test"
8
+ require 'rake/testtask'
9
+ Rake::TestTask.new(:test) do |test|
10
+ test.libs << 'lib' << 'test'
11
+ test.test_files = FileList['test/test*.rb']
12
+ test.verbose = true
13
+ end
14
+
15
+ task :default => :test
16
+
17
+
18
+ # "rake yard"
19
+ require 'yard'
20
+ YARD::Rake::YardocTask.new do |t|
21
+ t.files = %w[ --readme Readme.md lib/**/*.rb - VERSION ]
22
+ end
23
+
24
+
25
+ # "rake build"
26
+ require 'rubygems/tasks'
27
+ Gem::Tasks.new({
28
+ push: false,
29
+ sign: {}
30
+ }) do |tasks|
31
+ tasks.console.command = 'pry'
32
+ end
33
+ Gem::Tasks::Sign::Checksum.new sha2: true
34
+
35
+
36
+ # "rake version"
37
+ require 'rake/version_task'
38
+ Rake::VersionTask.new
39
+
40
+
41
+ # "rake fpm"
42
+ desc 'Convert latest .gem to .deb with FPM'
43
+ task fpm: :build do
44
+ latest_gem = Dir['pkg/*.gem'].pop
45
+ system "fpm -s gem -t deb #{Shellwords::escape latest_gem}"
46
+ system 'mv *.deb pkg'
47
+ end
data/Readme.md ADDED
@@ -0,0 +1,61 @@
1
+ # Hooks
2
+
3
+ [Kitchen Hooks](http://git.bluejeansnet.com/kitchen-hooks) provide a GitLab
4
+ WebHoook for automated Chef Server uploads following Kitchen standards.
5
+
6
+
7
+ ## Installation
8
+
9
+ Clone the repo and `rake build`.
10
+
11
+
12
+ ## Usage
13
+
14
+ After installing the gem, the `kitchen_hooks` executable should be available:
15
+
16
+ $ kitchen_hooks help
17
+ Commands:
18
+ kitchen_hooks art # Show application art
19
+ kitchen_hooks help [COMMAND] # Describe available commands or one specific command
20
+ kitchen_hooks server # Start application web server
21
+ kitchen_hooks version # Show application version
22
+
23
+ Use the `server` command to start the WebHook receiver:
24
+
25
+ $ kitchen_hooks server -c etc/config.json -p 80 -e production
26
+ == Sinatra/1.4.5 has taken the stage on 80 for production with backup from Thin
27
+ Thin web server (v1.6.3 codename Protein Powder)
28
+ Maximum connections set to 1024
29
+ Listening on 0.0.0.0:80, CTRL+C to stop
30
+ ...
31
+
32
+
33
+ ## TODO
34
+
35
+ * Use Ridley for data bag, role, and environment uploads to remove Chef dependency
36
+
37
+
38
+ ## Changelog
39
+
40
+ ### 1.3
41
+
42
+ * Added local database to store history (Daybreak), visualized on homepage
43
+
44
+ ### 1.2
45
+
46
+ * Added `bind` option to `server` command
47
+ * Added `berks upload` functionality when tagging realm versions
48
+
49
+ ### 1.1
50
+
51
+ * Moved `examples` to `etc`
52
+ * Started checking in `Gemfile.lock` for future reference
53
+ * Added `port` and `environment` options to `kitchen_hooks server`
54
+ * Move `rake fpm` `.deb` artifacts under `pkg` alongside `.gem` files
55
+ * Commits to the Kitchen trigger data bag, role, and environment uploads
56
+ * Tagging a cookbook with a version triggers a cookbook upload (frozen)
57
+ * Tagging a realm with the name of an environment applies version constraints
58
+
59
+ ### 1.0
60
+
61
+ * Initial release. Gem structure in place, but lacking functionaily
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.3.0
data/bin/kitchen_hooks ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'kitchen_hooks'
3
+ KitchenHooks::Main.start ARGV
data/etc/commit.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "before": "08f20548e398f634979047d0c8114260bcc2949a",
3
+ "after": "fb38bcc884a0579cb52836b00589bca653a9c229",
4
+ "ref": "refs/heads/master",
5
+ "user_id": 645,
6
+ "user_name": "Sean Clemmer",
7
+ "repository": {
8
+ "name": "Kitchen Hooks",
9
+ "url": "git@git.bluejeansnet.com:kitchen-hooks.git",
10
+ "description": "",
11
+ "homepage": "http://git.bluejeansnet.com/kitchen-hooks"
12
+ },
13
+ "commits": [
14
+ {
15
+ "id": "b635fcb8f05e7503c7e6255a6b3e0cebbf487df3",
16
+ "message": "Initial script",
17
+ "timestamp": "2014-11-20T15:45:54-08:00",
18
+ "url": "http://git.bluejeansnet.com/kitchen-hooks/commit/b635fcb8f05e7503c7e6255a6b3e0cebbf487df3",
19
+ "author": {
20
+ "name": "Kelly Wong",
21
+ "email": "kelly@bluejeans.com"
22
+ }
23
+ },
24
+ {
25
+ "id": "b76fd9058de0f0236605f1ac12aaa405e905a383",
26
+ "message": "Add notifications",
27
+ "timestamp": "2014-11-24T18:23:21-08:00",
28
+ "url": "http://git.bluejeansnet.com/kitchen-hooks/commit/b76fd9058de0f0236605f1ac12aaa405e905a383",
29
+ "author": {
30
+ "name": "Kelly Wong",
31
+ "email": "kelly@bluejeans.com"
32
+ }
33
+ },
34
+ {
35
+ "id": "750a5fbb0741977a2b3e5b87e680b8e1beec001e",
36
+ "message": "Make a gem",
37
+ "timestamp": "2014-11-25T17:47:16-08:00",
38
+ "url": "http://git.bluejeansnet.com/kitchen-hooks/commit/750a5fbb0741977a2b3e5b87e680b8e1beec001e",
39
+ "author": {
40
+ "name": "Kelly Wong",
41
+ "email": "kelly@bluejeans.com"
42
+ }
43
+ },
44
+ {
45
+ "id": "e3727928632d4ac30599c6726e9532b5e0cd86d7",
46
+ "message": "Remove MIT license",
47
+ "timestamp": "2014-11-25T18:29:17-08:00",
48
+ "url": "http://git.bluejeansnet.com/kitchen-hooks/commit/e3727928632d4ac30599c6726e9532b5e0cd86d7",
49
+ "author": {
50
+ "name": "Kelly Wong",
51
+ "email": "kelly@bluejeans.com"
52
+ }
53
+ },
54
+ {
55
+ "id": "fb38bcc884a0579cb52836b00589bca653a9c229",
56
+ "message": "Update readme",
57
+ "timestamp": "2014-11-25T18:30:57-08:00",
58
+ "url": "http://git.bluejeansnet.com/kitchen-hooks/commit/fb38bcc884a0579cb52836b00589bca653a9c229",
59
+ "author": {
60
+ "name": "Kelly Wong",
61
+ "email": "kelly@bluejeans.com"
62
+ }
63
+ }
64
+ ],
65
+ "total_commits_count": 5
66
+ }
data/etc/config.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "email": {
3
+ "user": "chef-upload@bluejeansnet.com",
4
+ "port": 25,
5
+ "server": "10.4.5.7",
6
+ "recipient": "sclemmer@bluejeans.com"
7
+ },
8
+ "servers": [
9
+ {
10
+ "name": "Prod",
11
+ "knife": "~/.chef/knife.rb"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path(File.join('..', 'lib'), __FILE__)
3
+ require 'kitchen_hooks'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'kitchen_hooks'
7
+ s.version = KitchenHooks::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.author = KitchenHooks::AUTHOR
10
+ s.email = KitchenHooks::EMAIL
11
+ s.summary = KitchenHooks::SUMMARY
12
+ s.description = KitchenHooks::SUMMARY + '.'
13
+ s.homepage = KitchenHooks::HOMEPAGE
14
+ s.license = KitchenHooks::LICENSE
15
+
16
+ s.add_runtime_dependency 'daybreak', '~> 0.3'
17
+ s.add_runtime_dependency 'retryable', '~> 1'
18
+ s.add_runtime_dependency 'berkshelf', '~> 3'
19
+ s.add_runtime_dependency 'mime-types', '~> 1'
20
+ s.add_runtime_dependency 'chef', '~> 11.16.4'
21
+ s.add_runtime_dependency 'thor', '~> 0'
22
+ s.add_runtime_dependency 'git', '~> 1.2'
23
+ s.add_runtime_dependency 'sinatra', '~> 1.4'
24
+ s.add_runtime_dependency 'ridley', '~> 4.1'
25
+
26
+ s.files = `git ls-files`.split("\n")
27
+ s.test_files = `git ls-files -- test/*`.split("\n")
28
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File::basename(f) }
29
+ s.require_paths = %w[ lib ]
30
+ end
@@ -0,0 +1,112 @@
1
+ require 'pathname'
2
+ require 'json'
3
+
4
+ require 'daybreak'
5
+ require 'sinatra/base'
6
+
7
+ require_relative 'helpers'
8
+ require_relative 'metadata'
9
+
10
+
11
+ module KitchenHooks
12
+ class App < Sinatra::Application
13
+ set :root, File.join(KitchenHooks::ROOT, 'web')
14
+
15
+ enable :sessions
16
+
17
+ include KitchenHooks::Helpers
18
+
19
+ def self.db! db_path
20
+ @@db = Daybreak::DB.new db_path
21
+ end
22
+
23
+ def db &block
24
+ if block_given?
25
+ @@db.synchronize do
26
+ yield
27
+ end
28
+ else
29
+ return @@db
30
+ end
31
+ end
32
+
33
+ def database
34
+ db_entries = {}
35
+ db.each do |k, v|
36
+ db_entries[k] = v
37
+ end
38
+ return db_entries.sort_by { |stamp, _| stamp }
39
+ end
40
+
41
+ def self.config! config
42
+ @@knives = config['servers'].map do |s|
43
+ Pathname.new(s['knife']).expand_path.realpath.to_s
44
+ end
45
+ end
46
+
47
+ def knives ; @@knives ||= [] end
48
+
49
+
50
+ get '/' do
51
+ erb :app, locals: {
52
+ database: database
53
+ }
54
+ end
55
+
56
+ get '/favicon.ico' do
57
+ send_file File.join(settings.root, 'favicon.ico'), \
58
+ :disposition => 'inline'
59
+ end
60
+
61
+ get %r|/app/(.*)| do |fn|
62
+ send_file File.join(settings.root, 'app', fn), \
63
+ :disposition => 'inline'
64
+ end
65
+
66
+
67
+ post '/' do
68
+ request.body.rewind
69
+ event = JSON::parse request.body.read
70
+
71
+ if commit_to_kitchen?(event)
72
+ perform_kitchen_upload(event, knives)
73
+ save_event \
74
+ type: 'kitchen upload',
75
+ author: author(event),
76
+ repo: repo_name(event),
77
+ raw: event
78
+ end
79
+
80
+ if tagged_commit_to_cookbook?(event) &&
81
+ tag_name(event) =~ /^v\d+/ # Tagged with version we're releasing
82
+ perform_cookbook_upload(event, knives)
83
+ save_event \
84
+ type: 'cookbook upload',
85
+ author: author(event),
86
+ repo: repo_name(event),
87
+ cookbook: cookbook_name(event),
88
+ raw: event
89
+ end
90
+
91
+ if tagged_commit_to_realm?(event) &&
92
+ tag_name(event) =~ /^bjn_/ # Tagged with environment we're pinning
93
+ perform_constraint_application(event, knives)
94
+ save_event \
95
+ type: 'constraint application',
96
+ author: author(event),
97
+ repo: repo_name(event),
98
+ cookbook: cookbook_name(event),
99
+ raw: event
100
+ end
101
+
102
+ db.flush
103
+ end
104
+
105
+ private
106
+ def save_event e
107
+ db do
108
+ db[Time.now.to_f] = e
109
+ end
110
+ end
111
+ end
112
+ end