engineyard-serverside 2.6.17 → 2.6.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/lib/engineyard-serverside/dependency_manager/bundler.rb +1 -1
  3. data/lib/engineyard-serverside/slug.rb +7 -0
  4. data/lib/engineyard-serverside/slug/distributor.rb +58 -0
  5. data/lib/engineyard-serverside/slug/enabler.rb +100 -0
  6. data/lib/engineyard-serverside/slug/failure_handler.rb +24 -0
  7. data/lib/engineyard-serverside/slug/finalizer.rb +86 -0
  8. data/lib/engineyard-serverside/slug/generator.rb +29 -0
  9. data/lib/engineyard-serverside/slug/migrator.rb +41 -0
  10. data/lib/engineyard-serverside/slug/restarter.rb +103 -0
  11. data/lib/engineyard-serverside/slug/source.rb +16 -0
  12. data/lib/engineyard-serverside/slug/source/updater.rb +194 -0
  13. data/lib/engineyard-serverside/version.rb +1 -1
  14. data/lib/railway.rb +43 -0
  15. data/lib/result.rb +7 -0
  16. data/lib/result/base.rb +41 -0
  17. data/lib/result/dsl.rb +16 -0
  18. data/lib/result/failure.rb +29 -0
  19. data/lib/result/success.rb +24 -0
  20. data/lib/runner.rb +34 -0
  21. metadata +25 -405
  22. data/spec/archive_deploy_spec.rb +0 -53
  23. data/spec/basic_deploy_spec.rb +0 -26
  24. data/spec/bundler_deploy_spec.rb +0 -160
  25. data/spec/configuration_spec.rb +0 -206
  26. data/spec/custom_deploy_spec.rb +0 -128
  27. data/spec/deploy_hook_spec.rb +0 -362
  28. data/spec/deprecation_spec.rb +0 -23
  29. data/spec/ey_yml_customized_deploy_spec.rb +0 -99
  30. data/spec/fixtures/gitrepo.tar.gz +0 -0
  31. data/spec/fixtures/invalid_hook.rb +0 -1
  32. data/spec/fixtures/lockfiles/0.9-no-bundler +0 -111
  33. data/spec/fixtures/lockfiles/0.9-with-bundler +0 -117
  34. data/spec/fixtures/lockfiles/1.0-no-bundler +0 -54
  35. data/spec/fixtures/lockfiles/1.0.0.rc.1-with-bundler +0 -162
  36. data/spec/fixtures/lockfiles/1.0.18-do_mysql +0 -88
  37. data/spec/fixtures/lockfiles/1.0.18-do_postgres +0 -79
  38. data/spec/fixtures/lockfiles/1.0.18-mysql +0 -43
  39. data/spec/fixtures/lockfiles/1.0.18-mysql2 +0 -43
  40. data/spec/fixtures/lockfiles/1.0.18-pg +0 -43
  41. data/spec/fixtures/lockfiles/1.0.6-no-bundler +0 -51
  42. data/spec/fixtures/lockfiles/1.0.6-with-any-bundler +0 -52
  43. data/spec/fixtures/lockfiles/1.0.6-with-bundler +0 -52
  44. data/spec/fixtures/lockfiles/1.15.1-no-bundler +0 -51
  45. data/spec/fixtures/lockfiles/1.3.1-rails-3.2.13 +0 -112
  46. data/spec/fixtures/lockfiles/not-a-lockfile +0 -1
  47. data/spec/fixtures/repos/assets_detected/Gemfile +0 -5
  48. data/spec/fixtures/repos/assets_detected/Gemfile.lock +0 -88
  49. data/spec/fixtures/repos/assets_detected/README +0 -1
  50. data/spec/fixtures/repos/assets_detected/Rakefile +0 -5
  51. data/spec/fixtures/repos/assets_detected/app/assets/empty +0 -0
  52. data/spec/fixtures/repos/assets_detected/config/application.rb +0 -5
  53. data/spec/fixtures/repos/assets_detected/config/ey.yml +0 -3
  54. data/spec/fixtures/repos/assets_disabled/Gemfile +0 -5
  55. data/spec/fixtures/repos/assets_disabled/Gemfile.lock +0 -88
  56. data/spec/fixtures/repos/assets_disabled/README +0 -1
  57. data/spec/fixtures/repos/assets_disabled/Rakefile +0 -6
  58. data/spec/fixtures/repos/assets_disabled/app/assets/empty +0 -0
  59. data/spec/fixtures/repos/assets_disabled/config/application.rb +0 -5
  60. data/spec/fixtures/repos/assets_disabled/config/ey.yml +0 -3
  61. data/spec/fixtures/repos/assets_disabled_in_ey_yml/Gemfile +0 -5
  62. data/spec/fixtures/repos/assets_disabled_in_ey_yml/Gemfile.lock +0 -88
  63. data/spec/fixtures/repos/assets_disabled_in_ey_yml/README +0 -1
  64. data/spec/fixtures/repos/assets_disabled_in_ey_yml/Rakefile +0 -6
  65. data/spec/fixtures/repos/assets_disabled_in_ey_yml/app/assets/empty +0 -0
  66. data/spec/fixtures/repos/assets_disabled_in_ey_yml/config/application.rb +0 -5
  67. data/spec/fixtures/repos/assets_disabled_in_ey_yml/config/ey.yml +0 -5
  68. data/spec/fixtures/repos/assets_disabled_utf8/Gemfile +0 -5
  69. data/spec/fixtures/repos/assets_disabled_utf8/Gemfile.lock +0 -88
  70. data/spec/fixtures/repos/assets_disabled_utf8/README +0 -3
  71. data/spec/fixtures/repos/assets_disabled_utf8/Rakefile +0 -5
  72. data/spec/fixtures/repos/assets_disabled_utf8/app/assets/empty +0 -0
  73. data/spec/fixtures/repos/assets_disabled_utf8/config/application.rb +0 -7
  74. data/spec/fixtures/repos/assets_disabled_utf8/config/ey.yml +0 -3
  75. data/spec/fixtures/repos/assets_enabled_all/Gemfile +0 -5
  76. data/spec/fixtures/repos/assets_enabled_all/Gemfile.lock +0 -88
  77. data/spec/fixtures/repos/assets_enabled_all/README +0 -1
  78. data/spec/fixtures/repos/assets_enabled_all/app/assets/empty +0 -0
  79. data/spec/fixtures/repos/assets_enabled_all/config/application.rb +0 -5
  80. data/spec/fixtures/repos/assets_enabled_all/config/ey.yml +0 -6
  81. data/spec/fixtures/repos/assets_enabled_all/script/assets +0 -5
  82. data/spec/fixtures/repos/assets_enabled_all/tmp/obstruction +0 -1
  83. data/spec/fixtures/repos/assets_enabled_in_ey_yml/Gemfile +0 -3
  84. data/spec/fixtures/repos/assets_enabled_in_ey_yml/Gemfile.lock +0 -10
  85. data/spec/fixtures/repos/assets_enabled_in_ey_yml/README +0 -1
  86. data/spec/fixtures/repos/assets_enabled_in_ey_yml/Rakefile +0 -8
  87. data/spec/fixtures/repos/assets_enabled_in_ey_yml/config/ey.yml +0 -4
  88. data/spec/fixtures/repos/assets_enabled_util_only/Gemfile +0 -5
  89. data/spec/fixtures/repos/assets_enabled_util_only/Gemfile.lock +0 -88
  90. data/spec/fixtures/repos/assets_enabled_util_only/README +0 -1
  91. data/spec/fixtures/repos/assets_enabled_util_only/Rakefile +0 -6
  92. data/spec/fixtures/repos/assets_enabled_util_only/app/assets/empty +0 -0
  93. data/spec/fixtures/repos/assets_enabled_util_only/config/application.rb +0 -5
  94. data/spec/fixtures/repos/assets_enabled_util_only/config/ey.yml +0 -6
  95. data/spec/fixtures/repos/assets_error/Gemfile +0 -5
  96. data/spec/fixtures/repos/assets_error/Gemfile.lock +0 -88
  97. data/spec/fixtures/repos/assets_error/README +0 -1
  98. data/spec/fixtures/repos/assets_error/Rakefile +0 -4
  99. data/spec/fixtures/repos/assets_error/app/assets/empty +0 -0
  100. data/spec/fixtures/repos/assets_error/config/application.rb +0 -5
  101. data/spec/fixtures/repos/assets_error/config/ey.yml +0 -4
  102. data/spec/fixtures/repos/assets_in_hook/Gemfile +0 -5
  103. data/spec/fixtures/repos/assets_in_hook/Gemfile.lock +0 -88
  104. data/spec/fixtures/repos/assets_in_hook/README +0 -2
  105. data/spec/fixtures/repos/assets_in_hook/Rakefile +0 -5
  106. data/spec/fixtures/repos/assets_in_hook/app/assets/empty +0 -0
  107. data/spec/fixtures/repos/assets_in_hook/config/application.rb +0 -5
  108. data/spec/fixtures/repos/assets_in_hook/config/ey.yml +0 -3
  109. data/spec/fixtures/repos/assets_in_hook/deploy/before_compile_assets.rb +0 -2
  110. data/spec/fixtures/repos/bundle_fails/Gemfile +0 -1
  111. data/spec/fixtures/repos/bundle_fails/README +0 -1
  112. data/spec/fixtures/repos/bundle_fails/deploy/after_bundle.rb +0 -1
  113. data/spec/fixtures/repos/bundler_disabled/Gemfile +0 -4
  114. data/spec/fixtures/repos/bundler_disabled/Gemfile.lock +0 -12
  115. data/spec/fixtures/repos/bundler_disabled/README +0 -1
  116. data/spec/fixtures/repos/bundler_disabled/config/ey.yml +0 -2
  117. data/spec/fixtures/repos/bundler_disabled/deploy/after_bundle.rb +0 -1
  118. data/spec/fixtures/repos/bundler_disabled/deploy/before_bundle.rb +0 -1
  119. data/spec/fixtures/repos/bundler_old/Gemfile +0 -5
  120. data/spec/fixtures/repos/bundler_old/Gemfile.lock +0 -15
  121. data/spec/fixtures/repos/bundler_old/README +0 -1
  122. data/spec/fixtures/repos/default/Gemfile +0 -4
  123. data/spec/fixtures/repos/default/Gemfile.lock +0 -12
  124. data/spec/fixtures/repos/default/README +0 -5
  125. data/spec/fixtures/repos/default/ey.yml +0 -3
  126. data/spec/fixtures/repos/executable_hooks/README +0 -1
  127. data/spec/fixtures/repos/executable_hooks/deploy/before_restart +0 -72
  128. data/spec/fixtures/repos/executable_hooks_not_executable/README +0 -3
  129. data/spec/fixtures/repos/executable_hooks_not_executable/deploy/before_restart +0 -3
  130. data/spec/fixtures/repos/ey_yml/Gemfile +0 -4
  131. data/spec/fixtures/repos/ey_yml/Gemfile.lock +0 -12
  132. data/spec/fixtures/repos/ey_yml/README +0 -1
  133. data/spec/fixtures/repos/ey_yml/config/ey.yml +0 -18
  134. data/spec/fixtures/repos/ey_yml/deploy/before_migrate.rb +0 -6
  135. data/spec/fixtures/repos/ey_yml_alt/Gemfile +0 -4
  136. data/spec/fixtures/repos/ey_yml_alt/Gemfile.lock +0 -12
  137. data/spec/fixtures/repos/ey_yml_alt/README +0 -1
  138. data/spec/fixtures/repos/ey_yml_alt/deploy/before_migrate.rb +0 -6
  139. data/spec/fixtures/repos/ey_yml_alt/ey.yml +0 -12
  140. data/spec/fixtures/repos/hook_fails/README +0 -1
  141. data/spec/fixtures/repos/hook_fails/deploy/before_deploy.rb +0 -1
  142. data/spec/fixtures/repos/hooks/README +0 -1
  143. data/spec/fixtures/repos/hooks/deploy/after_bundle.rb +0 -1
  144. data/spec/fixtures/repos/hooks/deploy/after_compile_assets.rb +0 -1
  145. data/spec/fixtures/repos/hooks/deploy/after_deploy.rb +0 -1
  146. data/spec/fixtures/repos/hooks/deploy/after_migrate.rb +0 -1
  147. data/spec/fixtures/repos/hooks/deploy/after_restart.rb +0 -1
  148. data/spec/fixtures/repos/hooks/deploy/after_symlink.rb +0 -1
  149. data/spec/fixtures/repos/hooks/deploy/before_bundle.rb +0 -1
  150. data/spec/fixtures/repos/hooks/deploy/before_compile_assets.rb +0 -1
  151. data/spec/fixtures/repos/hooks/deploy/before_deploy.rb +0 -1
  152. data/spec/fixtures/repos/hooks/deploy/before_migrate.rb +0 -1
  153. data/spec/fixtures/repos/hooks/deploy/before_restart.rb +0 -1
  154. data/spec/fixtures/repos/hooks/deploy/before_symlink.rb +0 -1
  155. data/spec/fixtures/repos/multi_dep_manager/README +0 -1
  156. data/spec/fixtures/repos/multi_dep_manager/composer.json +0 -5
  157. data/spec/fixtures/repos/multi_dep_manager/composer.lock +0 -462
  158. data/spec/fixtures/repos/multi_dep_manager/package.json +0 -7
  159. data/spec/fixtures/repos/multi_dep_manager/public/index.php +0 -4
  160. data/spec/fixtures/repos/no_ey_config/Gemfile +0 -3
  161. data/spec/fixtures/repos/no_ey_config/Gemfile.lock +0 -10
  162. data/spec/fixtures/repos/no_ey_config/README +0 -1
  163. data/spec/fixtures/repos/no_ey_config/ey.yml +0 -3
  164. data/spec/fixtures/repos/no_ey_config_no_warning/Gemfile +0 -3
  165. data/spec/fixtures/repos/no_ey_config_no_warning/Gemfile.lock +0 -10
  166. data/spec/fixtures/repos/no_ey_config_no_warning/README +0 -1
  167. data/spec/fixtures/repos/no_ey_config_no_warning/ey.yml +0 -5
  168. data/spec/fixtures/repos/no_gemfile_lock/Gemfile +0 -4
  169. data/spec/fixtures/repos/no_gemfile_lock/README +0 -1
  170. data/spec/fixtures/repos/no_gemfile_lock/ey.yml +0 -3
  171. data/spec/fixtures/repos/nodejs/README +0 -1
  172. data/spec/fixtures/repos/nodejs/package.json +0 -7
  173. data/spec/fixtures/repos/not_bundled/README +0 -1
  174. data/spec/fixtures/repos/npm_disabled/README +0 -1
  175. data/spec/fixtures/repos/npm_disabled/config/ey.yml +0 -2
  176. data/spec/fixtures/repos/npm_disabled/package.json +0 -7
  177. data/spec/fixtures/repos/php_composer_disabled/README +0 -1
  178. data/spec/fixtures/repos/php_composer_disabled/composer.json +0 -5
  179. data/spec/fixtures/repos/php_composer_disabled/composer.lock +0 -462
  180. data/spec/fixtures/repos/php_composer_disabled/config/ey.yml +0 -2
  181. data/spec/fixtures/repos/php_composer_disabled/public/index.php +0 -4
  182. data/spec/fixtures/repos/php_composer_lock/README +0 -1
  183. data/spec/fixtures/repos/php_composer_lock/composer.json +0 -5
  184. data/spec/fixtures/repos/php_composer_lock/composer.lock +0 -462
  185. data/spec/fixtures/repos/php_composer_lock/public/index.php +0 -4
  186. data/spec/fixtures/repos/php_no_composer_lock/README +0 -1
  187. data/spec/fixtures/repos/php_no_composer_lock/composer.json +0 -21
  188. data/spec/fixtures/repos/php_no_composer_lock/public/index.php +0 -4
  189. data/spec/fixtures/repos/public_system/Gemfile +0 -4
  190. data/spec/fixtures/repos/public_system/Gemfile.lock +0 -12
  191. data/spec/fixtures/repos/public_system/README +0 -5
  192. data/spec/fixtures/repos/public_system/ey.yml +0 -3
  193. data/spec/fixtures/repos/public_system/public/system/cant_touch_this.txt +0 -3
  194. data/spec/fixtures/repos/sqlite3/Gemfile +0 -4
  195. data/spec/fixtures/repos/sqlite3/Gemfile.lock +0 -89
  196. data/spec/fixtures/repos/sqlite3/README +0 -1
  197. data/spec/fixtures/retwisj.war +0 -0
  198. data/spec/fixtures/valid_hook.rb +0 -1
  199. data/spec/git_strategy_spec.rb +0 -34
  200. data/spec/lockfile_parser_spec.rb +0 -126
  201. data/spec/maintenance_spec.rb +0 -44
  202. data/spec/multi_dependency_manager_spec.rb +0 -25
  203. data/spec/nodejs_deploy_spec.rb +0 -30
  204. data/spec/php_deploy_spec.rb +0 -81
  205. data/spec/platform_configure_spec.rb +0 -61
  206. data/spec/rails31_deploy_spec.rb +0 -172
  207. data/spec/restart_spec.rb +0 -43
  208. data/spec/rollback_spec.rb +0 -87
  209. data/spec/server_spec.rb +0 -70
  210. data/spec/services_deploy_spec.rb +0 -165
  211. data/spec/shell_spec.rb +0 -57
  212. data/spec/source/archive_spec.rb +0 -33
  213. data/spec/source/git_spec.rb +0 -44
  214. data/spec/spec_helper.rb +0 -360
  215. data/spec/sqlite3_deploy_spec.rb +0 -38
  216. data/spec/support/integration.rb +0 -103
  217. data/spec/support/source_doubles.rb +0 -28
  218. data/spec/support/timecop.rb +0 -5
  219. data/spec/symlink_spec.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc8524f480f3b28b00ec3696240dc84f69b048ddcb3c8048daa3fa0870ca74bd
4
- data.tar.gz: 465b40842bb42ff53233590f9d52f4b1526875f590bac33cb9b39dd988309a2d
3
+ metadata.gz: cf8aba371f49c2c647e8bc5aabde90beb0151fd533997d863e5e5d61966d68b4
4
+ data.tar.gz: f8889817020595bcc1c55425c676aa7aa856862a1d8397b4ab85189a17f2a6ee
5
5
  SHA512:
6
- metadata.gz: b0729fb3d4bdfef8fd15d394ae6096b4b370e03576562bc97e8099d2413142d41ab487cb9940b9d2ccb1e1b6ccd698b4fd9ef97261a71b6fa1c62ae1bbea09f6
7
- data.tar.gz: 49d69442d91d472b0f9c6855bd41b92e2858621c781085a98e6b1f5188b421cb0708ede2f1e85b12db33668cdc013a77bba84150850c1dd47c484e69454b7f3e
6
+ metadata.gz: 90c63aad8219f0dc9b33e55588c87cbc80d0d94ef40da1dc10e48f646548f6ebc953247f158c6bbf641930b74ccc8895f6bd1f391926be722c102c47e354b65c
7
+ data.tar.gz: ae839c8c4feed22c8b5fb67e4a30f7209b4a79df7bd08a190cd25e421f7efec811c41c7b6059c9960e06c97a2aca3c97b44fe9570b688114703fb2048a0ef36d
@@ -94,7 +94,7 @@ To fix this problem, commit your Gemfile.lock to your repository and redeploy.
94
94
  # the [,)] is to stop us from looking for e.g. 0.9.2, seeing
95
95
  # 0.9.22, and mistakenly thinking 0.9.2 is there
96
96
  has_gem_cmd = %{gem list bundler | grep "bundler " | egrep -q "#{egrep_escaped_version}[,)]"}
97
- install_cmd = %{gem install bundler -q --no-rdoc --no-ri -v "#{bundler_version}"}
97
+ install_cmd = %{gem install bundler -q -v "#{bundler_version}"}
98
98
  sudo "#{clean_environment} && #{has_gem_cmd} || #{install_cmd}"
99
99
  end
100
100
 
@@ -0,0 +1,7 @@
1
+ module EY
2
+ module Serverside
3
+ module Slug
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ require 'railway'
2
+ require 'runner'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Slug
7
+ class Distributor
8
+ include Railway
9
+ include Runner
10
+
11
+ step :find_remotes
12
+ step :distribute_to_remotes
13
+
14
+ def self.distribute(data = {})
15
+ new(data[:config], data[:shell], data[:servers]).call(data)
16
+ end
17
+
18
+ attr_reader :config, :shell, :servers
19
+
20
+ def initialize(config, shell, servers)
21
+ @config = config
22
+ @shell = shell
23
+ @servers = servers
24
+ end
25
+
26
+ private
27
+ def find_remotes(input = {})
28
+ remotes = servers.
29
+ to_a.
30
+ reject {|server| server.role.to_sym == :app_master}
31
+
32
+ Success(input.merge(:remotes => remotes))
33
+ end
34
+
35
+ def distribute_to_remotes(input = {})
36
+ remotes = input[:remotes]
37
+ releases_path = "/data/#{input[:app_name]}/releases"
38
+ package = "#{releases_path}/#{input[:release_name]}.tgz"
39
+ internal_key = config.paths.internal_key
40
+
41
+ remotes.each do |remote|
42
+ cmd = "scp -i #{internal_key} #{package} #{remote.user}@#{remote.hostname}:#{releases_path}"
43
+
44
+ unless run_and_success?(cmd)
45
+ return Failure(
46
+ input.merge(
47
+ :error => "Could not copy #{package} to #{remote.hostname}"
48
+ )
49
+ )
50
+ end
51
+ end
52
+
53
+ Success(input)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,100 @@
1
+ require 'railway'
2
+ require 'runner'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Slug
7
+
8
+ class Enabler
9
+ include Railway
10
+ include Runner
11
+
12
+ step :enable_remotes
13
+ step :enable_local
14
+
15
+ attr_reader :config, :shell, :servers
16
+
17
+ def initialize(config, shell, servers)
18
+ @config = config
19
+ @shell = shell
20
+ @servers = servers
21
+ end
22
+
23
+ private
24
+ def enable_remotes(data)
25
+ enabled = []
26
+
27
+ remotes.each do |remote|
28
+ if run_and_success?(remote_command(remote, data))
29
+ enabled.push(remote)
30
+ else
31
+ return Failure(
32
+ data.merge(
33
+ :enabled => enabled,
34
+ :error => "Could not enable #{data[:release_name]} on #{remote.hostname}"
35
+ )
36
+ )
37
+ end
38
+ end
39
+
40
+ Success(data.merge(:enabled => enabled))
41
+ end
42
+
43
+ def enable_local(data = {})
44
+ unless run_and_success?(local_command(data))
45
+ return Failure(data.merge(:error => "Could not enable #{data[:release_name]} on the app master"))
46
+ end
47
+
48
+ data[:enabled].push(servers.first {|server| server.role == :app_master || server.role == :solo})
49
+
50
+ Success(data)
51
+ end
52
+
53
+ def remotes
54
+ servers.reject {|server| server.role == :app_master}
55
+ end
56
+
57
+ def remote_command(remote, data)
58
+ "ssh -i #{config.paths.internal_key} #{remote.user}@#{remote.hostname} '#{create_release(data)} && #{unarchive(data)} && #{link_current(data)}'"
59
+ end
60
+
61
+ def local_command(data)
62
+ "#{unarchive(data)} && #{link_current(data)}"
63
+ end
64
+
65
+ def create_release(data)
66
+ "mkdir -p #{release_path(data)}"
67
+ end
68
+
69
+ def unarchive(data)
70
+ "tar -C #{release_path(data)} -z -x -f #{package(data)}"
71
+ end
72
+
73
+ def link_current(data)
74
+ "ln -nsf #{release_path(data)} #{current_path(data)}"
75
+ end
76
+
77
+ def package(data)
78
+ "#{release_path(data)}.tgz"
79
+ end
80
+
81
+ def release_path(data)
82
+ "#{all_releases(data)}/#{data[:release_name]}"
83
+ end
84
+
85
+ def all_releases(data)
86
+ "#{app_path(data)}/releases"
87
+ end
88
+
89
+ def current_path(data)
90
+ "#{app_path(data)}/current"
91
+ end
92
+
93
+ def app_path(data)
94
+ "/data/#{data[:app_name]}"
95
+ end
96
+ end
97
+
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,24 @@
1
+ require 'result'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Slug
6
+
7
+ class FailureHandler
8
+ def self.handle(data = {})
9
+ new(data[:config], data[:shell], data[:servers]).call(data)
10
+ end
11
+
12
+ def initialize(config, shell, servers)
13
+ @config = config
14
+ @shell = shell
15
+ @servers = servers
16
+ end
17
+
18
+ def call(data = {})
19
+ Result::Failure.new(data)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,86 @@
1
+ require 'railway'
2
+ require 'runner'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Slug
7
+
8
+ class Finalizer
9
+ include Railway
10
+ include Runner
11
+
12
+ step :finalize_remotes
13
+ step :finalize_local
14
+
15
+ attr_reader :config, :shell, :servers
16
+
17
+ def initialize(config, shell, servers)
18
+ @config = config
19
+ @shell = shell
20
+ @servers = servers
21
+ end
22
+
23
+ private
24
+ def finalize_remotes(data)
25
+ finalized = []
26
+
27
+ remotes.each do |remote|
28
+ if run_and_success?(remote_command(remote, data))
29
+ finalized.push(remote)
30
+ else
31
+ return Failure(
32
+ data.merge(
33
+ :finalized => finalized,
34
+ :error => "Could not finalize #{data[:release_name]} on #{remote.hostname}"
35
+ )
36
+ )
37
+ end
38
+ end
39
+
40
+ Success(data.merge(:finalized => finalized))
41
+ end
42
+
43
+ def finalize_local(data = {})
44
+ unless run_and_success?(finalize_command(data))
45
+ return Failure(data.merge(:error => "Could not finalize #{data[:release_name]} on the app master"))
46
+ end
47
+
48
+ data[:finalized].push(servers.first {|server| server.role == :app_master || server.role == :solo})
49
+
50
+ Success(data)
51
+ end
52
+
53
+ def remotes
54
+ servers.reject {|server| server.role == :app_master}
55
+ end
56
+
57
+ def remote_command(remote, data)
58
+ "ssh -i #{config.paths.internal_key} #{remote.user}@#{remote.hostname} '#{finalize_command(data)}'"
59
+ end
60
+
61
+ def finalize_command(data)
62
+ [
63
+ "for release in #{all_releases(data)}/*",
64
+ %{do if [ -d "${release}" ] && [ "$(basename "${release}")" != "#{data[:release_name]}"]},
65
+ 'then rm -rf "${release}"',
66
+ 'fi',
67
+ 'done'
68
+ ].join(' ; ')
69
+ end
70
+
71
+ def old_release_path(data)
72
+ "#{all_releases(data)}/#{data[:current_release_name]}"
73
+ end
74
+
75
+ def all_releases(data)
76
+ "#{app_path(data)}/releases"
77
+ end
78
+
79
+ def app_path(data)
80
+ "/data/#{data[:app_name]}"
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,29 @@
1
+ require 'result'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Slug
6
+
7
+ module Generator
8
+ extend Result::DSL
9
+
10
+ def self.generate(data = {})
11
+ data[:shell].logged_system(ogun(data)).success? ?
12
+ Success(data.merge(:generated => true)) :
13
+ Failure(data.merge(:error => "Ogun build failed"))
14
+ end
15
+
16
+ def self.ogun(data = {})
17
+ [
18
+ "/engineyard/bin/ogun",
19
+ "build",
20
+ data[:app_name],
21
+ "--release",
22
+ data[:release_name]
23
+ ].join(' ')
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'result'
2
+ require 'runner'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Slug
7
+ class Migrator
8
+ include Result::DSL
9
+ include Runner
10
+
11
+ attr_reader :config, :shell
12
+
13
+ def initialize(config, shell)
14
+ @config = config
15
+ @shell = shell
16
+ end
17
+
18
+ def call(data = {})
19
+ return Success(data) unless config.migrate?
20
+
21
+ cmd = "PATH=#{paths.binstubs}:$PATH #{config.framework_envs} #{config.migration_command}"
22
+
23
+ return Failure(
24
+ data.merge(:error => "Could not migrate database")
25
+ ) unless Dir.chdir(paths.active_release) {run_and_success?(cmd)}
26
+
27
+ Success(data.merge(:migrated => true))
28
+ end
29
+
30
+ private
31
+ def paths
32
+ config.paths
33
+ end
34
+
35
+ def self.migrate(data = {})
36
+ new(data[:config], data[:shell]).call(data)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,103 @@
1
+ require 'railway'
2
+ require 'runner'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Slug
7
+
8
+ class Restarter
9
+ include Railway
10
+ include Runner
11
+
12
+ step :restart_remote_apps
13
+ step :restart_local
14
+
15
+ attr_reader :config, :shell, :servers
16
+
17
+ def self.restart(data = {})
18
+ new(data[:config], data[:shell], data[:servers]).call(data)
19
+ end
20
+
21
+ def initialize(config, shell, servers)
22
+ @config = config
23
+ @shell = shell
24
+ @servers = servers
25
+ end
26
+
27
+ private
28
+ def restart_remote_apps(data = {})
29
+ restarted = []
30
+
31
+ remote_apps.each do |remote|
32
+ if run_and_success?(remote_command(remote, data))
33
+ restarted.push(remote)
34
+ else
35
+ return Failure(
36
+ data.merge(
37
+ :restarted => restarted,
38
+ :error => "Could not restart #{data[:release_name]} on #{remote.hostname}"
39
+ )
40
+ )
41
+ end
42
+ end
43
+
44
+ Success(data.merge(:restarted => restarted))
45
+ end
46
+
47
+ def restart_local(data = {})
48
+ unless run_and_success?(restart_command(data))
49
+ return Failure(data.merge(:error => "Could not restart #{data[:release_name]} on the app master"))
50
+ end
51
+
52
+ data[:restarted].push(master)
53
+
54
+ Success(data)
55
+ end
56
+
57
+ def remotes
58
+ server_array.reject {|server|
59
+ master?(server)
60
+ }
61
+ end
62
+
63
+ def remote_apps
64
+ remotes.select {|server| server.role == :app}
65
+ end
66
+
67
+ def master?(server)
68
+ server == master
69
+ end
70
+
71
+ def util?(server)
72
+ server.role == :util
73
+ end
74
+
75
+ def master
76
+ @master ||= server_array.find {|server|
77
+ master_roles.include?(server.role)
78
+ }
79
+ end
80
+
81
+ def master_roles
82
+ [:app_master, :solo]
83
+ end
84
+
85
+ def server_array
86
+ @server_array ||= servers.to_a
87
+ end
88
+
89
+ def remote_command(remote, data)
90
+ "ssh -i #{internal_key} #{remote.user}@#{remote.hostname} '#{restart_command(data)}'"
91
+ end
92
+
93
+ def restart_command(data)
94
+ %{LANG="en_US.UTF-8" /engineyard/bin/app_#{data[:app_name]} deploy}
95
+ end
96
+
97
+ def internal_key
98
+ config.paths.internal_key
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end