engineyard-serverside 2.7.8pre2 → 2.8.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/bin/engineyard-serverside +1 -1
  2. data/bin/engineyard-serverside-execute-hook +1 -1
  3. data/bin/engineyard-serverside-execute-service-hook +35 -0
  4. data/lib/engineyard-serverside.rb +0 -1
  5. data/lib/engineyard-serverside/about.rb +11 -8
  6. data/lib/engineyard-serverside/callbacks.rb +11 -0
  7. data/lib/engineyard-serverside/callbacks/collection.rb +17 -0
  8. data/lib/engineyard-serverside/callbacks/collection/base.rb +79 -0
  9. data/lib/engineyard-serverside/callbacks/collection/combined.rb +45 -0
  10. data/lib/engineyard-serverside/callbacks/collection/deploy_hooks.rb +21 -0
  11. data/lib/engineyard-serverside/callbacks/collection/service_hooks.rb +17 -0
  12. data/lib/engineyard-serverside/callbacks/collection/service_hooks/collection.rb +24 -0
  13. data/lib/engineyard-serverside/callbacks/collection/service_hooks/combined.rb +40 -0
  14. data/lib/engineyard-serverside/callbacks/distributor.rb +21 -0
  15. data/lib/engineyard-serverside/callbacks/distributor/remote.rb +76 -0
  16. data/lib/engineyard-serverside/callbacks/distributor/viability_filter.rb +66 -0
  17. data/lib/engineyard-serverside/callbacks/executor.rb +23 -0
  18. data/lib/engineyard-serverside/callbacks/executor/base.rb +44 -0
  19. data/lib/engineyard-serverside/callbacks/executor/executable.rb +123 -0
  20. data/lib/engineyard-serverside/callbacks/executor/ruby.rb +20 -0
  21. data/lib/engineyard-serverside/callbacks/executor/ruby/context.rb +81 -0
  22. data/lib/engineyard-serverside/callbacks/executor/ruby/executor.rb +118 -0
  23. data/{spec/fixtures/gitrepo/bar → lib/engineyard-serverside/callbacks/hooks.rb} +0 -0
  24. data/lib/engineyard-serverside/callbacks/hooks/app.rb +21 -0
  25. data/lib/engineyard-serverside/callbacks/hooks/base.rb +43 -0
  26. data/lib/engineyard-serverside/callbacks/hooks/service.rb +28 -0
  27. data/lib/engineyard-serverside/callbacks/service_hook.rb +20 -0
  28. data/lib/engineyard-serverside/cli.rb +4 -225
  29. data/lib/engineyard-serverside/cli/app.rb +136 -0
  30. data/lib/engineyard-serverside/cli/helpers.rb +58 -0
  31. data/lib/engineyard-serverside/cli/server_hash_extractor.rb +49 -0
  32. data/lib/engineyard-serverside/cli/workflows.rb +45 -0
  33. data/lib/engineyard-serverside/cli/workflows/base.rb +78 -0
  34. data/lib/engineyard-serverside/cli/workflows/calling_deploy_hooks.rb +31 -0
  35. data/lib/engineyard-serverside/cli/workflows/deploying_applications.rb +28 -0
  36. data/lib/engineyard-serverside/cli/workflows/disabling_maintenance.rb +29 -0
  37. data/lib/engineyard-serverside/cli/workflows/enabling_maintenance.rb +29 -0
  38. data/lib/engineyard-serverside/cli/workflows/errors.rb +13 -0
  39. data/lib/engineyard-serverside/cli/workflows/helpers.rb +21 -0
  40. data/lib/engineyard-serverside/cli/workflows/integrating_servers.rb +71 -0
  41. data/lib/engineyard-serverside/cli/workflows/restarting_applications.rb +36 -0
  42. data/lib/engineyard-serverside/cli/workflows/rolling_back_applications.rb +28 -0
  43. data/lib/engineyard-serverside/cli/workflows/showing_maintenance_status.rb +28 -0
  44. data/lib/engineyard-serverside/configuration.rb +1 -0
  45. data/lib/engineyard-serverside/dependency_manager/bundler.rb +46 -18
  46. data/lib/engineyard-serverside/dependency_manager/npm.rb +12 -1
  47. data/lib/engineyard-serverside/deploy.rb +7 -45
  48. data/lib/engineyard-serverside/maintenance.rb +1 -9
  49. data/lib/engineyard-serverside/paths.rb +11 -0
  50. data/lib/engineyard-serverside/propagator.rb +59 -0
  51. data/lib/engineyard-serverside/rails_assets.rb +2 -1
  52. data/lib/engineyard-serverside/slug.rb +7 -0
  53. data/lib/engineyard-serverside/slug/distributor.rb +58 -0
  54. data/lib/engineyard-serverside/slug/enabler.rb +100 -0
  55. data/lib/engineyard-serverside/slug/failure_handler.rb +24 -0
  56. data/lib/engineyard-serverside/slug/finalizer.rb +86 -0
  57. data/lib/engineyard-serverside/slug/generator.rb +29 -0
  58. data/lib/engineyard-serverside/slug/migrator.rb +41 -0
  59. data/lib/engineyard-serverside/slug/restarter.rb +103 -0
  60. data/lib/engineyard-serverside/slug/source.rb +16 -0
  61. data/lib/engineyard-serverside/slug/source/updater.rb +194 -0
  62. data/lib/engineyard-serverside/version.rb +1 -1
  63. data/lib/railway.rb +43 -0
  64. data/lib/result.rb +7 -0
  65. data/lib/result/base.rb +41 -0
  66. data/lib/result/dsl.rb +16 -0
  67. data/lib/result/failure.rb +29 -0
  68. data/lib/result/success.rb +24 -0
  69. data/lib/runner.rb +34 -0
  70. data/spec/archive_deploy_spec.rb +1 -1
  71. data/spec/bundler_deploy_spec.rb +22 -1
  72. data/spec/configuration_spec.rb +1 -0
  73. data/spec/deploy_hook_spec.rb +148 -132
  74. data/spec/fixtures/lockfiles/1.15.1-no-bundler +51 -0
  75. data/spec/fixtures/repos/assets_error/Gemfile +5 -0
  76. data/spec/fixtures/repos/assets_error/Gemfile.lock +88 -0
  77. data/spec/fixtures/repos/assets_error/README +1 -0
  78. data/spec/fixtures/repos/assets_error/Rakefile +4 -0
  79. data/spec/fixtures/{gitrepo/foo → repos/assets_error/app/assets/empty} +0 -0
  80. data/spec/fixtures/repos/assets_error/config/application.rb +5 -0
  81. data/spec/fixtures/repos/assets_error/config/ey.yml +4 -0
  82. data/spec/fixtures/repos/bundler_old/Gemfile +5 -0
  83. data/spec/fixtures/repos/bundler_old/Gemfile.lock +15 -0
  84. data/spec/fixtures/repos/bundler_old/README +1 -0
  85. data/spec/fixtures/repos/no_ey_config_no_warning/Gemfile +3 -0
  86. data/spec/fixtures/repos/no_ey_config_no_warning/Gemfile.lock +10 -0
  87. data/spec/fixtures/repos/no_ey_config_no_warning/README +1 -0
  88. data/spec/fixtures/repos/no_ey_config_no_warning/ey.yml +5 -0
  89. data/spec/lockfile_parser_spec.rb +5 -1
  90. data/spec/rails31_deploy_spec.rb +8 -0
  91. data/spec/rollback_spec.rb +1 -1
  92. data/spec/services_deploy_spec.rb +12 -0
  93. data/spec/spec_helper.rb +14 -8
  94. metadata +488 -429
  95. data/lib/engineyard-serverside/cli_helpers.rb +0 -53
  96. data/lib/engineyard-serverside/deploy_hook.rb +0 -142
@@ -8,4 +8,4 @@ $LOAD_PATH.push(File.expand_path("../lib", File.dirname(__FILE__)))
8
8
 
9
9
  require 'engineyard-serverside'
10
10
 
11
- EY::Serverside::CLI.start
11
+ EY::Serverside::CLI::App.start
@@ -1,4 +1,4 @@
1
- #!/bin/sh
1
+ #!/bin/bash
2
2
 
3
3
  #
4
4
  # This script is used to execute non-ruby deploy hooks. It's called from
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+
3
+ #
4
+ # This script is used to execute non-ruby service hooks. It's called from
5
+ # EY::Serverside::Deploy#callback. If you'd like to call it directly you should
6
+ # be careful to replicate everything done in EY::Serverside::Deploy or your
7
+ # hook code may not execute as planned.
8
+ #
9
+
10
+ set -o nounset
11
+
12
+ abort() {
13
+ echo "$*"
14
+ exit 1
15
+ }
16
+
17
+ HOOK=${1:-}
18
+ [ -n "${HOOK}" ] || abort "No hook name provided."
19
+
20
+ # We run all deploy hooks from the root directory of the current release of
21
+ # their app.
22
+ [ -n "${EY_DEPLOY_RELEASE_PATH:-}" ] || abort "EY_DEPLOY_RELEASE_PATH must be set."
23
+ [ -d ${EY_DEPLOY_RELEASE_PATH} ] || abort "EY_DEPLOY_RELEASE_PATH must exist and be a directory"
24
+ cd ${EY_DEPLOY_RELEASE_PATH}
25
+
26
+ # Set up the service hook paths
27
+ _app_path=$(dirname $(dirname ${EY_DEPLOY_RELEASE_PATH}))
28
+ _service_hooks_path="${_app_path}/shared/hooks"
29
+
30
+ # Run the hook.
31
+ _hook_path="${service_hooks_path}/${HOOK}""
32
+ if [ ! \( -f ${_hook_path} -a -x ${_hook_path} \) ]; then
33
+ abort "${_hook_path} must exist and be executable"
34
+ fi
35
+ exec ${_hook_path}
@@ -28,7 +28,6 @@ require 'engineyard-serverside/about'
28
28
  require 'engineyard-serverside/task'
29
29
  require 'engineyard-serverside/server'
30
30
  require 'engineyard-serverside/deploy'
31
- require 'engineyard-serverside/deploy_hook'
32
31
  require 'engineyard-serverside/cli'
33
32
  require 'engineyard-serverside/configuration'
34
33
  require 'engineyard-serverside/deprecation'
@@ -25,22 +25,25 @@ module EY
25
25
  end
26
26
 
27
27
  def gem_binary
28
- File.join(Gem.default_bindir, 'gem')
28
+ gem_bin_path = File.join(Gem.default_bindir, 'gem')
29
+ if File.exists?("/usr/local/ey_resin/bin/ruby")
30
+ "/usr/local/ey_resin/bin/ruby -rubygems #{gem_bin_path}"
31
+ else
32
+ gem_bin_path
33
+ end
29
34
  end
30
35
 
31
36
  def binary
32
- resin_path = "/usr/local/ey_resin/ruby/bin/engineyard-serverside"
33
- if File.exists?(resin_path)
34
- resin_path
35
- else
36
- #gem relative path causes deploy hook failures if gem version mismatches with other app servers
37
- File.expand_path("../../../bin/#{gem_name}", __FILE__)
38
- end
37
+ File.expand_path("../../../bin/#{gem_name}", __FILE__)
39
38
  end
40
39
 
41
40
  def hook_executor
42
41
  binary + "-execute-hook"
43
42
  end
43
+
44
+ def service_hook_executor
45
+ binary + "-execute-service-hook"
46
+ end
44
47
  end
45
48
  end
46
49
  end
@@ -0,0 +1,11 @@
1
+ require 'engineyard-serverside/callbacks/collection'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Callbacks
6
+ def self.load(paths)
7
+ Collection.load(paths)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'engineyard-serverside/callbacks/collection/combined'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Callbacks
6
+
7
+ module Collection
8
+ attr_reader :app_hooks
9
+
10
+ def self.load(paths)
11
+ Combined.load(paths)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,79 @@
1
+ require 'engineyard-serverside/callbacks/distributor'
2
+ require 'engineyard-serverside/callbacks/executor'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Callbacks
7
+
8
+ module Collection
9
+ class Base
10
+ def self.load(paths)
11
+ new(paths)
12
+ end
13
+
14
+ def initialize(paths)
15
+ @paths = paths
16
+ load_hooks
17
+ end
18
+
19
+ def all
20
+ hooks
21
+ end
22
+
23
+ def matching(callback)
24
+ favor(
25
+ :ruby,
26
+ all.select {|hook| hook.matches?(callback.to_sym)}
27
+ )
28
+ end
29
+
30
+ def distribute(runner, callback)
31
+ Distributor.distribute(
32
+ runner,
33
+ minimize_ruby(
34
+ matching(callback)
35
+ )
36
+ )
37
+ end
38
+
39
+ def execute(config, shell, callback)
40
+ Executor.execute(
41
+ config,
42
+ shell,
43
+ matching(callback)
44
+ )
45
+ end
46
+
47
+ private
48
+ def favor(flavor, hooks)
49
+ (
50
+ hooks.select {|hook| hook.flavor == flavor} +
51
+ hooks.reject {|hook| hook.flavor == flavor}
52
+ ).first(1)
53
+ end
54
+
55
+ def minimize_ruby(hooks)
56
+ first_ruby = hooks.select {|hook| hook.flavor == :ruby}.first
57
+
58
+ return hooks unless first_ruby
59
+
60
+ ([first_ruby] + hooks.select {|hook| hook.flavor != :ruby}).flatten
61
+ end
62
+
63
+ def load_hooks
64
+ raise "Unimplemented"
65
+ end
66
+
67
+ def paths
68
+ @paths
69
+ end
70
+
71
+ def hooks
72
+ @hooks ||= []
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,45 @@
1
+ require 'engineyard-serverside/callbacks/collection/base'
2
+ require 'engineyard-serverside/callbacks/collection/deploy_hooks'
3
+ require 'engineyard-serverside/callbacks/collection/service_hooks'
4
+
5
+ module EY
6
+ module Serverside
7
+ module Callbacks
8
+ module Collection
9
+
10
+ class Combined < Base
11
+ def all
12
+ collections.
13
+ map {|collection| collection.all}.
14
+ flatten
15
+ end
16
+
17
+ def matching(callback)
18
+ collections.
19
+ map {|collection| collection.matching(callback)}.
20
+ flatten
21
+ end
22
+
23
+ private
24
+ def load_hooks
25
+ @service_hooks = ServiceHooks.load(paths)
26
+ @app_hooks = DeployHooks.load(paths)
27
+ end
28
+
29
+ def app_hooks
30
+ @app_hooks
31
+ end
32
+
33
+ def service_hooks
34
+ @service_hooks
35
+ end
36
+
37
+ def collections
38
+ [service_hooks, app_hooks]
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ require 'engineyard-serverside/callbacks/collection/base'
2
+ require 'engineyard-serverside/callbacks/hooks/app'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Callbacks
7
+ module Collection
8
+
9
+ class DeployHooks < Base
10
+ private
11
+ def load_hooks
12
+ Dir["#{paths.deploy_hooks}/*"].each do |hook_path|
13
+ hooks.push(Hooks::App.new(hook_path))
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ require 'engineyard-serverside/callbacks/collection/service_hooks/combined'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Callbacks
6
+ module Collection
7
+
8
+ module ServiceHooks
9
+ def self.load(paths)
10
+ Combined.load(paths)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ require 'engineyard-serverside/callbacks/collection/base'
2
+ require 'engineyard-serverside/callbacks/hooks/service'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Callbacks
7
+ module Collection
8
+ module ServiceHooks
9
+
10
+ class Collection < EY::Serverside::Callbacks::Collection::Base
11
+
12
+ private
13
+ def load_hooks
14
+ Dir["#{paths}/*"].each do |hook_path|
15
+ hooks.push(Hooks::Service.new(hook_path))
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ require 'engineyard-serverside/callbacks/collection/base'
2
+ require 'engineyard-serverside/callbacks/collection/service_hooks/collection'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Callbacks
7
+ module Collection
8
+ module ServiceHooks
9
+
10
+ class Combined < EY::Serverside::Callbacks::Collection::Base
11
+
12
+ def all
13
+ collections.
14
+ map {|collection| collection.all}.
15
+ flatten
16
+ end
17
+
18
+ def matching(callback)
19
+ collections.
20
+ map {|collection| collection.matching(callback)}.
21
+ flatten
22
+ end
23
+
24
+ private
25
+ def load_hooks
26
+ Dir["#{paths.shared_hooks}/*"].each do |service_path|
27
+ collections.push(ServiceHooks::Collection.load(service_path))
28
+ end
29
+ end
30
+
31
+ def collections
32
+ @collections ||= []
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ require 'engineyard-serverside/callbacks/distributor/remote'
2
+ require 'engineyard-serverside/callbacks/distributor/viability_filter'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Callbacks
7
+
8
+ module Distributor
9
+ def self.distribute(runner, hooks)
10
+ ViabilityFilter.
11
+ new.
12
+ call({:candidates => hooks, :shell => runner.shell}).
13
+ and_then {|callback_name|
14
+ Remote.distribute(runner, callback_name)
15
+ }
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,76 @@
1
+ module EY
2
+ module Serverside
3
+ module Callbacks
4
+ module Distributor
5
+
6
+ class Remote
7
+ attr_reader :runner, :hook
8
+
9
+ def self.distribute(runner, hook)
10
+ new(runner, hook).distribute
11
+ end
12
+
13
+ def initialize(runner, hook)
14
+ @runner = runner
15
+ @hook = hook
16
+ end
17
+
18
+ def distribute
19
+ shell.status "Running deploy hook: #{hook}"
20
+
21
+ runner.run escaped_command(hook) do |server, cmd|
22
+ instance_args = [
23
+ '--current-roles', server.roles.to_a.join(' ')
24
+ ]
25
+
26
+ if server.name
27
+ instance_args.push('--current-name')
28
+ instance_args.push(server.name.to_s)
29
+ end
30
+
31
+ instance_args.push('--config')
32
+ instance_args.push(config.to_json)
33
+
34
+ cmd << " " << Escape.shell_command(instance_args)
35
+ end
36
+ end
37
+
38
+ private
39
+ def config
40
+ runner.config
41
+ end
42
+
43
+ def shell
44
+ runner.shell
45
+ end
46
+
47
+ def paths
48
+ runner.paths
49
+ end
50
+
51
+ def escaped_command(hook)
52
+ Escape.shell_command(command_for(hook))
53
+ end
54
+
55
+ def command_for(hook_name)
56
+ cmd = [
57
+ About.binary,
58
+ 'hook', hook_name.to_s,
59
+ '--app', config.app,
60
+ '--environment-name', config.environment_name,
61
+ '--account-name', config.account_name,
62
+ '--release-path', paths.active_release.to_s,
63
+ '--framework-env', config.framework_env.to_s
64
+ ]
65
+
66
+ cmd.push('--verbose') if config.verbose
67
+
68
+ cmd
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+ end
76
+