simple_deploy 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/CHANGELOG +13 -0
  2. data/lib/simple_deploy/cli/attributes.rb +13 -4
  3. data/lib/simple_deploy/cli/clone.rb +18 -7
  4. data/lib/simple_deploy/cli/create.rb +24 -12
  5. data/lib/simple_deploy/cli/deploy.rb +36 -14
  6. data/lib/simple_deploy/cli/destroy.rb +20 -13
  7. data/lib/simple_deploy/cli/environments.rb +32 -0
  8. data/lib/simple_deploy/cli/events.rb +23 -9
  9. data/lib/simple_deploy/cli/execute.rb +27 -11
  10. data/lib/simple_deploy/cli/instances.rb +22 -11
  11. data/lib/simple_deploy/cli/list.rb +17 -21
  12. data/lib/simple_deploy/cli/outputs.rb +26 -13
  13. data/lib/simple_deploy/cli/parameters.rb +22 -9
  14. data/lib/simple_deploy/cli/protect.rb +22 -9
  15. data/lib/simple_deploy/cli/resources.rb +24 -10
  16. data/lib/simple_deploy/cli/shared.rb +17 -7
  17. data/lib/simple_deploy/cli/status.rb +22 -9
  18. data/lib/simple_deploy/cli/template.rb +22 -9
  19. data/lib/simple_deploy/cli/update.rb +23 -11
  20. data/lib/simple_deploy/cli.rb +30 -6
  21. data/lib/simple_deploy/exceptions.rb +13 -0
  22. data/lib/simple_deploy/stack/ssh.rb +1 -3
  23. data/lib/simple_deploy/stack.rb +7 -4
  24. data/lib/simple_deploy/version.rb +1 -1
  25. data/lib/simple_deploy.rb +1 -0
  26. data/simple_deploy.gemspec +1 -1
  27. data/spec/cli/attributes_spec.rb +8 -8
  28. data/spec/cli/clone_spec.rb +6 -6
  29. data/spec/cli/deploy_spec.rb +20 -16
  30. data/spec/cli/destroy_spec.rb +6 -6
  31. data/spec/cli/protect_spec.rb +15 -15
  32. data/spec/cli/shared_spec.rb +76 -0
  33. data/spec/cli/update_spec.rb +8 -6
  34. data/spec/stack/ssh_spec.rb +2 -5
  35. data/spec/stack_spec.rb +26 -12
  36. metadata +21 -18
  37. data/lib/simple_deploy/cli/ssh.rb +0 -39
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Parameters
7
+ include Shared
8
+
6
9
  def show
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -20,20 +23,30 @@ EOS
20
23
  opt :name, "Stack name to manage", :type => :string
21
24
  end
22
25
 
23
- CLI::Shared.valid_options? :provided => opts,
24
- :required => [:environment, :name]
25
-
26
- config = Config.new.environment opts[:environment]
26
+ valid_options? :provided => @opts,
27
+ :required => [:environment, :name]
27
28
 
28
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
29
+ config = Config.new.environment @opts[:environment]
29
30
 
30
- stack = Stack.new :environment => opts[:environment],
31
- :name => opts[:name],
31
+ stack = Stack.new :environment => @opts[:environment],
32
+ :name => @opts[:name],
32
33
  :config => config,
33
34
  :logger => logger
34
35
 
35
- jj stack.parameters
36
+ rescue_stackster_exceptions_and_exit do
37
+ puts stack.parameters.sort
38
+ end
39
+ end
40
+
41
+ def logger
42
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
43
+ end
44
+
45
+ def command_summary
46
+ 'Show parameters of a stack'
36
47
  end
48
+
37
49
  end
50
+
38
51
  end
39
52
  end
@@ -3,9 +3,12 @@ require 'trollop'
3
3
 
4
4
  module SimpleDeploy
5
5
  module CLI
6
+
6
7
  class Protect
8
+ include Shared
9
+
7
10
  def protect
8
- opts = Trollop::options do
11
+ @opts = Trollop::options do
9
12
  version SimpleDeploy::VERSION
10
13
  banner <<-EOS
11
14
 
@@ -23,21 +26,31 @@ EOS
23
26
  :multi => true
24
27
  end
25
28
 
26
- CLI::Shared.valid_options? :provided => opts,
27
- :required => [:environment, :name]
28
-
29
- config = Config.new.environment opts[:environment]
29
+ valid_options? :provided => @opts,
30
+ :required => [:environment, :name]
30
31
 
31
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
32
+ config = Config.new.environment @opts[:environment]
32
33
 
33
- opts[:name].each do |name|
34
- stack = Stack.new :environment => opts[:environment],
34
+ @opts[:name].each do |name|
35
+ stack = Stack.new :environment => @opts[:environment],
35
36
  :name => name,
36
37
  :config => config,
37
38
  :logger => logger
38
- stack.update :attributes => [{ 'protection' => opts[:protection] }]
39
+ rescue_stackster_exceptions_and_exit do
40
+ stack.update :attributes => [{ 'protection' => @opts[:protection] }]
41
+ end
39
42
  end
40
43
  end
44
+
45
+ def logger
46
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
47
+ end
48
+
49
+ def command_summary
50
+ 'Protect/Unprotect one or more stacks'
51
+ end
52
+
41
53
  end
54
+
42
55
  end
43
56
  end
@@ -2,9 +2,13 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Resources
7
+
8
+ include Shared
9
+
6
10
  def show
7
- opts = Trollop::options do
11
+ @opts = Trollop::options do
8
12
  version SimpleDeploy::VERSION
9
13
  banner <<-EOS
10
14
 
@@ -16,24 +20,34 @@ EOS
16
20
  opt :help, "Display Help"
17
21
  opt :environment, "Set the target environment", :type => :string
18
22
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
19
- :default => 'warn'
23
+ :default => 'info'
20
24
  opt :name, "Stack name to manage", :type => :string
21
25
  end
22
26
 
23
- CLI::Shared.valid_options? :provided => opts,
24
- :required => [:environment, :name]
27
+ valid_options? :provided => @opts,
28
+ :required => [:environment, :name]
25
29
 
26
- config = Config.new.environment opts[:environment]
30
+ config = Config.new.environment @opts[:environment]
27
31
 
28
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
29
-
30
- stack = Stack.new :environment => opts[:environment],
31
- :name => opts[:name],
32
+ stack = Stack.new :environment => @opts[:environment],
33
+ :name => @opts[:name],
32
34
  :config => config,
33
35
  :logger => logger
34
36
 
35
- jj stack.resources
37
+ rescue_stackster_exceptions_and_exit do
38
+ jj stack.resources
39
+ end
36
40
  end
41
+
42
+ def logger
43
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
44
+ end
45
+
46
+ def command_summary
47
+ 'Show resources of a stack'
48
+ end
49
+
37
50
  end
51
+
38
52
  end
39
53
  end
@@ -1,14 +1,14 @@
1
1
  module SimpleDeploy
2
2
  module CLI
3
+
3
4
  module Shared
4
5
 
5
- def self.parse_attributes(args)
6
+ def parse_attributes(args)
6
7
  attributes = args[:attributes]
7
- logger = args[:logger]
8
+ attrs = []
8
9
 
9
- attrs = []
10
10
  attributes.each do |attribs|
11
- key = attribs.split('=').first.gsub(/\s+/, "")
11
+ key = attribs.split('=').first.gsub(/\s+/, "")
12
12
  value = attribs.gsub(/^.+?=/, '')
13
13
  logger.info "Read #{key}=#{value}"
14
14
  attrs << { key => value }
@@ -16,26 +16,36 @@ module SimpleDeploy
16
16
  attrs
17
17
  end
18
18
 
19
- def self.valid_options?(args)
19
+ def valid_options?(args)
20
20
  provided = args[:provided]
21
21
  required = args[:required]
22
22
 
23
23
  required.each do |opt|
24
24
  unless provided[opt]
25
- puts "Option '#{opt} (-#{opt[0]})' required but not specified."
25
+ logger.error "Option '#{opt} (-#{opt[0]})' required but not specified."
26
26
  exit 1
27
27
  end
28
28
  end
29
29
 
30
30
  if required.include? :environment
31
31
  unless Config.new.environments.keys.include? provided[:environment]
32
- puts "Environment '#{provided[:environment]}' does not exist."
32
+ logger.error "Environment '#{provided[:environment]}' does not exist."
33
33
  exit 1
34
34
  end
35
35
  end
36
+ end
36
37
 
38
+ def command_name
39
+ self.class.name.split('::').last.downcase
40
+ end
41
+
42
+ def rescue_stackster_exceptions_and_exit
43
+ yield
44
+ rescue Stackster::Exceptions::Base
45
+ exit 1
37
46
  end
38
47
 
39
48
  end
49
+
40
50
  end
41
51
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Status
7
+ include Shared
8
+
6
9
  def show
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -18,20 +21,30 @@ EOS
18
21
  opt :name, "Stack name to manage", :type => :string
19
22
  end
20
23
 
21
- CLI::Shared.valid_options? :provided => opts,
22
- :required => [:environment, :name]
23
-
24
- config = Config.new.environment opts[:environment]
24
+ valid_options? :provided => @opts,
25
+ :required => [:environment, :name]
25
26
 
26
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
27
+ config = Config.new.environment @opts[:environment]
27
28
 
28
- stack = Stack.new :environment => opts[:environment],
29
- :name => opts[:name],
29
+ stack = Stack.new :environment => @opts[:environment],
30
+ :name => @opts[:name],
30
31
  :config => config,
31
32
  :logger => logger
32
33
 
33
- puts stack.status
34
+ rescue_stackster_exceptions_and_exit do
35
+ puts stack.status
36
+ end
37
+ end
38
+
39
+ def logger
40
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
41
+ end
42
+
43
+ def command_summary
44
+ 'Show status of a stack'
34
45
  end
46
+
35
47
  end
48
+
36
49
  end
37
50
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Template
7
+ include Shared
8
+
6
9
  def show
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -18,20 +21,30 @@ EOS
18
21
  opt :name, "Stack name to manage", :type => :string
19
22
  end
20
23
 
21
- CLI::Shared.valid_options? :provided => opts,
22
- :required => [:environment, :name]
23
-
24
- config = Config.new.environment opts[:environment]
24
+ valid_options? :provided => @opts,
25
+ :required => [:environment, :name]
25
26
 
26
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
27
+ config = Config.new.environment @opts[:environment]
27
28
 
28
- stack = Stack.new :environment => opts[:environment],
29
- :name => opts[:name],
29
+ stack = Stack.new :environment => @opts[:environment],
30
+ :name => @opts[:name],
30
31
  :config => config,
31
32
  :logger => logger
32
33
 
33
- jj stack.template
34
+ rescue_stackster_exceptions_and_exit do
35
+ jj stack.template
36
+ end
37
+ end
38
+
39
+ def logger
40
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
41
+ end
42
+
43
+ def command_summary
44
+ 'Show current template for stack'
34
45
  end
46
+
35
47
  end
48
+
36
49
  end
37
50
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Update
7
+ include Shared
8
+
6
9
  def update
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -24,24 +27,33 @@ EOS
24
27
  :multi => true
25
28
  end
26
29
 
27
- CLI::Shared.valid_options? :provided => opts,
28
- :required => [:environment, :name]
29
-
30
- config = Config.new.environment opts[:environment]
30
+ valid_options? :provided => @opts,
31
+ :required => [:environment, :name]
31
32
 
32
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
33
+ config = Config.new.environment @opts[:environment]
33
34
 
34
- attributes = CLI::Shared.parse_attributes :attributes => opts[:attributes],
35
- :logger => logger
35
+ attributes = parse_attributes :attributes => @opts[:attributes]
36
36
 
37
- opts[:name].each do |name|
38
- stack = Stack.new :environment => opts[:environment],
37
+ @opts[:name].each do |name|
38
+ stack = Stack.new :environment => @opts[:environment],
39
39
  :name => name,
40
40
  :config => config,
41
41
  :logger => logger
42
- stack.update :force => opts[:force], :attributes => attributes
42
+ rescue_stackster_exceptions_and_exit do
43
+ stack.update :force => @opts[:force], :attributes => attributes
44
+ end
43
45
  end
44
46
  end
47
+
48
+ def logger
49
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
50
+ end
51
+
52
+ def command_summary
53
+ 'Update the attributes for one more stacks'
54
+ end
55
+
45
56
  end
57
+
46
58
  end
47
59
  end
@@ -7,6 +7,7 @@ require 'simple_deploy/cli/clone'
7
7
  require 'simple_deploy/cli/create'
8
8
  require 'simple_deploy/cli/deploy'
9
9
  require 'simple_deploy/cli/destroy'
10
+ require 'simple_deploy/cli/environments'
10
11
  require 'simple_deploy/cli/events'
11
12
  require 'simple_deploy/cli/execute'
12
13
  require 'simple_deploy/cli/instances'
@@ -15,13 +16,13 @@ require 'simple_deploy/cli/outputs'
15
16
  require 'simple_deploy/cli/parameters'
16
17
  require 'simple_deploy/cli/protect'
17
18
  require 'simple_deploy/cli/resources'
18
- require 'simple_deploy/cli/ssh'
19
19
  require 'simple_deploy/cli/status'
20
20
  require 'simple_deploy/cli/template'
21
21
  require 'simple_deploy/cli/update'
22
22
 
23
23
  module SimpleDeploy
24
24
  module CLI
25
+
25
26
  def self.start
26
27
  cmd = ARGV.shift
27
28
 
@@ -37,7 +38,7 @@ module SimpleDeploy
37
38
  when 'deploy'
38
39
  CLI::Deploy.new.deploy
39
40
  when 'environments'
40
- CLI::List.new.environments
41
+ CLI::Environments.new.environments
41
42
  when 'events'
42
43
  CLI::Events.new.show
43
44
  when 'execute'
@@ -63,17 +64,40 @@ module SimpleDeploy
63
64
  when 'update'
64
65
  CLI::Update.new.update
65
66
  when '-h'
66
- puts "simple_deploy [attributes|clone|create|deploy|destroy|environments|events|execute|instances|list|outputs|parameters|protect|resources|ssh|status|template|update] [options]"
67
- puts "Append -h for help on specific subcommand."
67
+ usage
68
68
  when '-v'
69
69
  puts SimpleDeploy::VERSION
70
70
  else
71
71
  puts "Unknown command: '#{cmd}'."
72
- puts "simple_deploy [attributes|clone|create|deploy|destroy|environments|events|execute|instances|list|outputs|parameters|protect|resources|ssh|status|template|update] [options]"
73
- puts "Append -h for help on specific subcommand."
72
+ puts ''
73
+ usage
74
74
  exit 1
75
75
  end
76
76
  end
77
77
 
78
+ def self.usage
79
+ puts 'Usage: simple_deploy command'
80
+ puts ''
81
+ puts 'Append -h for help on specific subcommand.'
82
+ puts ''
83
+
84
+ puts 'Commands:'
85
+ commands.each do |cmd|
86
+ $stdout.printf " %-#{length_of_longest_command}s %s\n",
87
+ cmd.command_name,
88
+ cmd.command_summary
89
+ end
90
+ end
91
+
92
+ def self.commands
93
+ return @commands if @commands
94
+ klasses = SimpleDeploy::CLI.constants.reject { |c| c == :Shared }
95
+ @commands = klasses.map { |klass| SimpleDeploy::CLI.const_get(klass).new }
96
+ end
97
+
98
+ def self.length_of_longest_command
99
+ commands.map { |c| c.command_name.length }.max
100
+ end
101
+
78
102
  end
79
103
  end
@@ -0,0 +1,13 @@
1
+ module SimpleDeploy
2
+ module Exceptions
3
+
4
+ class Base < RuntimeError
5
+ attr_accessor :message
6
+
7
+ def initialize(message="")
8
+ @message = message
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -18,6 +18,7 @@ module SimpleDeploy
18
18
  end
19
19
 
20
20
  def execute(args)
21
+ return false if @instances.nil? || @instances.empty?
21
22
  create_execute_task args
22
23
  @task.execute
23
24
  end
@@ -25,9 +26,6 @@ module SimpleDeploy
25
26
  private
26
27
 
27
28
  def create_execute_task(args)
28
- if @instances.nil? || @instances.empty?
29
- raise "There are no running instances to execute this command."
30
- end
31
29
 
32
30
  @task = Capistrano::Configuration.new :output => @logger
33
31
  @task.logger.level = 3
@@ -87,13 +87,17 @@ module SimpleDeploy
87
87
  info['ipAddress']
88
88
  end
89
89
  end
90
- end.flatten
90
+ end.flatten.compact
91
91
  end
92
92
 
93
93
  def status
94
94
  stack.status
95
95
  end
96
96
 
97
+ def wait_for_stable
98
+ stack.wait_for_stable
99
+ end
100
+
97
101
  def exists?
98
102
  stack.status
99
103
  true
@@ -112,13 +116,12 @@ module SimpleDeploy
112
116
  def template
113
117
  JSON.parse stack.template
114
118
  end
115
-
119
+
116
120
  private
117
121
 
118
122
  def stack
119
123
  stackster_config = @config.environment @environment
120
- @stack ||= Stackster::Stack.new :environment => @environment,
121
- :name => @name,
124
+ @stack ||= Stackster::Stack.new :name => @name,
122
125
  :config => stackster_config,
123
126
  :logger => @logger
124
127
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleDeploy
2
- VERSION = "0.6.4"
2
+ VERSION = "0.6.5"
3
3
  end
data/lib/simple_deploy.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'simple_deploy/env'
2
+ require 'simple_deploy/exceptions'
2
3
  require 'simple_deploy/config'
3
4
  require 'simple_deploy/artifact'
4
5
  require 'simple_deploy/stack'
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec", "~> 2.11.0"
23
23
 
24
24
  s.add_runtime_dependency "capistrano", "= 2.13.5"
25
- s.add_runtime_dependency "stackster", '= 0.4.0'
25
+ s.add_runtime_dependency "stackster", '= 0.4.1'
26
26
  s.add_runtime_dependency "tinder", "= 1.9.1"
27
27
  s.add_runtime_dependency "trollop", "= 2.0"
28
28
  end
@@ -26,12 +26,12 @@ describe SimpleDeploy::CLI::Attributes do
26
26
  end
27
27
 
28
28
  it 'should output the attributes' do
29
- SimpleDeploy::CLI::Shared.should_receive(:valid_options?).
30
- with(:provided => @options,
31
- :required => [:environment, :name])
29
+ subject.should_receive(:valid_options?).
30
+ with(:provided => @options,
31
+ :required => [:environment, :name])
32
32
  Trollop.stub(:options).and_return(@options)
33
- subject.should_receive(:puts).with("foo=bar")
34
- subject.should_receive(:puts).with("baz=blah")
33
+ subject.should_receive(:puts).with('foo: bar')
34
+ subject.should_receive(:puts).with('baz: blah')
35
35
  subject.show
36
36
  end
37
37
 
@@ -39,9 +39,9 @@ describe SimpleDeploy::CLI::Attributes do
39
39
  before do
40
40
  @options[:as_command_args] = true
41
41
  Trollop.stub(:options).and_return(@options)
42
- SimpleDeploy::CLI::Shared.should_receive(:valid_options?).
43
- with(:provided => @options,
44
- :required => [:environment, :name])
42
+ subject.should_receive(:valid_options?).
43
+ with(:provided => @options,
44
+ :required => [:environment, :name])
45
45
  end
46
46
 
47
47
  it 'should output the attributes as command arguments' do
@@ -159,9 +159,9 @@ describe SimpleDeploy::CLI::Clone do
159
159
  end
160
160
 
161
161
  it 'should create the new stack using the filtered, merged and added attributes' do
162
- SimpleDeploy::CLI::Shared.should_receive(:valid_options?).
163
- with(:provided => @options,
164
- :required => [:environment, :source_name, :new_name])
162
+ subject.should_receive(:valid_options?).
163
+ with(:provided => @options,
164
+ :required => [:environment, :source_name, :new_name])
165
165
  Trollop.stub(:options).and_return(@options)
166
166
 
167
167
  @new_stack.should_receive(:create) do |options|
@@ -181,9 +181,9 @@ describe SimpleDeploy::CLI::Clone do
181
181
  it 'should create the new stack using a new template' do
182
182
  @options[:template] = 'brand_new_template.json'
183
183
 
184
- SimpleDeploy::CLI::Shared.should_receive(:valid_options?).
185
- with(:provided => @options,
186
- :required => [:environment, :source_name, :new_name])
184
+ subject.should_receive(:valid_options?).
185
+ with(:provided => @options,
186
+ :required => [:environment, :source_name, :new_name])
187
187
  Trollop.stub(:options).and_return(@options)
188
188
 
189
189
  @new_stack.should_receive(:create) do |options|