knife-spork 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +78 -4
- data/knife-spork.gemspec +3 -2
- data/lib/chef/knife/spork-bump.rb +34 -11
- data/lib/chef/knife/spork-check.rb +37 -3
- data/lib/chef/knife/spork-promote.rb +118 -31
- data/lib/chef/knife/spork-upload.rb +34 -0
- data/lib/knife-spork.rb +1 -1
- metadata +74 -35
data/README.md
CHANGED
@@ -2,6 +2,78 @@
|
|
2
2
|
|
3
3
|
A workflow plugin for Chef::Knife which helps multiple devs work on the same chef server and repo without treading on eachothers toes. This plugin was designed around the workflow we have here at Etsy, where several people are working on the chef repo and chef server at the same time. It contains several functions, documented below:
|
4
4
|
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
## SCRIPT INSTALL
|
8
|
+
|
9
|
+
Copy spork-* script from lib/chef/knife/spork-*.rb to your ~/.chef/plugins/knife directory.
|
10
|
+
|
11
|
+
## GEM INSTALL
|
12
|
+
knife-spork is available on rubygems.org - if you have that source in your gemrc, you can simply use:
|
13
|
+
|
14
|
+
````
|
15
|
+
gem install knife-spork
|
16
|
+
````
|
17
|
+
|
18
|
+
# Spork Configuration
|
19
|
+
|
20
|
+
Out of the box, knife spork will work with no configuration. However, you can optionally enable several features to enhance it's functionality.
|
21
|
+
|
22
|
+
Knife Spork will look for it's config file in the following locations, in ascending order of precedence.
|
23
|
+
|
24
|
+
* <chef-repo>/config/spork-config.yml
|
25
|
+
* /etc/spork-config.yml
|
26
|
+
* ~/.chef/spork-config.yml
|
27
|
+
|
28
|
+
Anything set in the config file in your home directory for example, will override options set in your chef repo or /etc.
|
29
|
+
|
30
|
+
Below is a sample config file with all supported options enabled below, followed by an explanation of each section.
|
31
|
+
|
32
|
+
````
|
33
|
+
git:
|
34
|
+
enabled: true
|
35
|
+
irccat:
|
36
|
+
enabled: true
|
37
|
+
server: irccat.mycompany.com
|
38
|
+
port: 12345
|
39
|
+
channel: "#chef"
|
40
|
+
graphite:
|
41
|
+
enabled: true
|
42
|
+
server: graphite.mycompany.com
|
43
|
+
port: 2003
|
44
|
+
gist:
|
45
|
+
enabled: true
|
46
|
+
in_chef: true
|
47
|
+
chef_path: cookbooks/gist/files/default/gist
|
48
|
+
path: /usr/bin/gist
|
49
|
+
default_environments: [ production, development ]
|
50
|
+
````
|
51
|
+
## Git
|
52
|
+
|
53
|
+
This section enables a couple of git commands which will run as part of your spork workflow, namely:
|
54
|
+
|
55
|
+
* When you bump a cookbook's version, the relevant metadata.rb file will be git added
|
56
|
+
* When you promote an environment, git pull will be run before your changes are made.
|
57
|
+
|
58
|
+
## Irccat
|
59
|
+
|
60
|
+
If you're using the irccat (https://github.com/RJ/irccat) irc bot, this lets you post notifications to the channel of your choice. It currently notifies on
|
61
|
+
|
62
|
+
* When a cookbook is uploaded using spork upload
|
63
|
+
* When an environment is promoted to the server using promote --remote
|
64
|
+
|
65
|
+
## Graphite
|
66
|
+
|
67
|
+
This lets you send to a graphite metric when promote --remote is performed. It send to the metric deploys.chef.<environment>
|
68
|
+
|
69
|
+
## Gist
|
70
|
+
|
71
|
+
This allows you to generate an optional gist of environment changes which will be added to irccat notifications on promote --remote. It supports the https://rubygems.org/gems/gist, and contains two parameters to use a version in your chef repo, or a version installed somewhere else locally.
|
72
|
+
|
73
|
+
## Default Environments
|
74
|
+
|
75
|
+
This allows you to specify a default list of environments you want to promote changes to. If this option is configured and you *ommit* the environment parameter when promoting, ie knife spork promote <cookbook>, then it will promote to all environments in this list.
|
76
|
+
|
5
77
|
# Spork Check
|
6
78
|
|
7
79
|
This function is designed to help you avoid trampling on other people's cookbook versions, and to make sure that when you come to version your own work it's easy to see what version numbers have already been used and if the one you're using will overwrite anything.
|
@@ -9,9 +81,11 @@ This function is designed to help you avoid trampling on other people's cookbook
|
|
9
81
|
## Usage
|
10
82
|
|
11
83
|
````
|
12
|
-
knife spork check COOKBOOK
|
84
|
+
knife spork check COOKBOOK ( --all)
|
13
85
|
````
|
14
86
|
|
87
|
+
By default, spork check only shows the 5 most recent remote cookbook versions. Add the --all option if you want to see everything.
|
88
|
+
|
15
89
|
## Example (Checking an Unfrozen Cookbook with version clash)
|
16
90
|
|
17
91
|
````
|
@@ -20,7 +94,7 @@ Checking versions for cookbook apache...
|
|
20
94
|
|
21
95
|
Current local version: 0.1.0
|
22
96
|
|
23
|
-
Remote versions:
|
97
|
+
Remote versions (Max. 5 most recent only):
|
24
98
|
*0.1.0, unfrozen
|
25
99
|
0.0.0, unfrozen
|
26
100
|
|
@@ -37,7 +111,7 @@ Checking versions for cookbook apache2...
|
|
37
111
|
|
38
112
|
Current local version: 1.0.6
|
39
113
|
|
40
|
-
Remote versions:
|
114
|
+
Remote versions (Max. 5 most recent only):
|
41
115
|
*1.0.6, frozen
|
42
116
|
1.0.5, frozen
|
43
117
|
1.0.4, frozen
|
@@ -59,7 +133,7 @@ Checking versions for cookbook apache2...
|
|
59
133
|
|
60
134
|
Current local version: 1.0.7
|
61
135
|
|
62
|
-
Remote versions:
|
136
|
+
Remote versions (Max. 5 most recent only):
|
63
137
|
1.0.6, frozen
|
64
138
|
1.0.5, frozen
|
65
139
|
1.0.4, frozen
|
data/knife-spork.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'knife-spork'
|
16
|
-
s.version = '0.1.
|
17
|
-
s.date = '2012-
|
16
|
+
s.version = '0.1.4'
|
17
|
+
s.date = '2012-02-03'
|
18
18
|
s.rubyforge_project = 'knife-spork'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
## that are needed for an end user to actually USE your code.
|
43
43
|
s.add_dependency('chef', [">= 0.10.4"])
|
44
44
|
s.add_dependency('git', [">= 1.2.5"])
|
45
|
+
s.add_dependency('app_conf', [">= 0.3.0"])
|
45
46
|
|
46
47
|
## Leave this section as-is. It will be automatically generated from the
|
47
48
|
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
@@ -6,6 +6,7 @@
|
|
6
6
|
# Based on the knife-cookbook-bump plugin by:
|
7
7
|
# Alalanta (no license specified)
|
8
8
|
|
9
|
+
require 'app_conf'
|
9
10
|
require 'chef/knife'
|
10
11
|
require 'chef/cookbook_loader'
|
11
12
|
require 'chef/cookbook_uploader'
|
@@ -28,9 +29,30 @@ module KnifeSpork
|
|
28
29
|
|
29
30
|
def run
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
if RUBY_VERSION.to_f < 1.9
|
33
|
+
ui.fatal "Sorry, knife-spork requires ruby 1.9 or newer."
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
33
37
|
self.config = Chef::Config.merge!(config)
|
38
|
+
|
39
|
+
if File.exists?("#{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml")
|
40
|
+
AppConf.load("#{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml")
|
41
|
+
ui.msg "Loaded config file #{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml...\n\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
if File.exists?("/etc/spork-config.yml")
|
45
|
+
AppConf.load("/etc/spork-config.yml")
|
46
|
+
ui.msg "Loaded config file /etc/spork-config.yml...\n\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
if File.exists?(File.expand_path("~/.chef/spork-config.yml"))
|
50
|
+
AppConf.load(File.expand_path("~/.chef/spork-config.yml"))
|
51
|
+
ui.msg "Loaded config file #{File.expand_path("~/.chef/spork-config.yml")}...\n\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
bump_type=""
|
55
|
+
|
34
56
|
if config.has_key?(:cookbook_path)
|
35
57
|
cookbook_path = config["cookbook_path"]
|
36
58
|
else
|
@@ -73,12 +95,13 @@ module KnifeSpork
|
|
73
95
|
patch(cookbook_path, cookbook, patch_type)
|
74
96
|
end
|
75
97
|
|
76
|
-
if
|
77
|
-
|
78
|
-
|
79
|
-
|
98
|
+
if !AppConf.git.nil? && AppConf.git.enabled
|
99
|
+
if !@@gitavail
|
100
|
+
ui.msg "Git gem not available, skipping git add.\n\n"
|
101
|
+
else
|
102
|
+
git_add(cookbook)
|
103
|
+
end
|
80
104
|
end
|
81
|
-
|
82
105
|
end
|
83
106
|
|
84
107
|
|
@@ -145,13 +168,13 @@ module KnifeSpork
|
|
145
168
|
ui.msg "Git add'ing #{path}cookbooks/#{cookbook}/metadata.rb\n\n"
|
146
169
|
g.add("#{path}cookbooks/#{cookbook}/metadata.rb")
|
147
170
|
rescue ArgumentError => e
|
148
|
-
|
171
|
+
ui.warn "Git: The root of your chef repo doesn't look like it's a git repo. Skipping git add...\n\n"
|
149
172
|
rescue
|
150
|
-
|
151
|
-
|
173
|
+
ui.warn "Git: Cookbook uploaded, but something went wrong with git add metadata.rb, Dumping log info..."
|
174
|
+
ui.warn "#{strio.string}"
|
152
175
|
end
|
153
176
|
end
|
154
|
-
|
177
|
+
end
|
155
178
|
end
|
156
179
|
|
157
180
|
end
|
@@ -4,6 +4,7 @@
|
|
4
4
|
# License:: GPL
|
5
5
|
|
6
6
|
|
7
|
+
require 'app_conf'
|
7
8
|
require 'json'
|
8
9
|
require 'chef/knife'
|
9
10
|
require 'chef/cookbook_loader'
|
@@ -17,11 +18,36 @@ module KnifeSpork
|
|
17
18
|
require 'chef/cookbook_version'
|
18
19
|
end
|
19
20
|
banner "knife spork check COOKBOOK"
|
20
|
-
|
21
|
+
|
22
|
+
option :all,
|
23
|
+
:short => "--a",
|
24
|
+
:long => "--all",
|
25
|
+
:description => "Show all uploaded versions of the cookbook"
|
26
|
+
|
21
27
|
def run
|
22
28
|
|
29
|
+
if RUBY_VERSION.to_f < 1.9
|
30
|
+
ui.fatal "Sorry, knife-spork requires ruby 1.9 or newer."
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
23
34
|
self.config = Chef::Config.merge!(config)
|
24
35
|
|
36
|
+
if File.exists?("#{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml")
|
37
|
+
AppConf.load("#{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml")
|
38
|
+
ui.msg "Loaded config file #{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml...\n\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
if File.exists?("/etc/spork-config.yml")
|
42
|
+
AppConf.load("/etc/spork-config.yml")
|
43
|
+
ui.msg "Loaded config file /etc/spork-config.yml...\n\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
if File.exists?(File.expand_path("~/.chef/spork-config.yml"))
|
47
|
+
AppConf.load(File.expand_path("~/.chef/spork-config.yml"))
|
48
|
+
ui.msg "Loaded config file #{File.expand_path("~/.chef/spork-config.yml")}...\n\n"
|
49
|
+
end
|
50
|
+
|
25
51
|
if config.has_key?(:cookbook_path)
|
26
52
|
cookbook_path = config["cookbook_path"]
|
27
53
|
else
|
@@ -63,7 +89,11 @@ module KnifeSpork
|
|
63
89
|
api_endpoint = env ? "environments/#{env}/cookbooks/#{cookbook}" : "cookbooks/#{cookbook}"
|
64
90
|
cookbooks = rest.get_rest(api_endpoint)
|
65
91
|
versions = cookbooks[cookbook]["versions"]
|
66
|
-
|
92
|
+
if config[:all]
|
93
|
+
return versions
|
94
|
+
else
|
95
|
+
return versions[0..4]
|
96
|
+
end
|
67
97
|
end
|
68
98
|
|
69
99
|
def check_versions(cookbook, local_version, remote_versions)
|
@@ -74,7 +104,11 @@ module KnifeSpork
|
|
74
104
|
ui.msg ""
|
75
105
|
ui.msg "Current local version: #{local_version}"
|
76
106
|
ui.msg ""
|
77
|
-
|
107
|
+
if config[:all]
|
108
|
+
ui.msg "Remote versions:"
|
109
|
+
else
|
110
|
+
ui.msg "Remote versions (Max. 5 most recent only):"
|
111
|
+
end
|
78
112
|
remote_versions.each do |v|
|
79
113
|
|
80
114
|
version_frozen = check_frozen(cookbook,v["version"])
|
@@ -25,8 +25,10 @@
|
|
25
25
|
# limitations under the License.
|
26
26
|
#
|
27
27
|
|
28
|
+
require 'app_conf'
|
28
29
|
require 'chef/knife'
|
29
30
|
require 'json'
|
31
|
+
require 'socket'
|
30
32
|
|
31
33
|
module KnifeSpork
|
32
34
|
class SporkPromote < Chef::Knife
|
@@ -57,49 +59,91 @@ module KnifeSpork
|
|
57
59
|
:default => nil
|
58
60
|
|
59
61
|
def run
|
62
|
+
|
63
|
+
if RUBY_VERSION.to_f < 1.9
|
64
|
+
ui.fatal "Sorry, knife-spork requires ruby 1.9 or newer."
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
self.config = Chef::Config.merge!(config)
|
69
|
+
|
70
|
+
if File.exists?("#{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml")
|
71
|
+
AppConf.load("#{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml")
|
72
|
+
ui.msg "Loaded config file #{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml...\n\n"
|
73
|
+
end
|
74
|
+
|
75
|
+
if File.exists?("/etc/spork-config.yml")
|
76
|
+
AppConf.load("/etc/spork-config.yml")
|
77
|
+
ui.msg "Loaded config file /etc/spork-config.yml...\n\n"
|
78
|
+
end
|
79
|
+
|
80
|
+
if File.exists?(File.expand_path("~/.chef/spork-config.yml"))
|
81
|
+
AppConf.load(File.expand_path("~/.chef/spork-config.yml"))
|
82
|
+
ui.msg "Loaded config file #{File.expand_path("~/.chef/spork-config.yml")}...\n\n"
|
83
|
+
end
|
84
|
+
|
60
85
|
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
61
86
|
|
62
|
-
if @name_args.empty?
|
87
|
+
if @name_args.empty? && AppConf.default_environments.nil?
|
63
88
|
show_usage
|
64
89
|
ui.error("You must specify a cookbook name and an environment")
|
65
90
|
exit 1
|
66
|
-
elsif @name_args.
|
91
|
+
elsif @name_args.empty? && !AppConf.default_environments.nil?
|
92
|
+
show_usage
|
93
|
+
ui.error("Default environments loaded from config, but you must specify a cookbook name")
|
94
|
+
exit 1
|
95
|
+
elsif @name_args.size != 2 && AppConf.default_environments.nil?
|
67
96
|
show_usage
|
68
97
|
ui.error("You must specify a cookbook name and an environment")
|
69
98
|
exit 1
|
70
99
|
end
|
71
|
-
|
72
|
-
if
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@cookbook = @name_args[1]
|
79
|
-
@environment = loader.load_from("environments", @name_args[0] + ".json")
|
80
|
-
|
81
|
-
if @cookbook == "all"
|
82
|
-
ui.msg "Promoting ALL cookbooks to environment #{@environment}\n\n"
|
83
|
-
cookbook_names = get_all_cookbooks
|
84
|
-
cookbook_names.each do |c|
|
85
|
-
@environment = promote(@environment, c)
|
100
|
+
|
101
|
+
if !AppConf.git.nil? && AppConf.git.enabled
|
102
|
+
if !@@gitavail
|
103
|
+
ui.msg "Git gem not available, skipping git pull.\n\n"
|
104
|
+
else
|
105
|
+
git_pull_if_repo
|
86
106
|
end
|
107
|
+
end
|
108
|
+
|
109
|
+
if AppConf.default_environments.nil?
|
110
|
+
environments = [ @name_args[0] ]
|
111
|
+
@cookbook = @name_args[1]
|
112
|
+
elsif !AppConf.default_environments.nil? && @name_args.size == 2
|
113
|
+
environments = [ @name_args[0] ]
|
114
|
+
@cookbook = @name_args[1]
|
87
115
|
else
|
88
|
-
|
116
|
+
environments = AppConf.default_environments
|
117
|
+
@cookbook = @name_args[0]
|
89
118
|
end
|
119
|
+
|
120
|
+
environments.each do |e|
|
121
|
+
ui.msg ""
|
122
|
+
ui.msg "Environment: #{e}"
|
123
|
+
@environment = loader.load_from("environments", "#{e}.json")
|
90
124
|
|
91
|
-
|
92
|
-
|
93
|
-
|
125
|
+
if @cookbook == "all"
|
126
|
+
ui.msg "Promoting ALL cookbooks to environment #{@environment}"
|
127
|
+
cookbook_names = get_all_cookbooks
|
128
|
+
cookbook_names.each do |c|
|
129
|
+
@environment = promote(@environment, c)
|
130
|
+
end
|
131
|
+
else
|
132
|
+
@environment = promote(@environment, @cookbook)
|
133
|
+
end
|
94
134
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
ui.info "\nPromotion complete, and environment uploaded."
|
99
|
-
else
|
100
|
-
ui.info "\nPromotion complete! Please remember to upload your changed Environment file to the Chef Server."
|
101
|
-
end
|
135
|
+
ui.msg "Saving changes into #{e}.json"
|
136
|
+
new_environment_json = pretty_print(@environment)
|
137
|
+
save_environment_changes(e,new_environment_json)
|
102
138
|
|
139
|
+
if config[:remote]
|
140
|
+
ui.msg "Uploading #{e} to server"
|
141
|
+
save_environment_changes_remote("#{e}.json")
|
142
|
+
ui.info "\nPromotion complete, and environment uploaded."
|
143
|
+
else
|
144
|
+
ui.info "\nPromotion complete! Please remember to upload your changed #{e}.json to the Chef Server."
|
145
|
+
end
|
146
|
+
end
|
103
147
|
end
|
104
148
|
|
105
149
|
def update_version_constraints(environment,cookbook,version_constraint)
|
@@ -147,7 +191,39 @@ module KnifeSpork
|
|
147
191
|
def save_environment_changes_remote(environment)
|
148
192
|
@loader ||= Knife::Core::ObjectLoader.new(Chef::Environment, ui)
|
149
193
|
updated = loader.load_from("environments", environment)
|
194
|
+
|
195
|
+
env_server = Chef::Environment.load(environment.gsub(".json","")).to_hash["cookbook_versions"]
|
196
|
+
env_local = updated.to_hash["cookbook_versions"]
|
197
|
+
env_diff = env_server.diff(env_local)
|
198
|
+
|
150
199
|
updated.save
|
200
|
+
|
201
|
+
if !AppConf.gist.nil? && AppConf.gist.enabled
|
202
|
+
if AppConf.gist.in_chef
|
203
|
+
gist_path = AppConf.gist.chef_path
|
204
|
+
else
|
205
|
+
gist_path = AppConf.gist.path
|
206
|
+
end
|
207
|
+
|
208
|
+
msg = "Environment #{environment.gsub(".json","")} uploaded at #{Time.now.getutc} by #{ENV['USER']}\n\nConstraints updated on server in this version:\n\n#{env_diff.collect { |k, v| "#{k}: #{v}\n" }.join}"
|
209
|
+
@gist = %x[ echo "#{msg}" | #{gist_path}]
|
210
|
+
end
|
211
|
+
|
212
|
+
if !AppConf.irccat.nil? && AppConf.irccat.enabled
|
213
|
+
message = "#{AppConf.irccat.channel} CHEF: #{ENV['USER']} uploaded environment #{environment.gsub(".json","")} #{@gist}"
|
214
|
+
s = TCPSocket.open(AppConf.irccat.server,AppConf.irccat.port)
|
215
|
+
s.write(message)
|
216
|
+
s.close
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
if !AppConf.graphite.nil? && AppConf.graphite.enabled
|
221
|
+
time = Time.now
|
222
|
+
message = "deploys.chef.#{environment.gsub(".json","")} 1 #{time.to_i}\n"
|
223
|
+
s = TCPSocket.open(AppConf.graphite.server,AppConf.graphite.port)
|
224
|
+
s.write(message)
|
225
|
+
s.close
|
226
|
+
end
|
151
227
|
end
|
152
228
|
|
153
229
|
def save_environment_changes(environment,envjson)
|
@@ -211,10 +287,10 @@ module KnifeSpork
|
|
211
287
|
ui.msg "Pulling latest changes from git\n\n"
|
212
288
|
g.pull
|
213
289
|
rescue ArgumentError => e
|
214
|
-
|
290
|
+
ui.warn "Git: The root of your chef repo doesn't look like it's a git repo. Skipping git pull...\n\n"
|
215
291
|
rescue
|
216
|
-
|
217
|
-
|
292
|
+
ui.warn "Git: Something went wrong with git pull, Dumping log info..."
|
293
|
+
ui.warn "#{strio.string}"
|
218
294
|
end
|
219
295
|
end
|
220
296
|
end
|
@@ -226,3 +302,14 @@ module KnifeSpork
|
|
226
302
|
!!(self =~ /^[-+]?[0-9]+$/)
|
227
303
|
end
|
228
304
|
end
|
305
|
+
|
306
|
+
class Hash
|
307
|
+
def diff(other)
|
308
|
+
self.keys.inject({}) do |memo, key|
|
309
|
+
unless self[key] == other[key]
|
310
|
+
memo[key] = "#{self[key]} changed to #{other[key]}"
|
311
|
+
end
|
312
|
+
memo
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
@@ -25,7 +25,9 @@
|
|
25
25
|
# limitations under the License.
|
26
26
|
#
|
27
27
|
|
28
|
+
require 'app_conf'
|
28
29
|
require 'chef/knife'
|
30
|
+
require 'socket'
|
29
31
|
|
30
32
|
module KnifeSpork
|
31
33
|
class SporkUpload < Chef::Knife
|
@@ -64,6 +66,29 @@ module KnifeSpork
|
|
64
66
|
:description => "Also upload cookbook dependencies"
|
65
67
|
|
66
68
|
def run
|
69
|
+
|
70
|
+
if RUBY_VERSION.to_f < 1.9
|
71
|
+
ui.fatal "Sorry, knife-spork requires ruby 1.9 or newer."
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
|
75
|
+
self.config = Chef::Config.merge!(config)
|
76
|
+
|
77
|
+
if File.exists?("#{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml")
|
78
|
+
AppConf.load("#{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml")
|
79
|
+
ui.msg "Loaded config file #{config[:cookbook_path].first.gsub("cookbooks","")}config/spork-config.yml...\n\n"
|
80
|
+
end
|
81
|
+
|
82
|
+
if File.exists?("/etc/spork-config.yml")
|
83
|
+
AppConf.load("/etc/spork-config.yml")
|
84
|
+
ui.msg "Loaded config file /etc/spork-config.yml...\n\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
if File.exists?(File.expand_path("~/.chef/spork-config.yml"))
|
88
|
+
AppConf.load(File.expand_path("~/.chef/spork-config.yml"))
|
89
|
+
ui.msg "Loaded config file #{File.expand_path("~/.chef/spork-config.yml")}...\n\n"
|
90
|
+
end
|
91
|
+
|
67
92
|
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
68
93
|
|
69
94
|
assert_environment_valid!
|
@@ -88,10 +113,19 @@ module KnifeSpork
|
|
88
113
|
end
|
89
114
|
end
|
90
115
|
ui.info("Uploading and freezing #{cookbook.name.to_s.ljust(justify_width + 10)} [#{cookbook.version}]")
|
116
|
+
|
91
117
|
upload(cookbook, justify_width)
|
92
118
|
cookbook.freeze_version
|
93
119
|
upload(cookbook, justify_width)
|
94
120
|
version_constraints_to_update[cookbook_name] = cookbook.version
|
121
|
+
|
122
|
+
if !AppConf.irccat.nil? && AppConf.irccat.enabled
|
123
|
+
message = "#{AppConf.irccat.channel} CHEF: #{ENV['USER']} uploaded and froze cookbook #{cookbook_name} version #{cookbook.version}"
|
124
|
+
s = TCPSocket.open(AppConf.irccat.server,AppConf.irccat.port)
|
125
|
+
s.write(message)
|
126
|
+
s.close
|
127
|
+
end
|
128
|
+
|
95
129
|
rescue Chef::Exceptions::CookbookNotFoundInRepo => e
|
96
130
|
ui.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
|
97
131
|
Chef::Log.debug(e)
|
data/lib/knife-spork.rb
CHANGED
metadata
CHANGED
@@ -1,45 +1,76 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-spork
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Jon Cowie
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2012-02-03 00:00:00 +00:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: chef
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 10
|
31
|
+
- 4
|
21
32
|
version: 0.10.4
|
22
33
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: git
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 2
|
46
|
+
- 5
|
32
47
|
version: 1.2.5
|
33
48
|
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: app_conf
|
34
52
|
prerelease: false
|
35
|
-
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 3
|
61
|
+
- 0
|
62
|
+
version: 0.3.0
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
36
65
|
description: A workflow plugin to help many devs work with the same chef repo/server
|
37
66
|
email: jonlives@gmail.com
|
38
67
|
executables: []
|
68
|
+
|
39
69
|
extensions: []
|
40
|
-
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
41
72
|
- README.md
|
42
|
-
files:
|
73
|
+
files:
|
43
74
|
- README.md
|
44
75
|
- Rakefile
|
45
76
|
- knife-spork.gemspec
|
@@ -48,29 +79,37 @@ files:
|
|
48
79
|
- lib/chef/knife/spork-promote.rb
|
49
80
|
- lib/chef/knife/spork-upload.rb
|
50
81
|
- lib/knife-spork.rb
|
82
|
+
has_rdoc: true
|
51
83
|
homepage: https://github.com/jonlives/knife-spork
|
52
84
|
licenses: []
|
85
|
+
|
53
86
|
post_install_message:
|
54
|
-
rdoc_options:
|
87
|
+
rdoc_options:
|
55
88
|
- --charset=UTF-8
|
56
|
-
require_paths:
|
89
|
+
require_paths:
|
57
90
|
- lib
|
58
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
92
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
100
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
70
107
|
requirements: []
|
108
|
+
|
71
109
|
rubyforge_project: knife-spork
|
72
|
-
rubygems_version: 1.
|
110
|
+
rubygems_version: 1.3.7
|
73
111
|
signing_key:
|
74
112
|
specification_version: 2
|
75
113
|
summary: A workflow plugin to help many devs work with the same chef repo/server
|
76
114
|
test_files: []
|
115
|
+
|