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.
- data/CHANGELOG +25 -15
- data/README.integration_specs +24 -36
- data/README.markdown +112 -96
- data/Rakefile +79 -5
- data/VERSION +1 -1
- data/lib/whiskey_disk.rb +297 -294
- data/lib/whiskey_disk/config.rb +99 -168
- data/lib/whiskey_disk/config/abstract_filter.rb +19 -0
- data/lib/whiskey_disk/config/filter.rb +48 -0
- data/lib/whiskey_disk/config/filters/add_environment_name_filter.rb +11 -0
- data/lib/whiskey_disk/config/filters/add_project_name_filter.rb +11 -0
- data/lib/whiskey_disk/config/filters/check_for_duplicate_domains_filter.rb +21 -0
- data/lib/whiskey_disk/config/filters/convert_role_strings_to_list_filter.rb +20 -0
- data/lib/whiskey_disk/config/filters/default_config_target_filter.rb +12 -0
- data/lib/whiskey_disk/config/filters/default_domain_filter.rb +12 -0
- data/lib/whiskey_disk/config/filters/drop_empty_domain_roles_filter.rb +32 -0
- data/lib/whiskey_disk/config/filters/environment_scope_filter.rb +20 -0
- data/lib/whiskey_disk/config/filters/hashify_domain_entries_filter.rb +29 -0
- data/lib/whiskey_disk/config/filters/localize_domains_filter.rb +24 -0
- data/lib/whiskey_disk/config/filters/modules/scope_helper.rb +11 -0
- data/lib/whiskey_disk/config/filters/normalize_ssh_options_filter.rb +29 -0
- data/lib/whiskey_disk/config/filters/project_scope_filter.rb +34 -0
- data/lib/whiskey_disk/config/filters/select_project_and_environment_filter.rb +12 -0
- data/lib/whiskey_disk/config/filters/stringify_hash_keys_filter.rb +25 -0
- data/lib/whiskey_disk/helpers.rb +1 -1
- data/lib/whiskey_disk/rake.rb +25 -22
- data/scenarios/git_repositories/config.git/HEAD +1 -0
- data/scenarios/git_repositories/config.git/config +5 -0
- data/scenarios/git_repositories/config.git/description +1 -0
- data/scenarios/git_repositories/config.git/git-daemon-export-ok +0 -0
- data/scenarios/git_repositories/config.git/hooks/applypatch-msg.sample +15 -0
- data/scenarios/git_repositories/config.git/hooks/commit-msg.sample +24 -0
- data/scenarios/git_repositories/config.git/hooks/post-commit.sample +8 -0
- data/scenarios/git_repositories/config.git/hooks/post-receive.sample +15 -0
- data/scenarios/git_repositories/config.git/hooks/post-update.sample +8 -0
- data/scenarios/git_repositories/config.git/hooks/pre-applypatch.sample +14 -0
- data/scenarios/git_repositories/config.git/hooks/pre-commit.sample +46 -0
- data/scenarios/git_repositories/config.git/hooks/pre-rebase.sample +169 -0
- data/scenarios/git_repositories/config.git/hooks/prepare-commit-msg.sample +36 -0
- data/scenarios/git_repositories/config.git/hooks/update.sample +128 -0
- data/scenarios/git_repositories/config.git/info/exclude +6 -0
- data/scenarios/git_repositories/config.git/objects/0d/b14dd6ddc54017c0a11960dcda82ed802cde69 +0 -0
- data/scenarios/git_repositories/config.git/objects/0e/e781f5ce80d64db32a74a7aae7b5248dafe112 +3 -0
- data/scenarios/git_repositories/config.git/objects/17/6bf54cf17d1d1c24556dc059c4144a5df230e8 +0 -0
- data/scenarios/git_repositories/config.git/objects/20/e9ff3feaa8ede30f707e5f1b4356e3c02bb7ec +0 -0
- data/scenarios/git_repositories/config.git/objects/45/117b1c775f0de415478dbf08ed9d667ab17d13 +0 -0
- data/scenarios/git_repositories/config.git/objects/51/3954c9aca090e6ce40359f0e9fde30ea78eb8c +0 -0
- data/scenarios/git_repositories/config.git/objects/66/947a7a11a6f5d3d561fe95de284ced3010819a +0 -0
- data/scenarios/git_repositories/config.git/objects/6b/bc79311bfac47d3ed724aa82a4814e0dda4c67 +0 -0
- data/scenarios/git_repositories/config.git/objects/71/eb5df52676e8e6efba471050b46978173af110 +1 -0
- data/scenarios/git_repositories/config.git/objects/84/17d2fe3e8fcc0825249c517b29b0f9ea8b8b31 +2 -0
- data/scenarios/git_repositories/config.git/objects/8b/384fcfcf7c0dee7c3c1d5636bee9e645d9cf38 +0 -0
- data/scenarios/git_repositories/config.git/objects/bb/59da633ba74296b0c2f9ff70784ac155ddb599 +0 -0
- data/scenarios/git_repositories/config.git/objects/cc/b86b26189afbf45d8eb9165812ab86dbdfca63 +0 -0
- data/scenarios/git_repositories/config.git/objects/d1/0bcd51fec41f854001e4d61f99d9e282a695d3 +0 -0
- data/scenarios/git_repositories/config.git/objects/d8/a8b0f5b1fd66844efb141d9544965ea0065f2d +0 -0
- data/scenarios/git_repositories/config.git/objects/e6/b02c66ad632e6b8535c4630cb8fe07732a72fc +0 -0
- data/scenarios/git_repositories/config.git/objects/e8/b8bfeeba735c0a1a873082554cb4d7256ac125 +0 -0
- data/scenarios/git_repositories/config.git/objects/f9/0181466a1a60b793ca9cc9abd584c18d4e3887 +0 -0
- data/scenarios/git_repositories/config.git/objects/f9/49d5d8a4f12c91471e34d4e277239c35ebd10d +0 -0
- data/scenarios/git_repositories/config.git/refs/heads/master +1 -0
- data/scenarios/git_repositories/project.git/HEAD +1 -0
- data/scenarios/git_repositories/project.git/config +5 -0
- data/scenarios/git_repositories/project.git/description +1 -0
- data/scenarios/git_repositories/project.git/git-daemon-export-ok +0 -0
- data/scenarios/git_repositories/project.git/hooks/applypatch-msg.sample +15 -0
- data/scenarios/git_repositories/project.git/hooks/commit-msg.sample +24 -0
- data/scenarios/git_repositories/project.git/hooks/post-commit.sample +8 -0
- data/scenarios/git_repositories/project.git/hooks/post-receive.sample +15 -0
- data/scenarios/git_repositories/project.git/hooks/post-update.sample +8 -0
- data/scenarios/git_repositories/project.git/hooks/pre-applypatch.sample +14 -0
- data/scenarios/git_repositories/project.git/hooks/pre-commit.sample +46 -0
- data/scenarios/git_repositories/project.git/hooks/pre-rebase.sample +169 -0
- data/scenarios/git_repositories/project.git/hooks/prepare-commit-msg.sample +36 -0
- data/scenarios/git_repositories/project.git/hooks/update.sample +128 -0
- data/scenarios/git_repositories/project.git/info/exclude +6 -0
- data/scenarios/git_repositories/project.git/objects/04/26e152e66c8cd42974279bdcae09be9839c172 +0 -0
- data/scenarios/git_repositories/project.git/objects/04/f4de85eaf72ef1631dc6d7424045c0a749b757 +1 -0
- data/scenarios/git_repositories/project.git/objects/06/13fe277280cbcdb2856e1eefc70bdaff011b20 +0 -0
- data/scenarios/git_repositories/project.git/objects/06/7aca89b86265eee211387434c3e50f37ccf009 +0 -0
- data/scenarios/git_repositories/project.git/objects/09/445dacc4822722612d60833c9948219ecdd8f5 +0 -0
- data/scenarios/git_repositories/project.git/objects/11/c4ec64326de35462f4e79d0f4229bf8e26e0c5 +0 -0
- data/scenarios/git_repositories/project.git/objects/20/1c7641c2e42b0b904e5c1f793489d8b858e4da +2 -0
- data/scenarios/git_repositories/project.git/objects/23/979639da60d2d31e9744468df1c1221b101e64 +0 -0
- data/scenarios/git_repositories/project.git/objects/27/a3fff2c4c45ab5513a405f694c0a042cb5d417 +1 -0
- data/scenarios/git_repositories/project.git/objects/2c/0c33cfba8e1af15df88522c0db2b10a6a94138 +2 -0
- data/scenarios/git_repositories/project.git/objects/38/b574660305ecb5fec6b2daa7ee1e0dbf1b6003 +0 -0
- data/scenarios/git_repositories/project.git/objects/4a/57abb5e4e426cfc9101b3af22ac83ccbd8e2ad +0 -0
- data/scenarios/git_repositories/project.git/objects/4c/77ebdd985e57afe7988480720c5dc77ec525c9 +0 -0
- data/scenarios/git_repositories/project.git/objects/51/c94da6f1b8aa9d2346088d3d362475b60c7f32 +0 -0
- data/scenarios/git_repositories/project.git/objects/5b/a96acf9cc9b87babe37c032676f53bf1ba9ae7 +2 -0
- data/scenarios/git_repositories/project.git/objects/5d/f555601d60f1c2a84d2364af0ad640612c3ba5 +0 -0
- data/scenarios/git_repositories/project.git/objects/71/03b5ac94940d596c2160a5cfcd55ca4ccac41f +0 -0
- data/scenarios/git_repositories/project.git/objects/73/3fc331098b03523f414f3509b9ae6e637c6866 +0 -0
- data/scenarios/git_repositories/project.git/objects/80/26076649ceccbe96a6292f2432652f08483035 +0 -0
- data/scenarios/git_repositories/project.git/objects/86/d1ef0976be4567de562224e1b51fbf9820c53a +1 -0
- data/scenarios/git_repositories/project.git/objects/87/a9d8b09b3401d21b23d90253332d6b28b47db2 +0 -0
- data/scenarios/git_repositories/project.git/objects/8b/030ba688255c917d189ae3f87d7c5ccd226bc2 +0 -0
- data/scenarios/git_repositories/project.git/objects/95/c9d5ad9b1c90e4c805516783105fc2037dedeb +2 -0
- data/scenarios/git_repositories/project.git/objects/95/d82d043af35a80eabfd56c0d705abfa3488787 +2 -0
- data/scenarios/git_repositories/project.git/objects/96/0bf34bb0b46d0aeb0be87f688f4ef06a4b35e1 +0 -0
- data/scenarios/git_repositories/project.git/objects/a3/860106dc1d148c7831cd45ae38829b4ed47702 +2 -0
- data/scenarios/git_repositories/project.git/objects/a8/506d6439b71784a72ac72d284b2ad53088f573 +0 -0
- data/scenarios/git_repositories/project.git/objects/ad/22ea6c7563777936ecfbe50d8e2cf8120fd525 +0 -0
- data/scenarios/git_repositories/project.git/objects/ae/3900de54aff557c61c81146d00f9d38e55a265 +1 -0
- data/scenarios/git_repositories/project.git/objects/bf/5e3740d52b80abb0378b3f85f93a53b1294521 +1 -0
- data/scenarios/git_repositories/project.git/objects/bf/b59811cdbc069418dee14b171e6e7e979784b7 +0 -0
- data/scenarios/git_repositories/project.git/objects/cc/5ac0afb24e727d5de344cc26a425f4fb7fd17d +3 -0
- data/scenarios/git_repositories/project.git/objects/d1/091aa2dd76885108461110c639e6b33a297fce +0 -0
- data/scenarios/git_repositories/project.git/objects/d8/913f6650eb2b7bf2a633732d8452008ca23dcb +0 -0
- data/scenarios/git_repositories/project.git/objects/db/d1b9667f1b26b13331ac0c321dced8be1aeab0 +3 -0
- data/scenarios/git_repositories/project.git/objects/e4/3b9107e9b1908ce415025e64eb83a493d329b7 +0 -0
- data/scenarios/git_repositories/project.git/objects/ef/2a88894d5421920b9dfe67a9a4d8043830e62e +0 -0
- data/scenarios/git_repositories/project.git/objects/f4/0123a1ff20c65d8dc15a38a83222647908e6f7 +0 -0
- data/scenarios/git_repositories/project.git/objects/f5/0af315b75ca0b12c720dec6d916b76b968c319 +0 -0
- data/scenarios/git_repositories/project.git/objects/f6/0215709b7b23f3738e9cbaf634b1c86bbd376a +0 -0
- data/scenarios/git_repositories/project.git/refs/heads/bad_rakefile +1 -0
- data/scenarios/git_repositories/project.git/refs/heads/hook_with_changed +1 -0
- data/scenarios/git_repositories/project.git/refs/heads/master +1 -0
- data/scenarios/git_repositories/project.git/refs/heads/no_rake_hooks +1 -0
- data/scenarios/git_repositories/project.git/refs/heads/post_rake_tasks +1 -0
- data/scenarios/invalid/deploy.yml +1 -0
- data/scenarios/local/deploy.yml.erb +17 -0
- data/scenarios/remote/deploy.yml +119 -0
- data/scenarios/setup/vagrant/.gitignore +3 -0
- data/scenarios/setup/vagrant/Vagrantfile +10 -0
- data/scenarios/setup/vagrant/manifests/integration.pp +32 -0
- data/scenarios/setup/vagrant/pids/.gitignore +1 -0
- data/spec/init_spec.rb +1 -1
- data/spec/install_spec.rb +4 -4
- data/spec/integration/branch_switching_spec.rb +41 -0
- data/spec/integration/deployment_failures_spec.rb +106 -0
- data/spec/integration/helper_spec.rb +90 -0
- data/spec/integration/invalid_configuration_spec.rb +39 -0
- data/spec/integration/local_deployments_spec.rb +230 -0
- data/spec/integration/post_rake_tasks_spec.rb +226 -0
- data/spec/integration/post_scripts_spec.rb +246 -0
- data/spec/integration/remote_deployments_spec.rb +166 -0
- data/spec/integration/staleness_checks_spec.rb +72 -0
- data/spec/spec_helper.rb +30 -2
- data/spec/wd_command_spec.rb +136 -136
- data/spec/wd_role_command_spec.rb +5 -5
- data/spec/whiskey_disk/config/filter_spec.rb +77 -0
- data/spec/whiskey_disk/config/filters/add_environment_name_filter_spec.rb +20 -0
- data/spec/whiskey_disk/config/filters/add_project_name_filter_spec.rb +19 -0
- data/spec/whiskey_disk/config/filters/check_for_duplicate_domains_filter_spec.rb +29 -0
- data/spec/whiskey_disk/config/filters/convert_role_strings_to_list_filter_spec.rb +48 -0
- data/spec/whiskey_disk/config/filters/default_config_target_filter_spec.rb +19 -0
- data/spec/whiskey_disk/config/filters/default_domain_filter_spec.rb +18 -0
- data/spec/whiskey_disk/config/filters/drop_empty_domain_roles_filter_spec.rb +60 -0
- data/spec/whiskey_disk/config/filters/environment_scope_filter_spec.rb +32 -0
- data/spec/whiskey_disk/config/filters/hashify_domain_entries_filter_spec.rb +41 -0
- data/spec/whiskey_disk/config/filters/localize_domains_filter_spec.rb +30 -0
- data/spec/whiskey_disk/config/filters/normalize_ssh_options_filter_spec.rb +56 -0
- data/spec/whiskey_disk/config/filters/project_scope_filter_spec.rb +75 -0
- data/spec/whiskey_disk/config/filters/select_project_and_environment_filter_spec.rb +30 -0
- data/spec/whiskey_disk/config/filters/stringify_hash_keys_filter_spec.rb +40 -0
- data/spec/whiskey_disk/config_spec.rb +259 -446
- data/spec/whiskey_disk/helpers_spec.rb +51 -51
- data/spec/whiskey_disk/rake_spec.rb +80 -80
- data/spec/whiskey_disk_spec.rb +591 -562
- data/whiskey_disk.gemspec +151 -20
- 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
|
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
|
-
|
26
|
-
gemspec.
|
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.
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
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
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
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
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
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
|