yyuu-capistrano-chef-solo 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -93,7 +93,19 @@ You can use cookbooks in remote repository.
93
93
 
94
94
  ```ruby
95
95
  set(:chef_solo_cookbooks_scm, :git)
96
- set(:chef_solo_cookbooks_repository, "git://example.com/example.git")
96
+ set(:chef_solo_cookbooks_repository, "git://github.com/opscode/cookbooks.git")
97
+ set(:chef_solo_cookbooks_revision, "master")
98
+ set(:chef_solo_cookbooks_subdir, "/")
99
+ ```
100
+
101
+ #### Using single cookbook in remote repository
102
+
103
+ Also you can use single cookbook in remote repository.
104
+
105
+ ```ruby
106
+ set(:chef_solo_cookbook_name, "python")
107
+ set(:chef_solo_cookbooks_scm, :git)
108
+ set(:chef_solo_cookbooks_repository, "git://github.com/opscode-cookbooks/python.git")
97
109
  set(:chef_solo_cookbooks_revision, "master")
98
110
  set(:chef_solo_cookbooks_subdir, "/")
99
111
  ```
@@ -105,17 +117,22 @@ You can use multiple cookbooks repositories at once.
105
117
  ```ruby
106
118
  set(:chef_solo_cookbooks) {{
107
119
  # use cookbooks in ./config/cookbooks.
108
- "local" => {
120
+ application => {
109
121
  :scm => :none,
110
122
  :deploy_subdir => "config/cookbooks",
111
123
  },
112
124
  # use cookbooks in git repository.
113
- "repository" => {
125
+ "cookbooks" => {
126
+ :scm => :git,
127
+ :repository => "git://github.com/opscode/cookbooks.git",
128
+ :revision => "master",
129
+ },
130
+ "python" => {
131
+ :cookbook_name => "python",
114
132
  :scm => :git,
115
- :repository => "git://example.com/example.git",
133
+ :repository => "git://github.com/opscode-cookbooks/python.git",
116
134
  :revision => "master",
117
- :deploy_subdir => "/",
118
- }
135
+ },
119
136
  }}
120
137
  ```
121
138
 
@@ -34,9 +34,11 @@ module Capistrano
34
34
  namespace(:chef_solo) {
35
35
  _cset(:chef_solo_version, "11.4.0")
36
36
  _cset(:chef_solo_path) { capture("echo $HOME/chef").strip }
37
- _cset(:chef_solo_path_children, %w(bundle cache config cookbooks))
38
- _cset(:chef_solo_config_file) { File.join(chef_solo_path, "config", "solo.rb") }
39
- _cset(:chef_solo_attributes_file) { File.join(chef_solo_path, "config", "solo.json") }
37
+ _cset(:chef_solo_cache_path) { File.join(chef_solo_path, "cache") }
38
+ _cset(:chef_solo_config_path) { File.join(chef_solo_path, "config") }
39
+ _cset(:chef_solo_cookbooks_path) { File.join(chef_solo_path, "cookbooks") }
40
+ _cset(:chef_solo_config_file) { File.join(chef_solo_config_path, "solo.rb") }
41
+ _cset(:chef_solo_attributes_file) { File.join(chef_solo_config_path, "solo.json") }
40
42
 
41
43
  _cset(:chef_solo_bootstrap_user) {
42
44
  if variables.key?(:chef_solo_user)
@@ -109,6 +111,9 @@ module Capistrano
109
111
  begin
110
112
  activated = _activate_settings(servers)
111
113
  yield
114
+ rescue => error
115
+ logger.info("could not connect with bootstrap settings: #{error}")
116
+ raise
112
117
  ensure
113
118
  _deactivate_settings(servers) if activated
114
119
  end
@@ -200,7 +205,7 @@ module Capistrano
200
205
  installed = false
201
206
  end
202
207
  unless installed
203
- dirs = chef_solo_path_children.map { |dir| File.join(chef_solo_path, dir) }
208
+ dirs = [ chef_solo_path, chef_solo_cache_path, chef_solo_config_path, chef_solo_cookbooks_path ].uniq
204
209
  run("mkdir -p #{dirs.map { |x| x.dump }.join(" ")}")
205
210
  top.put(chef_solo_gemfile, File.join(chef_solo_path, "Gemfile"))
206
211
  args = fetch(:chef_solo_bundle_options, [])
@@ -212,8 +217,8 @@ module Capistrano
212
217
 
213
218
  def update(options={})
214
219
  update_cookbooks(options)
215
- update_config(options)
216
220
  update_attributes(options)
221
+ update_config(options)
217
222
  end
218
223
 
219
224
  def update_cookbooks(options={})
@@ -222,7 +227,7 @@ module Capistrano
222
227
  tmpdir = capture("mktemp -d /tmp/cookbooks.XXXXXXXXXX", options).strip
223
228
  run("rm -rf #{tmpdir.dump} && mkdir -p #{tmpdir.dump}", options)
224
229
  deploy_cookbooks(name, tmpdir, variables, options)
225
- install_cookbooks(name, tmpdir, File.join(chef_solo_path, "cookbooks"), options)
230
+ install_cookbooks(name, tmpdir, chef_solo_cookbooks_path, options)
226
231
  ensure
227
232
  run("rm -rf #{tmpdir.dump}", options)
228
233
  end
@@ -233,7 +238,6 @@ module Capistrano
233
238
  # The definition of cookbooks.
234
239
  # By default, load cookbooks from local path of "config/cookbooks".
235
240
  #
236
- _cset(:chef_solo_cookbooks_name) { application }
237
241
  _cset(:chef_solo_cookbooks_exclude, %w(.hg .git .svn))
238
242
  _cset(:chef_solo_cookbooks_default_variables) {{
239
243
  :scm => :none,
@@ -249,7 +253,15 @@ module Capistrano
249
253
  variables[:deploy_subdir] = fetch(:chef_solo_cookbooks_subdir, "config/cookbooks")
250
254
  variables[:repository] = fetch(:chef_solo_cookbooks_repository) if exists?("chef_solo_cookbooks_repository")
251
255
  variables[:revision] = fetch(:chef_solo_cookbooks_revision) if exists?(:chef_solo_cookbooks_revision)
252
- { chef_solo_cookbooks_name => variables }
256
+ if exists?(:chef_solo_cookbook_name)
257
+ # deploy as single cookbook
258
+ name = fetch(:chef_solo_cookbook_name)
259
+ { name => variables.merge(:cookbook_name => name) }
260
+ else
261
+ # deploy as multiple cookbooks
262
+ name = fetch(:chef_solo_cookbooks_name, application)
263
+ { name => variables }
264
+ end
253
265
  }
254
266
 
255
267
  _cset(:chef_solo_repository_cache) { File.expand_path("tmp/cookbooks-cache") }
@@ -287,7 +299,14 @@ module Capistrano
287
299
  end
288
300
  strategy.deploy!
289
301
  end
290
- run("rsync -lrpt #{(release_path + "/").dump} #{destination.dump}", options)
302
+ if variables.key?(:cookbook_name)
303
+ # deploy as single cookbook
304
+ final_destination = File.join(destination, variables[:cookbook_name])
305
+ else
306
+ # deploy as multiple cookbooks
307
+ final_destination = destination
308
+ end
309
+ run("rsync -lrpt #{(release_path + "/").dump} #{final_destination.dump}", options)
291
310
  ensure
292
311
  run("rm -rf #{releases_path.dump}", options)
293
312
  end
@@ -310,12 +329,12 @@ module Capistrano
310
329
 
311
330
  _cset(:chef_solo_config) {
312
331
  (<<-EOS).gsub(/^\s*/, "")
313
- file_cache_path #{File.join(chef_solo_path, "cache").dump}
314
- cookbook_path #{File.join(chef_solo_path, "cookbooks").dump}
332
+ file_cache_path #{chef_solo_cache_path.dump}
333
+ cookbook_path #{chef_solo_cookbooks_path.dump}
315
334
  EOS
316
335
  }
317
336
  def update_config(options={})
318
- top.put(chef_solo_config, chef_solo_config_file)
337
+ top.put(chef_solo_config, chef_solo_config_file, options)
319
338
  end
320
339
 
321
340
  # merge nested hashes
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module ChefSolo
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ maintainer "Yamashita, Yuu"
2
+ maintainer_email "yamashita@geishatokyo.com"
3
+ description "single"
4
+ long_description "single"
5
+ version "0.0.1"
@@ -0,0 +1,7 @@
1
+ file "/tmp/single" do
2
+ owner "root"
3
+ group "root"
4
+ mode "0644"
5
+ end
6
+
7
+ # vim:set ft=ruby sw=2 ts=2 :
@@ -8,7 +8,11 @@ set :scm, :none
8
8
  set :use_sudo, false
9
9
  set :user, "vagrant"
10
10
  set :password, "vagrant"
11
- set :ssh_options, {:user_known_hosts_file => "/dev/null"}
11
+ set :ssh_options, {
12
+ :auth_methods => %w(publickey password),
13
+ :keys => File.join(ENV["HOME"], ".vagrant.d", "insecure_private_key"),
14
+ :user_known_hosts_file => "/dev/null",
15
+ }
12
16
 
13
17
  role :web, "192.168.33.10"
14
18
  role :app, "192.168.33.10"
@@ -198,7 +202,13 @@ namespace(:test_with_multiple_cookbooks) {
198
202
  :repository => File.expand_path("..", File.dirname(__FILE__)),
199
203
  :cookbooks => "config/cookbooks",
200
204
  },
201
- chef_solo_cookbooks_name => {
205
+ "single" => {
206
+ :cookbook_name => "single",
207
+ :scm => :none,
208
+ :repository => File.expand_path("..", File.dirname(__FILE__)),
209
+ :cookbooks => "config/cookbook",
210
+ },
211
+ application => {
202
212
  :scm => :git,
203
213
  :repository => "git://github.com/yyuu/capistrano-chef-solo.git",
204
214
  :revision => "develop",
@@ -218,7 +228,7 @@ namespace(:test_with_multiple_cookbooks) {
218
228
  }
219
229
 
220
230
  task(:test_run_list) {
221
- expected = %w(recipe[foo] recipe[one])
231
+ expected = %w(recipe[foo] recipe[single] recipe[one])
222
232
  chef_solo.run_list expected
223
233
  assert_run_list(expected)
224
234
  check_applied_recipes!(expected)
@@ -238,14 +248,19 @@ namespace(:test_with_bootstrap) {
238
248
  set(:chef_solo_bootstrap, true)
239
249
  set(:chef_solo_bootstrap_user, "bootstrap")
240
250
  set(:chef_solo_bootstrap_password, "bootstrap")
251
+ set(:chef_solo_bootstrap_ssh_options, {
252
+ # :auth_methods => %w(password), #==> setting :auth_methods throws Net::SSH::AuthenticationFailed (capistrano bug?)
253
+ :user_known_hosts_file => "/dev/null",
254
+ })
241
255
  run("getent passwd #{chef_solo_bootstrap_user.dump} || " +
242
256
  "#{sudo} useradd -m -p #{chef_solo_bootstrap_password.crypt(chef_solo_bootstrap_password).dump} #{chef_solo_bootstrap_user.dump}")
243
257
  }
244
258
 
245
259
  task(:teardown) {
246
260
  set(:chef_solo_bootstrap, false)
247
- set(:chef_solo_bootstrap_user, nil)
248
- set(:chef_solo_bootstrap_password, nil)
261
+ unset(:chef_solo_bootstrap_user)
262
+ unset(:chef_solo_bootstrap_password)
263
+ unset(:chef_solo_bootstrap_ssh_options)
249
264
  }
250
265
 
251
266
  task(:test_connect_with_settings) {
@@ -280,12 +295,14 @@ namespace(:test_without_bootstrap) {
280
295
  set(:chef_solo_bootstrap, false)
281
296
  set(:chef_solo_bootstrap_user, "bootstrap")
282
297
  set(:chef_solo_bootstrap_password, "bootstrap")
298
+ set(:chef_solo_bootstrap_ssh_options, {:user_known_hosts_file => "/dev/null"})
283
299
  }
284
300
 
285
301
  task(:teardown) {
286
302
  set(:chef_solo_bootstrap, false)
287
- set(:chef_solo_bootstrap_user, nil)
288
- set(:chef_solo_bootstrap_password, nil)
303
+ unset(:chef_solo_bootstrap_user)
304
+ unset(:chef_solo_bootstrap_password)
305
+ unset(:chef_solo_bootstrap_ssh_options)
289
306
  }
290
307
 
291
308
  task(:test_connect_with_settings) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yyuu-capistrano-chef-solo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-02 00:00:00.000000000 Z
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -127,6 +127,8 @@ files:
127
127
  - test/centos6-64/Gemfile
128
128
  - test/centos6-64/Vagrantfile
129
129
  - test/centos6-64/run.sh
130
+ - test/config/cookbook/metadata.rb
131
+ - test/config/cookbook/recipes/default.rb
130
132
  - test/config/cookbooks-ext/one/metadata.rb
131
133
  - test/config/cookbooks-ext/one/recipes/default.rb
132
134
  - test/config/cookbooks-ext/three/metadata.rb
@@ -175,6 +177,8 @@ test_files:
175
177
  - test/centos6-64/Gemfile
176
178
  - test/centos6-64/Vagrantfile
177
179
  - test/centos6-64/run.sh
180
+ - test/config/cookbook/metadata.rb
181
+ - test/config/cookbook/recipes/default.rb
178
182
  - test/config/cookbooks-ext/one/metadata.rb
179
183
  - test/config/cookbooks-ext/one/recipes/default.rb
180
184
  - test/config/cookbooks-ext/three/metadata.rb