engineyard-serverside 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,77 +1,79 @@
1
1
  module EY
2
- class DeployHook < Task
3
- def initialize(options)
4
- super(EY::Deploy::Configuration.new(options))
5
- end
2
+ module Serverside
3
+ class DeployHook < Task
4
+ def initialize(options)
5
+ super(EY::Serverside::Deploy::Configuration.new(options))
6
+ end
6
7
 
7
- def callback_context
8
- @context ||= CallbackContext.new(config)
9
- end
8
+ def callback_context
9
+ @context ||= CallbackContext.new(config)
10
+ end
10
11
 
11
- def run(hook)
12
- hook_path = "#{c.release_path}/deploy/#{hook}.rb"
13
- if File.exist?(hook_path)
14
- Dir.chdir(c.release_path) do
15
- puts "~> running deploy hook: deploy/#{hook}.rb"
16
- if desc = syntax_error(hook_path)
17
- hook_name = File.basename(hook_path)
18
- abort "*** [Error] Invalid Ruby syntax in hook: #{hook_name} ***\n*** #{desc.chomp} ***"
19
- else
20
- callback_context.instance_eval(IO.read(hook_path))
12
+ def run(hook)
13
+ hook_path = "#{c.release_path}/deploy/#{hook}.rb"
14
+ if File.exist?(hook_path)
15
+ Dir.chdir(c.release_path) do
16
+ puts "~> running deploy hook: deploy/#{hook}.rb"
17
+ if desc = syntax_error(hook_path)
18
+ hook_name = File.basename(hook_path)
19
+ abort "*** [Error] Invalid Ruby syntax in hook: #{hook_name} ***\n*** #{desc.chomp} ***"
20
+ else
21
+ callback_context.instance_eval(IO.read(hook_path))
22
+ end
21
23
  end
22
24
  end
23
25
  end
24
- end
25
26
 
26
- def syntax_error(file)
27
- valid = Kernel.system("ruby -c #{file} 2>/tmp/ey_invalid_deploy_hook | grep 'Syntax OK' --quiet")
28
- File.new("/tmp/ey_invalid_deploy_hook").gets unless valid
29
- end
30
-
31
- class CallbackContext
32
- def initialize(config)
33
- @configuration = config
34
- @node = node
27
+ def syntax_error(file)
28
+ valid = Kernel.system("ruby -c #{file} 2>/tmp/ey_invalid_deploy_hook | grep 'Syntax OK' --quiet")
29
+ File.new("/tmp/ey_invalid_deploy_hook").gets unless valid
35
30
  end
36
31
 
37
- def method_missing(meth, *args, &blk)
38
- if @configuration.respond_to?(meth)
39
- @configuration.send(meth, *args, &blk)
40
- else
41
- super
32
+ class CallbackContext
33
+ def initialize(config)
34
+ @configuration = config
35
+ @node = node
42
36
  end
43
- end
44
37
 
45
- def respond_to?(meth, include_private=false)
46
- @configuration.respond_to?(meth, include_private) || super
47
- end
38
+ def method_missing(meth, *args, &blk)
39
+ if @configuration.respond_to?(meth)
40
+ @configuration.send(meth, *args, &blk)
41
+ else
42
+ super
43
+ end
44
+ end
48
45
 
49
- def run(cmd)
50
- system(Escape.shell_command(["sh", "-l", "-c", cmd]))
51
- end
46
+ def respond_to?(meth, include_private=false)
47
+ @configuration.respond_to?(meth, include_private) || super
48
+ end
52
49
 
53
- def sudo(cmd)
54
- system(Escape.shell_command(["sudo", "sh", "-l", "-c", cmd]))
55
- end
50
+ def run(cmd)
51
+ system(Escape.shell_command(["sh", "-l", "-c", cmd]))
52
+ end
53
+
54
+ def sudo(cmd)
55
+ system(Escape.shell_command(["sudo", "sh", "-l", "-c", cmd]))
56
+ end
56
57
 
57
- # convenience functions for running on certain instance types
58
- def on_app_master(&blk) on_roles(%w[solo app_master], &blk) end
59
- def on_app_servers(&blk) on_roles(%w[solo app_master app], &blk) end
60
- def on_app_servers_and_utilities(&blk) on_roles(%w[solo app_master app util], &blk) end
58
+ # convenience functions for running on certain instance types
59
+ def on_app_master(&blk) on_roles(%w[solo app_master], &blk) end
60
+ def on_app_servers(&blk) on_roles(%w[solo app_master app], &blk) end
61
+ def on_app_servers_and_utilities(&blk) on_roles(%w[solo app_master app util], &blk) end
61
62
 
62
- def on_utilities(*names, &blk)
63
- names.flatten!
64
- on_roles(%w[util]) do
65
- blk.call if names.empty? || names.include?(current_name)
63
+ def on_utilities(*names, &blk)
64
+ names.flatten!
65
+ on_roles(%w[util]) do
66
+ blk.call if names.empty? || names.include?(current_name)
67
+ end
68
+ end
69
+
70
+ private
71
+ def on_roles(desired_roles)
72
+ yield if desired_roles.any? { |role| current_roles.include?(role) }
66
73
  end
67
- end
68
74
 
69
- private
70
- def on_roles(desired_roles)
71
- yield if desired_roles.any? { |role| current_roles.include?(role) }
72
75
  end
73
76
 
74
77
  end
75
-
76
78
  end
77
79
  end
@@ -0,0 +1,27 @@
1
+ module EY
2
+ module Serverside
3
+ def self.deprecation_warning(msg)
4
+ STDERR.puts "DEPRECATION WARNING: #{msg}"
5
+ end
6
+ end
7
+
8
+ def self.const_missing(const)
9
+ if EY::Serverside.const_defined?(const)
10
+ EY::Serverside.deprecation_warning("EY::#{const} has been deprecated. use EY::Serverside::#{const} instead")
11
+ EY::Serverside.class_eval(const.to_s)
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ def self.node
18
+ EY::Serverside.deprecation_warning("EY.node has been deprecated. use EY::Serverside.node instead")
19
+ EY::Serverside.node
20
+ end
21
+
22
+ def self.dna_json
23
+ EY::Serverside.deprecation_warning("EY.dna_json has been deprecated. use EY::Serverside.dna_json instead")
24
+ EY::Serverside.dna_json
25
+ end
26
+
27
+ end
@@ -1,101 +1,103 @@
1
1
  require 'yaml'
2
2
  module EY
3
- class LockfileParser
3
+ module Serverside
4
+ class LockfileParser
4
5
 
5
- attr_reader :bundler_version, :lockfile_version
6
+ attr_reader :bundler_version, :lockfile_version
6
7
 
7
- def initialize(lockfile_contents)
8
- @lockfile_version, @bundler_version = Parse106.new(lockfile_contents).parse
9
- end
8
+ def initialize(lockfile_contents)
9
+ @lockfile_version, @bundler_version = Parse106.new(lockfile_contents).parse
10
+ end
10
11
 
11
- private
12
+ private
12
13
 
13
- class BaseParser
14
- def initialize(contents)
15
- @contents = contents
16
- end
17
- def parse
18
- raise "Unknown lockfile format #{@contents[0,50]}..."
14
+ class BaseParser
15
+ def initialize(contents)
16
+ @contents = contents
17
+ end
18
+ def parse
19
+ raise "Unknown lockfile format #{@contents[0,50]}..."
20
+ end
19
21
  end
20
- end
21
22
 
22
- class Parse09 < BaseParser
23
- def parse
24
- from_yaml = safe_yaml_load(@contents)
25
- unless from_yaml.is_a?(Hash)
26
- return super
27
- end
28
- bundler_version = from_yaml['specs'].map do |spec|
29
- # spec is a one-element hash: the key is the gem name, and
30
- # the value is {"version" => the-version}.
31
- if spec.keys.first == "bundler"
32
- spec.values.first["version"]
23
+ class Parse09 < BaseParser
24
+ def parse
25
+ from_yaml = safe_yaml_load(@contents)
26
+ unless from_yaml.is_a?(Hash)
27
+ return super
33
28
  end
34
- end.compact.first
35
- [:bundler09, bundler_version]
36
- end
37
- def safe_yaml_load(loadable)
38
- YAML.load(loadable) #won't always raise... soemtimes parses the contents as 1 big string
39
- rescue ArgumentError => e # not yaml
40
- nil
29
+ bundler_version = from_yaml['specs'].map do |spec|
30
+ # spec is a one-element hash: the key is the gem name, and
31
+ # the value is {"version" => the-version}.
32
+ if spec.keys.first == "bundler"
33
+ spec.values.first["version"]
34
+ end
35
+ end.compact.first
36
+ [:bundler09, bundler_version]
37
+ end
38
+ def safe_yaml_load(loadable)
39
+ YAML.load(loadable) #won't always raise... soemtimes parses the contents as 1 big string
40
+ rescue ArgumentError => e # not yaml
41
+ nil
42
+ end
41
43
  end
42
- end
43
44
 
44
- class Parse10 < Parse09
45
- def parse
46
- unless @contents.index(/^DEPENDENCIES/)
47
- return super
48
- end
49
- dep_section = ""
50
- in_dependencies_section = false
51
- @contents.each_line do |line|
52
- if line =~ /^DEPENDENCIES/
53
- in_dependencies_section = true
54
- elsif line =~ /^\S/
55
- in_dependencies_section = false
56
- elsif in_dependencies_section
57
- dep_section << line
45
+ class Parse10 < Parse09
46
+ def parse
47
+ unless @contents.index(/^DEPENDENCIES/)
48
+ return super
49
+ end
50
+ dep_section = ""
51
+ in_dependencies_section = false
52
+ @contents.each_line do |line|
53
+ if line =~ /^DEPENDENCIES/
54
+ in_dependencies_section = true
55
+ elsif line =~ /^\S/
56
+ in_dependencies_section = false
57
+ elsif in_dependencies_section
58
+ dep_section << line
59
+ end
58
60
  end
59
- end
60
61
 
61
- unless dep_section.length > 0
62
- raise "Couldn't parse #{@contents}; exiting"
63
- exit(1)
64
- end
62
+ unless dep_section.length > 0
63
+ raise "Couldn't parse #{@contents}; exiting"
64
+ exit(1)
65
+ end
65
66
 
66
- result = dep_section.scan(/^\s*bundler\s*\(=\s*([^\)]+)\)/).first
67
- bundler_version = result ? result.first : nil
68
- [:bundler10, bundler_version]
67
+ result = dep_section.scan(/^\s*bundler\s*\(=\s*([^\)]+)\)/).first
68
+ bundler_version = result ? result.first : nil
69
+ [:bundler10, bundler_version]
70
+ end
69
71
  end
70
- end
71
72
 
72
- class Parse106 < Parse10
73
- def parse
74
- unless @contents.index(/^METADATA/)
75
- return super
76
- end
77
- meta_section = ""
78
- in_meta_section = false
79
- @contents.each_line do |line|
80
- if line =~ /^METADATA/
81
- in_meta_section = true
82
- elsif line =~ /^\S/
83
- in_meta_section = false
84
- elsif in_meta_section
85
- meta_section << line
73
+ class Parse106 < Parse10
74
+ def parse
75
+ unless @contents.index(/^METADATA/)
76
+ return super
77
+ end
78
+ meta_section = ""
79
+ in_meta_section = false
80
+ @contents.each_line do |line|
81
+ if line =~ /^METADATA/
82
+ in_meta_section = true
83
+ elsif line =~ /^\S/
84
+ in_meta_section = false
85
+ elsif in_meta_section
86
+ meta_section << line
87
+ end
86
88
  end
87
- end
88
89
 
89
- unless meta_section.length > 0
90
- raise "Couldn't parse #{@contents}; exiting"
91
- exit(1)
92
- end
90
+ unless meta_section.length > 0
91
+ raise "Couldn't parse #{@contents}; exiting"
92
+ exit(1)
93
+ end
93
94
 
94
- result = meta_section.scan(/^\s*version:\s*(.*)$/).first
95
- bundler_version = result ? result.first : nil
96
- [:bundler10, bundler_version]
95
+ result = meta_section.scan(/^\s*version:\s*(.*)$/).first
96
+ bundler_version = result ? result.first : nil
97
+ [:bundler10, bundler_version]
98
+ end
97
99
  end
98
- end
99
100
 
101
+ end
100
102
  end
101
103
  end
@@ -1,78 +1,80 @@
1
1
  require 'open4'
2
2
 
3
3
  module EY
4
- module LoggedOutput
4
+ module Serverside
5
+ module LoggedOutput
5
6
 
6
- class Tee
7
- def initialize(*streams)
8
- @streams = streams.flatten
9
- end
7
+ class Tee
8
+ def initialize(*streams)
9
+ @streams = streams.flatten
10
+ end
10
11
 
11
- def <<(output)
12
- @streams.each do |s|
13
- s << output
14
- s.flush
12
+ def <<(output)
13
+ @streams.each do |s|
14
+ s << output
15
+ s.flush
16
+ end
17
+ self
15
18
  end
16
- self
17
- end
18
- end # Tee
19
+ end # Tee
19
20
 
20
- @@logfile = File.join(ENV['HOME'], 'ey.log')
21
- def self.logfile=(filename)
22
- File.unlink filename if File.exist?(filename) # start fresh
23
- @@logfile = filename
24
- end
21
+ @@logfile = File.join(ENV['HOME'], 'ey.log')
22
+ def self.logfile=(filename)
23
+ File.unlink filename if File.exist?(filename) # start fresh
24
+ @@logfile = filename
25
+ end
25
26
 
26
- def self.logfile
27
- @@logfile
28
- end
27
+ def self.logfile
28
+ @@logfile
29
+ end
29
30
 
30
- @@verbose = false
31
- def self.verbose=(v)
32
- @@verbose = !!v
33
- end
31
+ @@verbose = false
32
+ def self.verbose=(v)
33
+ @@verbose = !!v
34
+ end
34
35
 
35
- def self.verbose?
36
- @@verbose
37
- end
36
+ def self.verbose?
37
+ @@verbose
38
+ end
38
39
 
39
- def verbose?
40
- EY::LoggedOutput.verbose?
41
- end
40
+ def verbose?
41
+ EY::Serverside::LoggedOutput.verbose?
42
+ end
42
43
 
43
- def info(msg)
44
- with_logfile do |log|
45
- Tee.new($stdout, log) << (msg + "\n")
44
+ def info(msg)
45
+ with_logfile do |log|
46
+ Tee.new($stdout, log) << (msg + "\n")
47
+ end
46
48
  end
47
- end
48
49
 
49
- def debug(msg)
50
- with_logfile do |log|
51
- log << "#{msg}\n"
50
+ def debug(msg)
51
+ with_logfile do |log|
52
+ log << "#{msg}\n"
53
+ end
52
54
  end
53
- end
54
55
 
55
- def logged_system(cmd)
56
- with_logfile do |log|
57
- out = verbose? ? Tee.new($stdout, log) : log
58
- err = Tee.new($stderr, log) # we always want to see errors
56
+ def logged_system(cmd)
57
+ with_logfile do |log|
58
+ out = verbose? ? Tee.new($stdout, log) : log
59
+ err = Tee.new($stderr, log) # we always want to see errors
60
+
61
+ out << ":: running #{cmd}\n"
59
62
 
60
- out << ":: running #{cmd}\n"
63
+ # :quiet means don't raise an error on nonzero exit status
64
+ status = Open4.spawn cmd, 0 => '', 1 => out, 2 => err, :quiet => true
65
+ status.exitstatus == 0
66
+ end
67
+ end
61
68
 
62
- # :quiet means don't raise an error on nonzero exit status
63
- status = Open4.spawn cmd, 0 => '', 1 => out, 2 => err, :quiet => true
64
- status.exitstatus == 0
69
+ private
70
+ def with_logfile
71
+ File.open(logfile, 'a') {|f| yield f }
65
72
  end
66
- end
67
73
 
68
- private
69
- def with_logfile
70
- File.open(logfile, 'a') {|f| yield f }
71
- end
74
+ def logfile
75
+ EY::Serverside::LoggedOutput.logfile
76
+ end
72
77
 
73
- def logfile
74
- EY::LoggedOutput.logfile
75
78
  end
76
-
77
79
  end
78
80
  end