whiskey_disk 0.6.22 → 0.6.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +25 -15
  2. data/README.integration_specs +24 -36
  3. data/README.markdown +112 -96
  4. data/Rakefile +79 -5
  5. data/VERSION +1 -1
  6. data/lib/whiskey_disk.rb +297 -294
  7. data/lib/whiskey_disk/config.rb +99 -168
  8. data/lib/whiskey_disk/config/abstract_filter.rb +19 -0
  9. data/lib/whiskey_disk/config/filter.rb +48 -0
  10. data/lib/whiskey_disk/config/filters/add_environment_name_filter.rb +11 -0
  11. data/lib/whiskey_disk/config/filters/add_project_name_filter.rb +11 -0
  12. data/lib/whiskey_disk/config/filters/check_for_duplicate_domains_filter.rb +21 -0
  13. data/lib/whiskey_disk/config/filters/convert_role_strings_to_list_filter.rb +20 -0
  14. data/lib/whiskey_disk/config/filters/default_config_target_filter.rb +12 -0
  15. data/lib/whiskey_disk/config/filters/default_domain_filter.rb +12 -0
  16. data/lib/whiskey_disk/config/filters/drop_empty_domain_roles_filter.rb +32 -0
  17. data/lib/whiskey_disk/config/filters/environment_scope_filter.rb +20 -0
  18. data/lib/whiskey_disk/config/filters/hashify_domain_entries_filter.rb +29 -0
  19. data/lib/whiskey_disk/config/filters/localize_domains_filter.rb +24 -0
  20. data/lib/whiskey_disk/config/filters/modules/scope_helper.rb +11 -0
  21. data/lib/whiskey_disk/config/filters/normalize_ssh_options_filter.rb +29 -0
  22. data/lib/whiskey_disk/config/filters/project_scope_filter.rb +34 -0
  23. data/lib/whiskey_disk/config/filters/select_project_and_environment_filter.rb +12 -0
  24. data/lib/whiskey_disk/config/filters/stringify_hash_keys_filter.rb +25 -0
  25. data/lib/whiskey_disk/helpers.rb +1 -1
  26. data/lib/whiskey_disk/rake.rb +25 -22
  27. data/scenarios/git_repositories/config.git/HEAD +1 -0
  28. data/scenarios/git_repositories/config.git/config +5 -0
  29. data/scenarios/git_repositories/config.git/description +1 -0
  30. data/scenarios/git_repositories/config.git/git-daemon-export-ok +0 -0
  31. data/scenarios/git_repositories/config.git/hooks/applypatch-msg.sample +15 -0
  32. data/scenarios/git_repositories/config.git/hooks/commit-msg.sample +24 -0
  33. data/scenarios/git_repositories/config.git/hooks/post-commit.sample +8 -0
  34. data/scenarios/git_repositories/config.git/hooks/post-receive.sample +15 -0
  35. data/scenarios/git_repositories/config.git/hooks/post-update.sample +8 -0
  36. data/scenarios/git_repositories/config.git/hooks/pre-applypatch.sample +14 -0
  37. data/scenarios/git_repositories/config.git/hooks/pre-commit.sample +46 -0
  38. data/scenarios/git_repositories/config.git/hooks/pre-rebase.sample +169 -0
  39. data/scenarios/git_repositories/config.git/hooks/prepare-commit-msg.sample +36 -0
  40. data/scenarios/git_repositories/config.git/hooks/update.sample +128 -0
  41. data/scenarios/git_repositories/config.git/info/exclude +6 -0
  42. data/scenarios/git_repositories/config.git/objects/0d/b14dd6ddc54017c0a11960dcda82ed802cde69 +0 -0
  43. data/scenarios/git_repositories/config.git/objects/0e/e781f5ce80d64db32a74a7aae7b5248dafe112 +3 -0
  44. data/scenarios/git_repositories/config.git/objects/17/6bf54cf17d1d1c24556dc059c4144a5df230e8 +0 -0
  45. data/scenarios/git_repositories/config.git/objects/20/e9ff3feaa8ede30f707e5f1b4356e3c02bb7ec +0 -0
  46. data/scenarios/git_repositories/config.git/objects/45/117b1c775f0de415478dbf08ed9d667ab17d13 +0 -0
  47. data/scenarios/git_repositories/config.git/objects/51/3954c9aca090e6ce40359f0e9fde30ea78eb8c +0 -0
  48. data/scenarios/git_repositories/config.git/objects/66/947a7a11a6f5d3d561fe95de284ced3010819a +0 -0
  49. data/scenarios/git_repositories/config.git/objects/6b/bc79311bfac47d3ed724aa82a4814e0dda4c67 +0 -0
  50. data/scenarios/git_repositories/config.git/objects/71/eb5df52676e8e6efba471050b46978173af110 +1 -0
  51. data/scenarios/git_repositories/config.git/objects/84/17d2fe3e8fcc0825249c517b29b0f9ea8b8b31 +2 -0
  52. data/scenarios/git_repositories/config.git/objects/8b/384fcfcf7c0dee7c3c1d5636bee9e645d9cf38 +0 -0
  53. data/scenarios/git_repositories/config.git/objects/bb/59da633ba74296b0c2f9ff70784ac155ddb599 +0 -0
  54. data/scenarios/git_repositories/config.git/objects/cc/b86b26189afbf45d8eb9165812ab86dbdfca63 +0 -0
  55. data/scenarios/git_repositories/config.git/objects/d1/0bcd51fec41f854001e4d61f99d9e282a695d3 +0 -0
  56. data/scenarios/git_repositories/config.git/objects/d8/a8b0f5b1fd66844efb141d9544965ea0065f2d +0 -0
  57. data/scenarios/git_repositories/config.git/objects/e6/b02c66ad632e6b8535c4630cb8fe07732a72fc +0 -0
  58. data/scenarios/git_repositories/config.git/objects/e8/b8bfeeba735c0a1a873082554cb4d7256ac125 +0 -0
  59. data/scenarios/git_repositories/config.git/objects/f9/0181466a1a60b793ca9cc9abd584c18d4e3887 +0 -0
  60. data/scenarios/git_repositories/config.git/objects/f9/49d5d8a4f12c91471e34d4e277239c35ebd10d +0 -0
  61. data/scenarios/git_repositories/config.git/refs/heads/master +1 -0
  62. data/scenarios/git_repositories/project.git/HEAD +1 -0
  63. data/scenarios/git_repositories/project.git/config +5 -0
  64. data/scenarios/git_repositories/project.git/description +1 -0
  65. data/scenarios/git_repositories/project.git/git-daemon-export-ok +0 -0
  66. data/scenarios/git_repositories/project.git/hooks/applypatch-msg.sample +15 -0
  67. data/scenarios/git_repositories/project.git/hooks/commit-msg.sample +24 -0
  68. data/scenarios/git_repositories/project.git/hooks/post-commit.sample +8 -0
  69. data/scenarios/git_repositories/project.git/hooks/post-receive.sample +15 -0
  70. data/scenarios/git_repositories/project.git/hooks/post-update.sample +8 -0
  71. data/scenarios/git_repositories/project.git/hooks/pre-applypatch.sample +14 -0
  72. data/scenarios/git_repositories/project.git/hooks/pre-commit.sample +46 -0
  73. data/scenarios/git_repositories/project.git/hooks/pre-rebase.sample +169 -0
  74. data/scenarios/git_repositories/project.git/hooks/prepare-commit-msg.sample +36 -0
  75. data/scenarios/git_repositories/project.git/hooks/update.sample +128 -0
  76. data/scenarios/git_repositories/project.git/info/exclude +6 -0
  77. data/scenarios/git_repositories/project.git/objects/04/26e152e66c8cd42974279bdcae09be9839c172 +0 -0
  78. data/scenarios/git_repositories/project.git/objects/04/f4de85eaf72ef1631dc6d7424045c0a749b757 +1 -0
  79. data/scenarios/git_repositories/project.git/objects/06/13fe277280cbcdb2856e1eefc70bdaff011b20 +0 -0
  80. data/scenarios/git_repositories/project.git/objects/06/7aca89b86265eee211387434c3e50f37ccf009 +0 -0
  81. data/scenarios/git_repositories/project.git/objects/09/445dacc4822722612d60833c9948219ecdd8f5 +0 -0
  82. data/scenarios/git_repositories/project.git/objects/11/c4ec64326de35462f4e79d0f4229bf8e26e0c5 +0 -0
  83. data/scenarios/git_repositories/project.git/objects/20/1c7641c2e42b0b904e5c1f793489d8b858e4da +2 -0
  84. data/scenarios/git_repositories/project.git/objects/23/979639da60d2d31e9744468df1c1221b101e64 +0 -0
  85. data/scenarios/git_repositories/project.git/objects/27/a3fff2c4c45ab5513a405f694c0a042cb5d417 +1 -0
  86. data/scenarios/git_repositories/project.git/objects/2c/0c33cfba8e1af15df88522c0db2b10a6a94138 +2 -0
  87. data/scenarios/git_repositories/project.git/objects/38/b574660305ecb5fec6b2daa7ee1e0dbf1b6003 +0 -0
  88. data/scenarios/git_repositories/project.git/objects/4a/57abb5e4e426cfc9101b3af22ac83ccbd8e2ad +0 -0
  89. data/scenarios/git_repositories/project.git/objects/4c/77ebdd985e57afe7988480720c5dc77ec525c9 +0 -0
  90. data/scenarios/git_repositories/project.git/objects/51/c94da6f1b8aa9d2346088d3d362475b60c7f32 +0 -0
  91. data/scenarios/git_repositories/project.git/objects/5b/a96acf9cc9b87babe37c032676f53bf1ba9ae7 +2 -0
  92. data/scenarios/git_repositories/project.git/objects/5d/f555601d60f1c2a84d2364af0ad640612c3ba5 +0 -0
  93. data/scenarios/git_repositories/project.git/objects/71/03b5ac94940d596c2160a5cfcd55ca4ccac41f +0 -0
  94. data/scenarios/git_repositories/project.git/objects/73/3fc331098b03523f414f3509b9ae6e637c6866 +0 -0
  95. data/scenarios/git_repositories/project.git/objects/80/26076649ceccbe96a6292f2432652f08483035 +0 -0
  96. data/scenarios/git_repositories/project.git/objects/86/d1ef0976be4567de562224e1b51fbf9820c53a +1 -0
  97. data/scenarios/git_repositories/project.git/objects/87/a9d8b09b3401d21b23d90253332d6b28b47db2 +0 -0
  98. data/scenarios/git_repositories/project.git/objects/8b/030ba688255c917d189ae3f87d7c5ccd226bc2 +0 -0
  99. data/scenarios/git_repositories/project.git/objects/95/c9d5ad9b1c90e4c805516783105fc2037dedeb +2 -0
  100. data/scenarios/git_repositories/project.git/objects/95/d82d043af35a80eabfd56c0d705abfa3488787 +2 -0
  101. data/scenarios/git_repositories/project.git/objects/96/0bf34bb0b46d0aeb0be87f688f4ef06a4b35e1 +0 -0
  102. data/scenarios/git_repositories/project.git/objects/a3/860106dc1d148c7831cd45ae38829b4ed47702 +2 -0
  103. data/scenarios/git_repositories/project.git/objects/a8/506d6439b71784a72ac72d284b2ad53088f573 +0 -0
  104. data/scenarios/git_repositories/project.git/objects/ad/22ea6c7563777936ecfbe50d8e2cf8120fd525 +0 -0
  105. data/scenarios/git_repositories/project.git/objects/ae/3900de54aff557c61c81146d00f9d38e55a265 +1 -0
  106. data/scenarios/git_repositories/project.git/objects/bf/5e3740d52b80abb0378b3f85f93a53b1294521 +1 -0
  107. data/scenarios/git_repositories/project.git/objects/bf/b59811cdbc069418dee14b171e6e7e979784b7 +0 -0
  108. data/scenarios/git_repositories/project.git/objects/cc/5ac0afb24e727d5de344cc26a425f4fb7fd17d +3 -0
  109. data/scenarios/git_repositories/project.git/objects/d1/091aa2dd76885108461110c639e6b33a297fce +0 -0
  110. data/scenarios/git_repositories/project.git/objects/d8/913f6650eb2b7bf2a633732d8452008ca23dcb +0 -0
  111. data/scenarios/git_repositories/project.git/objects/db/d1b9667f1b26b13331ac0c321dced8be1aeab0 +3 -0
  112. data/scenarios/git_repositories/project.git/objects/e4/3b9107e9b1908ce415025e64eb83a493d329b7 +0 -0
  113. data/scenarios/git_repositories/project.git/objects/ef/2a88894d5421920b9dfe67a9a4d8043830e62e +0 -0
  114. data/scenarios/git_repositories/project.git/objects/f4/0123a1ff20c65d8dc15a38a83222647908e6f7 +0 -0
  115. data/scenarios/git_repositories/project.git/objects/f5/0af315b75ca0b12c720dec6d916b76b968c319 +0 -0
  116. data/scenarios/git_repositories/project.git/objects/f6/0215709b7b23f3738e9cbaf634b1c86bbd376a +0 -0
  117. data/scenarios/git_repositories/project.git/refs/heads/bad_rakefile +1 -0
  118. data/scenarios/git_repositories/project.git/refs/heads/hook_with_changed +1 -0
  119. data/scenarios/git_repositories/project.git/refs/heads/master +1 -0
  120. data/scenarios/git_repositories/project.git/refs/heads/no_rake_hooks +1 -0
  121. data/scenarios/git_repositories/project.git/refs/heads/post_rake_tasks +1 -0
  122. data/scenarios/invalid/deploy.yml +1 -0
  123. data/scenarios/local/deploy.yml.erb +17 -0
  124. data/scenarios/remote/deploy.yml +119 -0
  125. data/scenarios/setup/vagrant/.gitignore +3 -0
  126. data/scenarios/setup/vagrant/Vagrantfile +10 -0
  127. data/scenarios/setup/vagrant/manifests/integration.pp +32 -0
  128. data/scenarios/setup/vagrant/pids/.gitignore +1 -0
  129. data/spec/init_spec.rb +1 -1
  130. data/spec/install_spec.rb +4 -4
  131. data/spec/integration/branch_switching_spec.rb +41 -0
  132. data/spec/integration/deployment_failures_spec.rb +106 -0
  133. data/spec/integration/helper_spec.rb +90 -0
  134. data/spec/integration/invalid_configuration_spec.rb +39 -0
  135. data/spec/integration/local_deployments_spec.rb +230 -0
  136. data/spec/integration/post_rake_tasks_spec.rb +226 -0
  137. data/spec/integration/post_scripts_spec.rb +246 -0
  138. data/spec/integration/remote_deployments_spec.rb +166 -0
  139. data/spec/integration/staleness_checks_spec.rb +72 -0
  140. data/spec/spec_helper.rb +30 -2
  141. data/spec/wd_command_spec.rb +136 -136
  142. data/spec/wd_role_command_spec.rb +5 -5
  143. data/spec/whiskey_disk/config/filter_spec.rb +77 -0
  144. data/spec/whiskey_disk/config/filters/add_environment_name_filter_spec.rb +20 -0
  145. data/spec/whiskey_disk/config/filters/add_project_name_filter_spec.rb +19 -0
  146. data/spec/whiskey_disk/config/filters/check_for_duplicate_domains_filter_spec.rb +29 -0
  147. data/spec/whiskey_disk/config/filters/convert_role_strings_to_list_filter_spec.rb +48 -0
  148. data/spec/whiskey_disk/config/filters/default_config_target_filter_spec.rb +19 -0
  149. data/spec/whiskey_disk/config/filters/default_domain_filter_spec.rb +18 -0
  150. data/spec/whiskey_disk/config/filters/drop_empty_domain_roles_filter_spec.rb +60 -0
  151. data/spec/whiskey_disk/config/filters/environment_scope_filter_spec.rb +32 -0
  152. data/spec/whiskey_disk/config/filters/hashify_domain_entries_filter_spec.rb +41 -0
  153. data/spec/whiskey_disk/config/filters/localize_domains_filter_spec.rb +30 -0
  154. data/spec/whiskey_disk/config/filters/normalize_ssh_options_filter_spec.rb +56 -0
  155. data/spec/whiskey_disk/config/filters/project_scope_filter_spec.rb +75 -0
  156. data/spec/whiskey_disk/config/filters/select_project_and_environment_filter_spec.rb +30 -0
  157. data/spec/whiskey_disk/config/filters/stringify_hash_keys_filter_spec.rb +40 -0
  158. data/spec/whiskey_disk/config_spec.rb +259 -446
  159. data/spec/whiskey_disk/helpers_spec.rb +51 -51
  160. data/spec/whiskey_disk/rake_spec.rb +80 -80
  161. data/spec/whiskey_disk_spec.rb +591 -562
  162. data/whiskey_disk.gemspec +151 -20
  163. metadata +151 -18
data/Rakefile CHANGED
@@ -4,12 +4,85 @@ require 'rake/testtask'
4
4
  desc 'Default: run unit tests.'
5
5
  task :default => :test
6
6
 
7
- desc 'Test RubyCloud'
7
+ desc 'Test whiskey_disk'
8
8
  task :test do
9
9
  files = Dir['spec/**/*_spec.rb'].join(" ")
10
10
  system("bacon #{files}")
11
11
  end
12
12
 
13
+ namespace :integration do
14
+ def say(mesg)
15
+ STDERR.puts mesg
16
+ end
17
+
18
+ def vagrant_path
19
+ File.expand_path(File.join(File.dirname(__FILE__), 'scenarios', 'setup', 'vagrant'))
20
+ end
21
+
22
+ def root_path
23
+ File.expand_path(File.dirname(__FILE__))
24
+ end
25
+
26
+ def pidfile
27
+ File.join(vagrant_path, 'pids', 'git-daemon.pid')
28
+ end
29
+
30
+ def start_git_daemon
31
+ stop_git_daemon
32
+ say "Starting git daemon..."
33
+ run(root_path, "git daemon --base-path=#{root_path}/scenarios/git_repositories/ --reuseaddr --verbose --detach --pid-file=#{pidfile}")
34
+ end
35
+
36
+ def stop_git_daemon
37
+ return unless File.exists?(pidfile)
38
+ pid = File.read(pidfile).chomp
39
+ return if pid == ''
40
+ say "Stopping git daemon..."
41
+ run(root_path, "kill #{pid}")
42
+ end
43
+
44
+ def start_vm
45
+ say "Bringing up vagrant vm..."
46
+ run(vagrant_path, 'vagrant up')
47
+ copy_ssh_config
48
+ end
49
+
50
+ def stop_vm
51
+ say "Shutting down vagrant vm..."
52
+ run(vagrant_path, 'vagrant halt')
53
+ end
54
+
55
+ def copy_ssh_config
56
+ say "Capturing vagrant ssh_config data..."
57
+ run(vagrant_path, "vagrant ssh_config > #{vagrant_path}/ssh_config")
58
+ end
59
+
60
+ def run(path, cmd)
61
+ Dir.chdir(path)
62
+ say "running: #{cmd} [cwd: #{Dir.pwd}]"
63
+ system(cmd)
64
+ end
65
+
66
+ desc 'Start a vagrant VM and git-daemon server to support running integration specs'
67
+ task :up do
68
+ start_vm
69
+ start_git_daemon
70
+ end
71
+
72
+ desc 'Shut down integration vagrant VM and git-daemon server'
73
+ task :down do
74
+ stop_git_daemon
75
+ stop_vm
76
+ end
77
+
78
+ desc 'Completely remove the vagrant VM files used by the integration spec suite'
79
+ task :destroy do
80
+ stop_git_daemon
81
+ stop_vm
82
+ run(vagrant_path, 'vagrant destroy')
83
+ end
84
+ end
85
+
13
86
  begin
14
87
  require 'jeweler'
15
88
  Jeweler::Tasks.new do |gemspec|
@@ -20,12 +93,13 @@ begin
20
93
  gemspec.homepage = "http://github.com/flogic/whiskey_disk"
21
94
  gemspec.authors = ["Rick Bradley"]
22
95
  gemspec.add_dependency('rake')
23
-
96
+
24
97
  # I've decided that the integration spec shizzle shouldn't go into the gem
25
- gemspec.files.exclude 'scenarios', 'spec/integration'
26
- gemspec.test_files.exclude 'scenarios', 'spec/integration'
98
+ rejected = %w(scenarios spec/integration)
99
+ gemspec.files.reject {|f| rejected.include?(f) }
100
+ gemspec.test_files.reject {|f| rejected.include?(f) }
27
101
  end
28
- Jeweler::GemcutterTasks.new
102
+ Jeweler::GemcutterTasks.new
29
103
  rescue LoadError
30
104
  # if you get here, you need Jeweler installed to do packaging and gem installation, yo.
31
105
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.22
1
+ 0.6.23
data/lib/whiskey_disk.rb CHANGED
@@ -1,320 +1,323 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'whiskey_disk', 'config'))
2
2
 
3
3
  class WhiskeyDisk
4
- class << self
5
- attr_writer :configuration
6
- attr_reader :results
7
-
8
- def reset
9
- @configuration = nil
10
- @buffer = nil
11
- @staleness_checks = nil
12
- @results = nil
13
- end
14
-
15
- def buffer
16
- @buffer ||= []
17
- end
18
-
19
- def configuration
20
- @configuration ||= WhiskeyDisk::Config.fetch
21
- end
22
-
23
- def [](key)
24
- configuration[key.to_s]
25
- end
26
-
27
- def check_staleness?
28
- WhiskeyDisk::Config.check_staleness?
29
- end
30
-
31
- def enable_staleness_checks
32
- @staleness_checks = true
33
- end
34
-
35
- def staleness_checks_enabled?
36
- !!@staleness_checks
37
- end
4
+ attr_writer :configuration, :config
5
+ attr_reader :results
6
+
7
+ def initialize(options = {})
8
+ @staleness_checks = true if options[:staleness_checks]
9
+ end
10
+
11
+ def buffer
12
+ @buffer ||= []
13
+ end
14
+
15
+ def config
16
+ @config ||= WhiskeyDisk::Config.new
17
+ end
18
+
19
+ def configuration
20
+ @configuration ||= config.fetch
21
+ end
22
+
23
+ def debugging?
24
+ config.debug?
25
+ end
26
+
27
+ def setting(key)
28
+ configuration[key.to_s]
29
+ end
30
+
31
+ def check_staleness?
32
+ config.check_staleness?
33
+ end
34
+
35
+ def staleness_checks_enabled?
36
+ !!@staleness_checks
37
+ end
38
38
 
39
- def enqueue(command)
40
- buffer << command
41
- end
42
-
43
- def remote?(domain)
44
- return false unless domain
45
- return false if domain == 'local'
46
- limit = WhiskeyDisk::Config.domain_limit
47
- return false if limit and domain_limit_match?(domain, limit)
39
+ def enqueue(command)
40
+ buffer << command
41
+ end
42
+
43
+ def remote?(domain)
44
+ return false unless domain
45
+ return false if domain == 'local'
46
+ limit = config.domain_limit
47
+ return false if limit and domain_limit_match?(domain, limit)
48
48
 
49
- true
50
- end
51
-
52
- def has_config_repo?
53
- ! (self[:config_repository].nil? or self[:config_repository] == '')
54
- end
55
-
56
- def project_name_specified?
57
- self[:project] != 'unnamed_project'
58
- end
49
+ true
50
+ end
51
+
52
+ def has_config_repo?
53
+ ! (setting(:config_repository).nil? or setting(:config_repository) == '')
54
+ end
55
+
56
+ def project_name_specified?
57
+ setting(:project) != 'unnamed_project'
58
+ end
59
59
 
60
- def branch
61
- (self[:branch] and self[:branch] != '') ? self[:branch] : 'master'
62
- end
63
-
64
- def config_branch
65
- (self[:config_branch] and self[:config_branch] != '') ? self[:config_branch] : 'master'
60
+ def branch
61
+ (setting(:branch) and setting(:branch) != '') ? setting(:branch) : 'master'
62
+ end
63
+
64
+ def config_branch
65
+ (setting(:config_branch) and setting(:config_branch) != '') ? setting(:config_branch) : 'master'
66
+ end
67
+
68
+ def env_vars
69
+ return '' unless setting(:rake_env)
70
+ setting(:rake_env).keys.inject('') do |buffer,k|
71
+ buffer += "#{k}='#{setting(:rake_env)[k]}' "
72
+ buffer
66
73
  end
67
-
68
- def env_vars
69
- return '' unless self[:rake_env]
70
- self[:rake_env].keys.inject('') do |buffer,k|
71
- buffer += "#{k}='#{self[:rake_env][k]}' "
72
- buffer
73
- end
74
+ end
75
+
76
+ def parent_path(path)
77
+ File.split(path).first
78
+ end
79
+
80
+ def tail_path(path)
81
+ File.split(path).last
82
+ end
83
+
84
+ def needs(*keys)
85
+ keys.each do |key|
86
+ raise "No value for '#{key}' declared in configuration files [#{config.configuration_file}]" unless setting(key)
74
87
  end
88
+ end
89
+
90
+ def apply_staleness_check(commands)
91
+ needs(:deploy_to, :repository)
75
92
 
76
- def parent_path(path)
77
- File.split(path).first
78
- end
93
+ check = "cd #{setting(:deploy_to)}; " +
94
+ "ml=\`git log -1 --pretty=format:%H\`; " +
95
+ "mr=\`git ls-remote #{setting(:repository)} refs/heads/#{branch}\`; "
79
96
 
80
- def tail_path(path)
81
- File.split(path).last
97
+ if setting(:deploy_config_to)
98
+ check += "cd #{setting(:deploy_config_to)}; " +
99
+ "cl=\`git log -1 --pretty=format:%H\`; " +
100
+ "cr=\`git ls-remote #{setting(:config_repository)} refs/heads/#{config_branch}\`; "
82
101
  end
83
102
 
84
- def needs(*keys)
85
- keys.each do |key|
86
- raise "No value for '#{key}' declared in configuration files [#{WhiskeyDisk::Config.configuration_file}]" unless self[key]
87
- end
88
- end
103
+ check += "if [[ $ml != ${mr%%\t*} ]] " +
104
+ (setting(:deploy_config_to) ? "|| [[ $cl != ${cr%%\t*} ]]" : '') +
105
+ "; then #{commands}; else echo \"No changes to deploy.\"; fi"
106
+ end
107
+
108
+ def join_commands
109
+ buffer.collect {|c| "{ #{c} ; }"}.join(' && ')
110
+ end
111
+
112
+ def bundle
113
+ return '' if buffer.empty?
114
+ (staleness_checks_enabled? and check_staleness?) ? apply_staleness_check(join_commands) : join_commands
115
+ end
89
116
 
90
- def apply_staleness_check(commands)
91
- needs(:deploy_to, :repository)
92
-
93
- check = "cd #{self[:deploy_to]}; " +
94
- "ml=\`git log -1 --pretty=format:%H\`; " +
95
- "mr=\`git ls-remote #{self[:repository]} refs/heads/#{branch}\`; "
96
-
97
- if self[:deploy_config_to]
98
- check += "cd #{self[:deploy_config_to]}; " +
99
- "cl=\`git log -1 --pretty=format:%H\`; " +
100
- "cr=\`git ls-remote #{self[:config_repository]} refs/heads/#{config_branch}\`; "
101
- end
102
-
103
- check += "if [[ $ml != ${mr%%\t*} ]] " +
104
- (self[:deploy_config_to] ? "|| [[ $cl != ${cr%%\t*} ]]" : '') +
105
- "; then #{commands}; else echo \"No changes to deploy.\"; fi"
106
- end
107
-
108
- def join_commands
109
- buffer.collect {|c| "{ #{c} ; }"}.join(' && ')
110
- end
111
-
112
- def bundle
113
- return '' if buffer.empty?
114
- (staleness_checks_enabled? and check_staleness?) ? apply_staleness_check(join_commands) : join_commands
115
- end
117
+ def domain_limit_match?(domain, limit)
118
+ domain.sub(%r{^.*@}, '') == limit
119
+ end
120
+
121
+ def domain_of_interest?(domain)
122
+ return true unless limit = config.domain_limit
123
+ domain_limit_match?(domain, limit)
124
+ end
125
+
126
+ def encode_roles(roles)
127
+ return '' unless roles and !roles.empty?
128
+ "export WD_ROLES='#{roles.join(':')}'; "
129
+ end
116
130
 
117
- def domain_limit_match?(domain, limit)
118
- domain.sub(%r{^.*@}, '') == limit
119
- end
120
-
121
- def domain_of_interest?(domain)
122
- return true unless limit = WhiskeyDisk::Config.domain_limit
123
- domain_limit_match?(domain, limit)
124
- end
125
-
126
- def encode_roles(roles)
127
- return '' unless roles and !roles.empty?
128
- "export WD_ROLES='#{roles.join(':')}'; "
129
- end
131
+ def build_command(domain, cmd)
132
+ "#{'set -x; ' if debugging?}" + encode_roles(domain['roles']) + cmd
133
+ end
134
+
135
+ def run(domain, cmd)
136
+ ssh(domain, cmd)
137
+ end
130
138
 
131
- def build_command(domain, cmd)
132
- "#{'set -x; ' if Config.debug?}" + encode_roles(domain[:roles]) + cmd
133
- end
134
-
135
- def run(domain, cmd)
136
- ssh(domain, cmd)
137
- end
139
+ def ssh(domain, cmd)
140
+ args = []
141
+ args << domain['name']
142
+ args << '-v' if debugging?
143
+ args += domain['ssh_options'] if domain['ssh_options']
144
+ args << build_command(domain, cmd)
138
145
 
139
- def ssh(domain, cmd)
140
- puts "Running command on [#{domain}]: [#{cmd}]" if Config.debug?
141
- args = [domain[:name], build_command(domain, cmd)]
142
- args.unshift '-v' if Config.debug?
143
- system('ssh', *args)
144
- end
145
-
146
- def shell(domain, cmd)
147
- puts "Running command locally: [#{cmd}]" if Config.debug?
148
- system('bash', '-c', build_command(domain, cmd))
149
- end
150
-
151
- def flush
152
- needs(:domain)
153
- self[:domain].each do |domain|
154
- next unless domain_of_interest?(domain[:name])
155
- puts "Deploying #{domain[:name]}..."
156
- status = remote?(domain[:name]) ? run(domain, bundle) : shell(domain, bundle)
157
- record_result(domain[:name], status)
158
- end
159
- end
160
-
161
- def record_result(domain, status)
162
- @results ||= []
163
- @results << { :domain => domain, :status => status }
146
+ puts "Running: ssh #{args.join(' ')}" if debugging?
147
+ system('ssh', *args)
148
+ end
149
+
150
+ def shell(domain, cmd)
151
+ puts "Running command locally: [#{cmd}]" if debugging?
152
+ system('bash', '-c', build_command(domain, cmd))
153
+ end
154
+
155
+ def flush
156
+ needs(:domain)
157
+ setting(:domain).each do |domain|
158
+ next unless domain_of_interest?(domain['name'])
159
+ puts "Deploying #{domain['name']}..."
160
+ status = remote?(domain['name']) ? run(domain, bundle) : shell(domain, bundle)
161
+ record_result(domain['name'], status)
164
162
  end
163
+ end
164
+
165
+ def record_result(domain, status)
166
+ @results ||= []
167
+ @results << { 'domain' => domain, 'status' => status }
168
+ end
165
169
 
166
- def summarize_results(results)
167
- successes = failures = 0
168
- results.each do |result|
169
- puts "#{result[:domain]} => #{result[:status] ? 'succeeded' : 'failed'}."
170
- if result[:status]
171
- successes += 1
172
- else
173
- failures += 1
174
- end
175
- end
176
- [successes + failures, successes, failures]
177
- end
178
-
179
- def summarize
180
- puts "\nResults:"
181
- if results and not results.empty?
182
- total, successes, failures = summarize_results(results)
183
- puts "Total: #{total} deployment#{total == 1 ? '' : 's'}, " +
184
- "#{successes} success#{successes == 1 ? '' : 'es'}, " +
185
- "#{failures} failure#{failures == 1 ? '' : 's'}."
170
+ def summarize_results(results)
171
+ successes = failures = 0
172
+ results.each do |result|
173
+ puts "#{result['domain']} => #{result['status'] ? 'succeeded' : 'failed'}."
174
+ if result['status']
175
+ successes += 1
186
176
  else
187
- puts "No deployments to report."
188
- end
189
- end
190
-
191
- def success?
192
- return true if !results or results.empty?
193
- results.all? {|result| result[:status] }
194
- end
195
-
196
- def if_file_present(path, cmd)
197
- "if [ -e #{path} ]; then #{cmd}; fi"
198
- end
199
-
200
- def if_task_defined(task, cmd)
201
- %Q(rakep=`#{env_vars} rake -P` && if [[ `echo "${rakep}" | grep #{task}` != "" ]]; then #{cmd}; fi )
202
- end
203
-
204
- def safe_branch_checkout(path, my_branch)
205
- %Q(cd #{path} && git checkout -b #{my_branch} origin/#{my_branch} || git checkout #{my_branch} origin/#{my_branch} || git checkout #{my_branch})
206
- end
207
-
208
- def clone_repository(repo, path, my_branch)
209
- enqueue "cd #{parent_path(path)}"
210
- enqueue("if [ -e #{path} ]; then echo 'Repository already cloned to [#{path}]. Skipping.'; " +
211
- "else git clone #{repo} #{tail_path(path)} && #{safe_branch_checkout(path, my_branch)}; fi")
212
- end
213
-
214
- def refresh_checkout(path, repo_branch)
215
- enqueue "cd #{path}"
216
- enqueue "git fetch origin +refs/heads/#{repo_branch}:refs/remotes/origin/#{repo_branch} #{'&>/dev/null' unless Config.debug?}"
217
- enqueue "git checkout #{repo_branch} #{'&>/dev/null' unless Config.debug?}"
218
- enqueue "git reset --hard origin/#{repo_branch} #{'&>/dev/null' unless Config.debug?}"
177
+ failures += 1
178
+ end
219
179
  end
180
+ [successes + failures, successes, failures]
181
+ end
182
+
183
+ def summarize
184
+ puts "\nResults:"
185
+ if results and not results.empty?
186
+ total, successes, failures = summarize_results(results)
187
+ puts "Total: #{total} deployment#{total == 1 ? '' : 's'}, " +
188
+ "#{successes} success#{successes == 1 ? '' : 'es'}, " +
189
+ "#{failures} failure#{failures == 1 ? '' : 's'}."
190
+ else
191
+ puts "No deployments to report."
192
+ end
193
+ end
194
+
195
+ def success?
196
+ return true if !results or results.empty?
197
+ results.all? {|result| result['status'] }
198
+ end
199
+
200
+ def if_file_present(path, cmd)
201
+ "if [ -e #{path} ]; then #{cmd}; fi"
202
+ end
203
+
204
+ def if_task_defined(task, cmd)
205
+ %Q(rakep=`#{env_vars} rake -P` && if [[ `echo "${rakep}" | grep #{task}` != "" ]]; then #{cmd}; fi )
206
+ end
207
+
208
+ def safe_branch_checkout(path, my_branch)
209
+ %Q(cd #{path} && git checkout -b #{my_branch} origin/#{my_branch} || git checkout #{my_branch} origin/#{my_branch} || git checkout #{my_branch})
210
+ end
211
+
212
+ def clone_repository(repo, path, my_branch)
213
+ enqueue "cd #{parent_path(path)}"
214
+ enqueue("if [ -e #{path} ]; then echo 'Repository already cloned to [#{path}]. Skipping.'; " +
215
+ "else git clone #{repo} #{tail_path(path)} && #{safe_branch_checkout(path, my_branch)}; fi")
216
+ end
217
+
218
+ def refresh_checkout(path, repo_branch)
219
+ enqueue "cd #{path}"
220
+ enqueue "git fetch origin +refs/heads/#{repo_branch}:refs/remotes/origin/#{repo_branch} #{'&>/dev/null' unless debugging?}"
221
+ enqueue "git checkout #{repo_branch} #{'&>/dev/null' unless debugging?}"
222
+ enqueue "git reset --hard origin/#{repo_branch} #{'&>/dev/null' unless debugging?}"
223
+ end
220
224
 
221
- def run_rake_task(path, task_name)
222
- enqueue "echo Running rake #{task_name}..."
223
- enqueue "cd #{path}"
224
- enqueue(if_file_present("#{self[:deploy_to]}/Rakefile",
225
- if_task_defined(task_name, "#{env_vars} rake #{'--trace' if Config.debug?} #{task_name} to=#{self[:environment]}")))
226
- end
227
-
228
- def build_path(path)
229
- return path if path =~ %r{^/}
230
- File.join(self[:deploy_to], path)
231
- end
225
+ def run_rake_task(path, task_name)
226
+ enqueue "echo Running rake #{task_name}..."
227
+ enqueue "cd #{path}"
228
+ enqueue(if_file_present("#{setting(:deploy_to)}/Rakefile",
229
+ if_task_defined(task_name, "#{env_vars} rake #{'--trace' if debugging?} #{task_name} to=#{setting(:environment)}")))
230
+ end
231
+
232
+ def build_path(path)
233
+ return path if path =~ %r{^/}
234
+ File.join(setting(:deploy_to), path)
235
+ end
232
236
 
233
- def run_script(script)
234
- return unless script
235
- enqueue(%Q<cd #{self[:deploy_to]}; echo "Running post script..."; #{env_vars} bash #{'-x' if Config.debug?} #{build_path(script)}>)
236
- end
237
+ def run_script(script)
238
+ return unless script
239
+ enqueue(%Q<cd #{setting(:deploy_to)}; echo "Running post script..."; #{env_vars} bash #{'-x' if debugging?} #{build_path(script)}>)
240
+ end
237
241
 
238
- def ensure_main_parent_path_is_present
239
- needs(:deploy_to)
240
- enqueue "mkdir -p #{parent_path(self[:deploy_to])}"
241
- end
242
-
243
- def ensure_config_parent_path_is_present
244
- needs(:deploy_config_to)
245
- enqueue "mkdir -p #{parent_path(self[:deploy_config_to])}"
246
- end
242
+ def ensure_main_parent_path_is_present
243
+ needs(:deploy_to)
244
+ enqueue "mkdir -p #{parent_path(setting(:deploy_to))}"
245
+ end
246
+
247
+ def ensure_config_parent_path_is_present
248
+ needs(:deploy_config_to)
249
+ enqueue "mkdir -p #{parent_path(setting(:deploy_config_to))}"
250
+ end
247
251
 
248
- def checkout_main_repository
249
- needs(:deploy_to, :repository)
250
- clone_repository(self[:repository], self[:deploy_to], branch)
251
- end
252
-
253
- def checkout_configuration_repository
254
- needs(:deploy_config_to, :config_repository)
255
- clone_repository(self[:config_repository], self[:deploy_config_to], config_branch)
256
- end
257
-
258
- def snapshot_git_revision
259
- needs(:deploy_to)
260
- enqueue "cd #{self[:deploy_to]}"
261
- enqueue %Q{ml=\`git log -1 --pretty=format:%H\`}
262
- end
263
-
264
- def initialize_git_changes
265
- needs(:deploy_to)
266
- enqueue "rm -f #{self[:deploy_to]}/.whiskey_disk_git_changes"
267
- snapshot_git_revision
268
- end
269
-
270
- def initialize_rsync_changes
271
- needs(:deploy_to)
272
- enqueue "rm -f #{self[:deploy_to]}/.whiskey_disk_rsync_changes"
273
- end
274
-
275
- def initialize_all_changes
276
- needs(:deploy_to)
277
- initialize_git_changes
278
- initialize_rsync_changes
279
- end
280
-
281
- def capture_git_changes
282
- needs(:deploy_to)
283
- enqueue "git diff --name-only ${ml}..HEAD > #{self[:deploy_to]}/.whiskey_disk_git_changes"
284
- end
285
-
286
- def update_main_repository_checkout
287
- needs(:deploy_to)
288
- initialize_git_changes
289
- refresh_checkout(self[:deploy_to], branch)
290
- capture_git_changes
291
- end
292
-
293
- def update_configuration_repository_checkout
294
- needs(:deploy_config_to)
295
- initialize_rsync_changes
296
- refresh_checkout(self[:deploy_config_to], config_branch)
297
- end
298
-
299
- def refresh_configuration
300
- needs(:deploy_to, :deploy_config_to)
301
- raise "Must specify project name when using a configuration repository." unless project_name_specified?
302
- enqueue "echo Rsyncing configuration..."
303
- enqueue("rsync -a#{'v --progress' if Config.debug?} " + '--log-format="%t [%p] %i %n" ' +
304
- "#{self[:deploy_config_to]}/#{self[:project]}/#{self[:config_target]}/ #{self[:deploy_to]}/ " +
305
- "> #{self[:deploy_to]}/.whiskey_disk_rsync_changes")
306
- end
307
-
308
- def run_post_setup_hooks
309
- needs(:deploy_to)
310
- run_script(self[:post_setup_script])
311
- run_rake_task(self[:deploy_to], "deploy:post_setup")
312
- end
313
-
314
- def run_post_deploy_hooks
315
- needs(:deploy_to)
316
- run_script(self[:post_deploy_script])
317
- run_rake_task(self[:deploy_to], "deploy:post_deploy")
318
- end
252
+ def checkout_main_repository
253
+ needs(:deploy_to, :repository)
254
+ clone_repository(setting(:repository), setting(:deploy_to), branch)
255
+ end
256
+
257
+ def checkout_configuration_repository
258
+ needs(:deploy_config_to, :config_repository)
259
+ clone_repository(setting(:config_repository), setting(:deploy_config_to), config_branch)
260
+ end
261
+
262
+ def snapshot_git_revision
263
+ needs(:deploy_to)
264
+ enqueue "cd #{setting(:deploy_to)}"
265
+ enqueue %Q{ml=\`git log -1 --pretty=format:%H\`}
266
+ end
267
+
268
+ def initialize_git_changes
269
+ needs(:deploy_to)
270
+ enqueue "rm -f #{setting(:deploy_to)}/.whiskey_disk_git_changes"
271
+ snapshot_git_revision
272
+ end
273
+
274
+ def initialize_rsync_changes
275
+ needs(:deploy_to)
276
+ enqueue "rm -f #{setting(:deploy_to)}/.whiskey_disk_rsync_changes"
277
+ end
278
+
279
+ def initialize_all_changes
280
+ needs(:deploy_to)
281
+ initialize_git_changes
282
+ initialize_rsync_changes
283
+ end
284
+
285
+ def capture_git_changes
286
+ needs(:deploy_to)
287
+ enqueue "git diff --name-only ${ml}..HEAD > #{setting(:deploy_to)}/.whiskey_disk_git_changes"
288
+ end
289
+
290
+ def update_main_repository_checkout
291
+ needs(:deploy_to)
292
+ initialize_git_changes
293
+ refresh_checkout(setting(:deploy_to), branch)
294
+ capture_git_changes
295
+ end
296
+
297
+ def update_configuration_repository_checkout
298
+ needs(:deploy_config_to)
299
+ initialize_rsync_changes
300
+ refresh_checkout(setting(:deploy_config_to), config_branch)
301
+ end
302
+
303
+ def refresh_configuration
304
+ needs(:deploy_to, :deploy_config_to)
305
+ raise "Must specify project name when using a configuration repository." unless project_name_specified?
306
+ enqueue "echo Rsyncing configuration..."
307
+ enqueue("rsync -a#{'v --progress' if debugging?} " + '--log-format="%t [%p] %i %n" ' +
308
+ "#{setting(:deploy_config_to)}/#{setting(:project)}/#{setting(:config_target)}/ #{setting(:deploy_to)}/ " +
309
+ "> #{setting(:deploy_to)}/.whiskey_disk_rsync_changes")
310
+ end
311
+
312
+ def run_post_setup_hooks
313
+ needs(:deploy_to)
314
+ run_script(setting(:post_setup_script))
315
+ run_rake_task(setting(:deploy_to), "deploy:post_setup")
316
+ end
317
+
318
+ def run_post_deploy_hooks
319
+ needs(:deploy_to)
320
+ run_script(setting(:post_deploy_script))
321
+ run_rake_task(setting(:deploy_to), "deploy:post_deploy")
319
322
  end
320
323
  end