engineyard-serverside 2.6.19 → 2.7.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. data/lib/engineyard-serverside/callbacks.rb +11 -0
  2. data/lib/engineyard-serverside/callbacks/collection.rb +17 -0
  3. data/lib/engineyard-serverside/callbacks/collection/base.rb +94 -0
  4. data/lib/engineyard-serverside/callbacks/collection/combined.rb +45 -0
  5. data/lib/engineyard-serverside/callbacks/collection/deploy_hooks.rb +21 -0
  6. data/lib/engineyard-serverside/callbacks/collection/service_hooks.rb +17 -0
  7. data/lib/engineyard-serverside/callbacks/collection/service_hooks/collection.rb +24 -0
  8. data/lib/engineyard-serverside/callbacks/collection/service_hooks/combined.rb +40 -0
  9. data/lib/engineyard-serverside/callbacks/distributor.rb +23 -0
  10. data/lib/engineyard-serverside/callbacks/distributor/base.rb +38 -0
  11. data/lib/engineyard-serverside/callbacks/distributor/executable.rb +19 -0
  12. data/lib/engineyard-serverside/callbacks/distributor/executable/runnable.rb +41 -0
  13. data/lib/engineyard-serverside/callbacks/distributor/executable/unrunnable.rb +19 -0
  14. data/lib/engineyard-serverside/callbacks/distributor/ruby.rb +59 -0
  15. data/lib/engineyard-serverside/callbacks/distributor/ruby/distributor.rb +57 -0
  16. data/lib/engineyard-serverside/callbacks/hooks.rb +0 -0
  17. data/lib/engineyard-serverside/callbacks/hooks/app.rb +17 -0
  18. data/lib/engineyard-serverside/callbacks/hooks/base.rb +39 -0
  19. data/lib/engineyard-serverside/callbacks/hooks/service.rb +24 -0
  20. data/lib/engineyard-serverside/callbacks/service_hook.rb +20 -0
  21. data/lib/engineyard-serverside/deploy.rb +7 -45
  22. data/lib/engineyard-serverside/deploy_hook.rb +20 -83
  23. data/lib/engineyard-serverside/deploy_hook/callback_context.rb +77 -0
  24. data/lib/engineyard-serverside/paths.rb +9 -0
  25. data/lib/engineyard-serverside/version.rb +1 -1
  26. metadata +187 -193
  27. checksums.yaml +0 -7
@@ -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,94 @@
1
+ require 'engineyard-serverside/callbacks/distributor'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Callbacks
6
+ module Collection
7
+
8
+ # A base class for all Callback::Collection classes
9
+ class Base
10
+
11
+ # Load and return a callback collection
12
+ # @param paths (EY::Serverside::Paths) a paths object
13
+ def self.load(paths)
14
+ new(paths)
15
+ end
16
+
17
+ # Create a new collection instance
18
+ # @params paths (EY::Serverside::Paths) a paths object
19
+ def initialize(paths)
20
+ @paths = paths
21
+ load_hooks
22
+ end
23
+
24
+ # Get all of the hooks in the collection
25
+ # @return [Array<EY::Serverside::Callbacks::Hooks::Base>]
26
+ # the hooks tracked by the collection
27
+ def all
28
+ hooks
29
+ end
30
+
31
+ # Given a callback name (ie `before_bundle`), get all of the hooks
32
+ # that match said callback name, favoring ruby-flavored hooks when
33
+ # both ruby-flavored and executable-flavored hooks are present for a
34
+ # given context.
35
+ # @param callback (Symbol) the desired callback name
36
+ # @return [Array<EY::Serverside::Callbacks::Hooks::Base>]
37
+ # the tracked hooks for the given callback name
38
+ def matching(callback)
39
+ favor(
40
+ :ruby,
41
+ all.select {|hook| hook.matches?(callback.to_sym)}
42
+ )
43
+ end
44
+
45
+ # Given a runner and a callback name, distribute the invocation of
46
+ # the matching hooks via the runner. Due to the nature of ruby-
47
+ # flavored hooks, if there is more than one ruby-flavored hook in the
48
+ # list of hooks that match the desired callback, only one of them
49
+ # is actually distributed.
50
+ # @param runner (EY::Serverside::DeployBase) the runner with which to
51
+ # distribute the matching hooks
52
+ # @param callback (Symbol) the desired callback name
53
+ def distribute(runner, callback)
54
+ Distributor.distribute(
55
+ runner,
56
+ minimize_ruby(
57
+ matching(callback)
58
+ )
59
+ )
60
+ end
61
+
62
+ private
63
+ def favor(flavor, hooks)
64
+ (
65
+ hooks.select {|hook| hook.flavor == flavor} +
66
+ hooks.reject {|hook| hook.flavor == flavor}
67
+ ).first(1)
68
+ end
69
+
70
+ def minimize_ruby(hooks)
71
+ first_ruby = hooks.select {|hook| hook.flavor == :ruby}.first
72
+
73
+ return hooks unless first_ruby
74
+
75
+ ([first_ruby] + hooks.select {|hook| hook.flavor != :ruby}).flatten
76
+ end
77
+
78
+ def load_hooks
79
+ raise "Unimplemented"
80
+ end
81
+
82
+ def paths
83
+ @paths
84
+ end
85
+
86
+ def hooks
87
+ @hooks ||= []
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
94
+ 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,23 @@
1
+ require 'engineyard-serverside/callbacks/distributor/ruby'
2
+ require 'engineyard-serverside/callbacks/distributor/executable'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Callbacks
7
+
8
+ module Distributor
9
+ FLAVORS = {
10
+ :ruby => Ruby,
11
+ :executable => Executable,
12
+ }
13
+
14
+ def self.distribute(runner, hooks)
15
+ hooks.each do |hook|
16
+ FLAVORS[hook.flavor].distribute(runner, hook)
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ module EY
2
+ module Serverside
3
+ module Callbacks
4
+ module Distributor
5
+
6
+ class Base
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
+ raise 'Unimplemented Hook Distributor!'
20
+ end
21
+
22
+ def config
23
+ runner.config
24
+ end
25
+
26
+ def shell
27
+ runner.shell
28
+ end
29
+
30
+ def paths
31
+ runner.paths
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ require 'engineyard-serverside/callbacks/distributor/executable/runnable'
2
+ require 'engineyard-serverside/callbacks/distributor/executable/unrunnable'
3
+
4
+ module EY
5
+ module Serverside
6
+ module Callbacks
7
+ module Distributor
8
+
9
+ module Executable
10
+ def self.distribute(runner, hook)
11
+ (hook.path.executable? ? Runnable : Unrunnable).
12
+ distribute(runner, hook)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ require 'engineyard-serverside/callbacks/distributor/base'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Callbacks
6
+ module Distributor
7
+ module Executable
8
+
9
+ class Runnable < Base
10
+ def distribute
11
+ shell.status "Running deploy hook: #{hook}"
12
+
13
+ runner.run [About.hook_executor, hook.callback_name].join(' ') do |server, cmd|
14
+ cmd = hook_env_vars(server).
15
+ reject {|name,value| value.nil?}.
16
+ map {|name,value| "#{name}=#{Escape.shell_command([value])}"}.
17
+ join(' ') + ' ' + config.framework_envs + ' ' + cmd
18
+ end
19
+ end
20
+
21
+ private
22
+ def hook_env_vars(server)
23
+ {
24
+ 'EY_DEPLOY_ACCOUNT_NAME' => config.account_name,
25
+ 'EY_DEPLOY_APP' => config.app,
26
+ 'EY_DEPLOY_CONFIG' => config.to_json,
27
+ 'EY_DEPLOY_CURRENT_ROLES' => server.roles.to_a.join(' '),
28
+ 'EY_DEPLOY_CURRENT_NAME' => server.name ? server.name.to_s : nil,
29
+ 'EY_DEPLOY_ENVIRONMENT_NAME' => config.environment_name,
30
+ 'EY_DEPLOY_FRAMEWORK_ENV' => config.framework_env.to_s,
31
+ 'EY_DEPLOY_RELEASE_PATH' => paths.active_release.to_s,
32
+ 'EY_DEPLOY_VERBOSE' => (config.verbose ? '1' : '0'),
33
+ }
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ require 'engineyard-serverside/callbacks/distributor/base'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Callbacks
6
+ module Distributor
7
+ module Executable
8
+
9
+ class Unrunnable < Base
10
+ def distribute
11
+ shell.warning "Skipping possible deploy hook #{hook} because it is not executable."
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ require 'engineyard-serverside/callbacks/distributor/base'
2
+
3
+ module EY
4
+ module Serverside
5
+ module Callbacks
6
+ module Distributor
7
+
8
+ class Ruby < Base
9
+ def self.distribute(runner, hook)
10
+ new(runner, hook).distribute
11
+ end
12
+
13
+ def distribute
14
+ shell.status "Running deploy hook: #{hook}.rb"
15
+
16
+ runner.run escaped_command(hook) do |server, cmd|
17
+ instance_args = [
18
+ '--current-roles', server.roles.to_a.join(' ')
19
+ ]
20
+
21
+ if server.name
22
+ instance_args.push('--current-name')
23
+ instance_args.push(server.name.to_s)
24
+ end
25
+
26
+ instance_args.push('--config')
27
+ instance_args.push(config.to_json)
28
+
29
+ cmd << " " << Escape.shell_command(instance_args)
30
+ end
31
+ end
32
+
33
+ private
34
+ def escaped_command(hook)
35
+ Escape.shell_command(command_for(hook.callback_name))
36
+ end
37
+
38
+ def command_for(hook_name)
39
+ cmd = [
40
+ About.binary,
41
+ 'hook', hook_name.to_s,
42
+ '--app', config.app,
43
+ '--environment-name', config.environment_name,
44
+ '--account-name', config.account_name,
45
+ '--release-path', paths.active_release.to_s,
46
+ '--framework-env', config.framework_env.to_s
47
+ ]
48
+
49
+ cmd.push('--verbose') if config.verbose
50
+
51
+ cmd
52
+ end
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ end
59
+