baptize 0.0.4 → 0.0.5

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDJjNzBjYWM3MDg4MTQ3ODNjOTE1NGJhNTg5ZDE1ZWIxMDkzYTBiYw==
4
+ MzU2MjAxMzk0MmY0MjFmNmU2NTkxYTI0ZTA4NGJmOGYwNjAyYzE3Nw==
5
5
  data.tar.gz: !binary |-
6
- MzQ5MzNmM2I1OTcwZTQ3N2RiMGZiMWYwYjUxNDdjNGQ3ZTU4MGQyZA==
6
+ OWY5ZjY4NDAyNWEzMGIwMmU1ZThjYTMxMzIwZGFhMGRlNTRlZDVmMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTIwNWE0ZGI5MWZkODJhNWEzNTAyMmMwMzFlNmI0Mzc0NjgzNmU5Y2ZjYzZj
10
- MWZjZDI5MDBiZjkzMjhhZTI5OTVmZjliYjRhMzVmOWQ2M2UwZGExN2IyYzA5
11
- OGI3MDJlMGZkZDFiOGRmYzA4YTEyZGY0MjY1Mzc4YTcwOWQ1NmY=
9
+ MGE5ZDk0NzU0ZGQxYThmY2NhZGVmNmNmMmJiMmM3M2ViNDNiMzI1MjA0ZDZj
10
+ N2E3MTRhYTdjYzc1N2U5MTQ3YjZhMmEwNzk4ZDhlMTg4NDQ3NzEzYzE5NTY0
11
+ YzQ4ZWQ1ODUzMmExZTY2ZDM1Y2QwOWFkOGM3N2VmNGNhMDY5MmI=
12
12
  data.tar.gz: !binary |-
13
- ZDZlNTA2NjIwZmZlZjYyM2FhNWRhNGQ5ODdlMDViYzZkNmVjOTYwZDQzMDI3
14
- MzRkMGViOGU1NTQzYWUyMzM5ZjhhMjRjMTVmNGQxOWM5Yjk5MTJkZTE2ODk0
15
- ZGRmODgxY2E1YjQxNjZlMzJjOTk4NmQ4MWJkMThkZDAxMWRiYTY=
13
+ NTA2MDA5ODliMWM4OTNjOTRhNjJjZTg0OTFkMmU0YjY1ODQ5ZDIwZTIxYzM4
14
+ OWU5N2I3YTYwOGRlM2FjMjlkNDU3ODk4ZTg5MjBlMDBjNzY4NmE2MjUzZDEw
15
+ M2RhMzQ4MDYxNGYwOWE3YmQ0MGUwYTg0YzRkYTYwMGU5NTc1ZDQ=
@@ -25,6 +25,23 @@ module Capistrano
25
25
  results.all?
26
26
  end
27
27
 
28
+ # Runs a rake command remotely
29
+ def remote_rake(rake_command, options = {})
30
+ options = {:bundle_cmd => fetch(:bundle_cmd, "bundle"), :current_path => current_path, :rails_env => rails_env, :env => {}}.merge(options)
31
+ command = ""
32
+ command << "cd #{options[:current_path]} && " if options[:current_path]
33
+ command << "RAILS_ENV=#{options[:rails_env]} " if options[:rails_env]
34
+ options[:env].each do |k,v|
35
+ command << "#{k}=#{v.shellescape} "
36
+ end
37
+ if options[:bundle_cmd]
38
+ command << "#{options[:bundle_cmd]} exec rake #{rake_command}"
39
+ else
40
+ command << "rake #{rake_command}"
41
+ end
42
+ options[:norun] ? command : run(command)
43
+ end
44
+
28
45
  # logs the command then executes it locally.
29
46
  # returns the command output as a string
30
47
  def run_locally(cmd)
@@ -61,6 +78,11 @@ module Capistrano
61
78
  load(conf)
62
79
  end
63
80
  end
81
+ if fetch(:use_sudo, true)
82
+ default_run_options[:shell] = 'sudo bash'
83
+ else
84
+ default_run_options[:shell].gsub!(/^sudo /, "")
85
+ end
64
86
  end
65
87
  end
66
88
 
@@ -79,7 +101,7 @@ module Capistrano
79
101
  def render(path, locals = {})
80
102
  require 'erb'
81
103
  require 'ostruct'
82
- ERB.new(File.read(path)).result(OpenStruct.new(locals).instance_eval { binding })
104
+ ERB.new(File.read(path)).result(locals.kind_of?(Binding) ? locals : OpenStruct.new(locals).instance_eval { binding })
83
105
  end
84
106
 
85
107
  end
@@ -14,19 +14,17 @@ module Capistrano
14
14
 
15
15
  desc "Loads baptize configuration files"
16
16
  task :load_configuration do
17
- top.instance_eval do
18
- top.load_configuration :baptize
19
- default_run_options[:shell] = 'sudo bash' if fetch(:use_sudo, true)
20
- end
17
+ top.load_configuration :baptize
21
18
  end
22
19
 
23
20
  task :default do
24
- load_configuration
25
21
  install
26
22
  end
27
23
 
28
24
  desc "Configures all available policies"
29
- task :install do ; end
25
+ task :install do
26
+ load_configuration
27
+ end
30
28
 
31
29
  namespace :policies do
32
30
  desc "List available policies"
@@ -49,11 +47,41 @@ module Capistrano
49
47
  end
50
48
  end
51
49
  end
52
- end
50
+ end # end namespace policies
53
51
 
54
- end
52
+ namespace :ssh do
53
+ desc "Describe available ssh connections"
54
+ task :default do
55
+ load_configuration
56
+ count = 1
57
+ roles.each do |name,servers|
58
+ servers.each do |host|
59
+ puts "cap baptize:ssh:#{count} (#{name}) #{host}"
60
+ count = count + 1
61
+ end
62
+ end
63
+ end
64
+
65
+ 1.upto(10).each do |num|
66
+ task num.to_s.to_sym do
67
+ load_configuration
68
+ count = 1
69
+ roles.each do |name,servers|
70
+ servers.each do |host|
71
+ if count == num
72
+ command = "ssh -i #{ssh_options[:keys]} #{user}@#{host}"
73
+ puts "ssh -i #{ssh_options[:keys]} #{user}@#{host}"
74
+ exec command
75
+ end
76
+ count = count + 1
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end # end namespace ssh
82
+ end # end namespace baptize
55
83
  end
56
- end
57
84
 
85
+ end
58
86
  end
59
87
  end
@@ -2,20 +2,23 @@ module Capistrano
2
2
  module Baptize
3
3
  module Plugins
4
4
  module Base
5
+ def fail_verification(message = "Assertion failed")
6
+ raise VerificationFailure, message
7
+ end
5
8
 
6
9
  def has_file(path)
7
- raise VerificationFailure, "Remote file #{path} does not exist" unless remote_assert("test -e #{path.shellescape}")
10
+ remote_assert("test -e #{path.shellescape}") or fail_verification("Remote file #{path} does not exist")
8
11
  end
9
12
 
10
13
  def has_directory(path)
11
- raise VerificationFailure, "Remote directory #{path} does not exist" unless remote_assert("test -d #{path.shellescape}")
14
+ remote_assert("test -d #{path.shellescape}") or fail_verification("Remote directory #{path} does not exist")
12
15
  end
13
16
 
14
17
  def matches_local(local_path, remote_path)
15
18
  raise VerificationFailure, "Couldn't find local file #{local_path}" unless ::File.exists?(local_path)
16
19
  require 'digest/md5'
17
20
  local_md5 = Digest::MD5.hexdigest(::File.read(local_path))
18
- raise VerificationFailure, "Remote file #{remote_path} doesn't match local file #{local_path}" unless md5_of_file(remote_path, local_md5)
21
+ md5_of_file(remote_path, local_md5) or fail_verification("Remote file #{remote_path} doesn't match local file #{local_path}")
19
22
  end
20
23
 
21
24
  def file_contains(path, text, options = {})
@@ -31,11 +34,11 @@ module Capistrano
31
34
  end
32
35
 
33
36
  def has_executable(path)
34
- raise VerificationFailure, "No executable #{path} found" unless remote_assert "which #{path.shellescape}"
37
+ remote_assert("which #{path.shellescape}") or fail_verification("No executable #{path} found")
35
38
  end
36
39
 
37
40
  def has_user(name)
38
- raise VerificationFailure, "No user #{name}" unless remote_assert "id -u #{name.to_s.shellescape}"
41
+ remote_assert("id -u #{name.to_s.shellescape}") or fail_verification("No user #{name}")
39
42
  end
40
43
  end
41
44
  end
@@ -19,7 +19,7 @@ module Capistrano
19
19
  if use_tarball
20
20
  raise "Can't tarball streaming upload" if from.kind_of?(IO)
21
21
  exclude = use_tarball[:exclude] if (use_tarball.kind_of?(Hash) && use_tarball[:exclude])
22
- tar_options = exclude.map {|glob| "--exclude \"#{glob}\" " }.join('')
22
+ tar_options = Array(exclude).flatten.map {|glob| "--exclude \"#{glob}\" " }.join('')
23
23
  tempfile = Dir::Tmpname.make_tmpname(['/tmp/baptize-', '.tar.gz'], nil)
24
24
  local_command = "cd #{from.shellescape} ; #{local_tar_bin} -zcf #{tempfile.shellescape} #{tar_options}."
25
25
  raise "Unable to tar #{from}" unless run_locally(local_command)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baptize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Troels Knak-Nielsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-08 00:00:00.000000000 Z
11
+ date: 2013-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano