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
data/CHANGELOG CHANGED
@@ -1,3 +1,16 @@
1
+ ## v0.6.5:
2
+
3
+ * Fixed instances command handling of nil IP addresses
4
+ * Upgraded to stackster 0.4.1
5
+ * Remove 'ssh' command
6
+ * Update output format for 'attributes', 'instances', 'parameters' commands
7
+ * Update help output
8
+ * Minor internal cli refactor
9
+ * Removed unused env argument passed into Stackster::Stack
10
+ * Added log_level to clone cli class
11
+ * Catching stackster exceptions in CLI
12
+ * Refactored shared specs
13
+
1
14
  ## v0.6.4:
2
15
 
3
16
  * Check for artifact encryption via attribute name_encrypted (where name is name of archive)
@@ -4,6 +4,8 @@ module SimpleDeploy
4
4
  module CLI
5
5
 
6
6
  class Attributes
7
+ include Shared
8
+
7
9
  def show
8
10
  @opts = Trollop::options do
9
11
  version SimpleDeploy::VERSION
@@ -23,15 +25,22 @@ EOS
23
25
  opt :name, "Stack name to manage", :type => :string
24
26
  end
25
27
 
26
- CLI::Shared.valid_options? :provided => @opts,
27
- :required => [:environment, :name]
28
+ valid_options? :provided => @opts,
29
+ :required => [:environment, :name]
28
30
 
29
31
  @opts[:as_command_args] ? command_args_output : default_output
30
32
  end
31
33
 
34
+ def command_summary
35
+ 'Show attributes for stack'
36
+ end
37
+
32
38
  private
39
+
33
40
  def attribute_data
34
- Hash[stack.attributes.sort]
41
+ rescue_stackster_exceptions_and_exit do
42
+ Hash[stack.attributes.sort]
43
+ end
35
44
  end
36
45
 
37
46
  def command_args_output
@@ -43,7 +52,7 @@ EOS
43
52
  end
44
53
 
45
54
  def default_output
46
- attribute_data.each_pair { |k, v| puts "#{k}=#{v}" }
55
+ attribute_data.each_pair { |k, v| puts "#{k}: #{v}" }
47
56
  end
48
57
 
49
58
  def logger
@@ -3,7 +3,10 @@ require 'tempfile'
3
3
 
4
4
  module SimpleDeploy
5
5
  module CLI
6
+
6
7
  class Clone
8
+ include Shared
9
+
7
10
  def clone
8
11
  @opts = Trollop::options do
9
12
  version SimpleDeploy::VERSION
@@ -16,6 +19,8 @@ simple_deploy clone -s SOURCE_STACK_NAME -n NEW_STACK_NAME -e ENVIRONMENT -a ATT
16
19
  EOS
17
20
  opt :help, "Display Help"
18
21
  opt :environment, "Set the target environment", :type => :string
22
+ opt :log_level, "Log level: debug, info, warn, error", :type => :string,
23
+ :default => 'info'
19
24
  opt :source_name, "Stack name for the stack to clone", :type => :string
20
25
  opt :new_name, "Stack name for the new stack", :type => :string
21
26
  opt :attributes, "= separated attribute and it's value", :type => :string,
@@ -23,11 +28,10 @@ EOS
23
28
  opt :template, "Path to a new template file", :type => :string
24
29
  end
25
30
 
26
- CLI::Shared.valid_options? :provided => @opts,
27
- :required => [:environment, :source_name, :new_name]
31
+ valid_options? :provided => @opts,
32
+ :required => [:environment, :source_name, :new_name]
28
33
 
29
- override_attributes = CLI::Shared.parse_attributes :attributes => @opts[:attributes],
30
- :logger => logger
34
+ override_attributes = parse_attributes :attributes => @opts[:attributes]
31
35
 
32
36
  cloned_attributes = filter_attributes source_stack.attributes
33
37
  new_attributes = merge_attributes cloned_attributes, override_attributes
@@ -40,12 +44,17 @@ EOS
40
44
  File::open(template_file, 'w') { |f| f.write source_stack.template.to_json }
41
45
  end
42
46
 
43
- new_stack.create :attributes => new_attributes,
44
- :template => template_file
47
+ rescue_stackster_exceptions_and_exit do
48
+ new_stack.create :attributes => new_attributes,
49
+ :template => template_file
50
+ end
45
51
  end
46
52
 
47
- private
53
+ def command_summary
54
+ 'Clone a stack'
55
+ end
48
56
 
57
+ private
49
58
  def filter_attributes(source_attributes)
50
59
  selected = source_attributes.select { |k| k !~ /^deployment/ }
51
60
  selected.map { |k,v| { k => v } }
@@ -88,6 +97,8 @@ EOS
88
97
  :config => config,
89
98
  :logger => logger
90
99
  end
100
+
91
101
  end
102
+
92
103
  end
93
104
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Create
7
+ include Shared
8
+
6
9
  def create
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -23,24 +26,33 @@ EOS
23
26
  opt :template, "Path to the template file", :type => :string
24
27
  end
25
28
 
26
- CLI::Shared.valid_options? :provided => opts,
27
- :required => [:environment, :name, :template]
28
-
29
- config = Config.new.environment opts[:environment]
29
+ valid_options? :provided => @opts,
30
+ :required => [:environment, :name, :template]
30
31
 
31
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
32
+ config = Config.new.environment @opts[:environment]
32
33
 
33
- attributes = CLI::Shared.parse_attributes :attributes => opts[:attributes],
34
- :logger => logger
34
+ attributes = parse_attributes :attributes => @opts[:attributes]
35
35
 
36
- stack = Stack.new :environment => opts[:environment],
37
- :name => opts[:name],
36
+ stack = Stack.new :environment => @opts[:environment],
37
+ :name => @opts[:name],
38
38
  :config => config,
39
39
  :logger => logger
40
40
 
41
- stack.create :attributes => attributes,
42
- :template => opts[:template]
41
+ rescue_stackster_exceptions_and_exit do
42
+ stack.create :attributes => attributes,
43
+ :template => @opts[:template]
44
+ end
45
+ end
46
+
47
+ def logger
48
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
49
+ end
50
+
51
+ def command_summary
52
+ 'Create a new stack'
43
53
  end
54
+
44
55
  end
56
+
45
57
  end
46
58
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Deploy
7
+ include Shared
8
+
6
9
  def deploy
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -48,30 +51,39 @@ EOS
48
51
  opt :internal, "Use internal IP for ssh commands"
49
52
  end
50
53
 
51
- CLI::Shared.valid_options? :provided => opts,
52
- :required => [:environment, :name]
54
+ valid_options? :provided => @opts,
55
+ :required => [:environment, :name]
53
56
 
54
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
57
+ new_attributes = parse_attributes :attributes => @opts[:attributes]
55
58
 
56
- new_attributes = CLI::Shared.parse_attributes :attributes => opts[:attributes],
57
- :logger => logger
58
- opts[:name].each do |name|
59
+ @opts[:name].each do |name|
59
60
  notifier = Notifier.new :stack_name => name,
60
- :environment => opts[:environment],
61
+ :environment => @opts[:environment],
61
62
  :logger => logger
62
63
 
63
- stack = Stack.new :environment => opts[:environment],
64
+ stack = Stack.new :environment => @opts[:environment],
64
65
  :name => name,
65
66
  :logger => logger,
66
- :internal => opts[:internal]
67
+ :internal => @opts[:internal]
67
68
 
68
69
  proceed = true
69
- proceed = stack.update :force => opts[:force], :attributes => new_attributes if new_attributes.any?
70
+
71
+ if new_attributes.any?
72
+ rescue_stackster_exceptions_and_exit do
73
+ proceed = stack.update :force => @opts[:force],
74
+ :attributes => new_attributes
75
+ end
76
+ end
77
+
78
+ stack.wait_for_stable
70
79
 
71
80
  if proceed
72
- notifier.send_deployment_start_message unless opts[:quiet]
73
- if stack.deploy opts[:force]
74
- notifier.send_deployment_complete_message unless opts[:quiet]
81
+ notifier.send_deployment_start_message unless @opts[:quiet]
82
+
83
+ result = stack.deploy @opts[:force]
84
+
85
+ if result
86
+ notifier.send_deployment_complete_message unless @opts[:quiet]
75
87
  else
76
88
  logger.error "Deployment to #{name} did not complete succesfully."
77
89
  exit 1
@@ -83,6 +95,16 @@ EOS
83
95
 
84
96
  end
85
97
  end
98
+
99
+ def logger
100
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
101
+ end
102
+
103
+ def command_summary
104
+ 'Execute deployment on given stack(s)'
105
+ end
106
+
86
107
  end
108
+
87
109
  end
88
110
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Destroy
7
+ include Shared
8
+
6
9
  def destroy
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -20,24 +23,28 @@ EOS
20
23
  opt :name, "Stack name(s) of stack to deploy", :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
- if stack.destroy
36
- exit 0
37
- else
38
- exit 1
39
- end
36
+ exit 1 unless stack.destroy
37
+ end
38
+
39
+ def logger
40
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
41
+ end
42
+
43
+ def command_summary
44
+ 'Destroy a stack'
40
45
  end
46
+
41
47
  end
48
+
42
49
  end
43
50
  end
@@ -0,0 +1,32 @@
1
+ require 'trollop'
2
+
3
+ module SimpleDeploy
4
+ module CLI
5
+
6
+ class Environments
7
+ include Shared
8
+
9
+ def environments
10
+ @opts = Trollop::options do
11
+ version SimpleDeploy::VERSION
12
+ banner <<-EOS
13
+
14
+ List environments
15
+
16
+ simple_deploy environments
17
+
18
+ EOS
19
+ opt :help, "Display Help"
20
+ end
21
+
22
+ Config.new.environments.keys.each { |e| puts e }
23
+ end
24
+
25
+ def command_summary
26
+ 'List environments'
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
@@ -2,13 +2,16 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Events
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
 
11
- Show attributes for stack.
14
+ Show events for stack.
12
15
 
13
16
  simple_deploy attributes -n STACK_NAME -e ENVIRONMENT
14
17
 
@@ -19,20 +22,31 @@ EOS
19
22
  opt :environment, "Set the target environment", :type => :string
20
23
  opt :name, "Stack name to manage", :type => :string
21
24
  end
22
- CLI::Shared.valid_options? :provided => opts,
23
- :required => [:environment, :name]
24
25
 
25
- config = Config.new.environment opts[:environment]
26
+ valid_options? :provided => @opts,
27
+ :required => [:environment, :name]
26
28
 
27
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
29
+ config = Config.new.environment @opts[:environment]
28
30
 
29
- stack = Stack.new :environment => opts[:environment],
30
- :name => opts[:name],
31
+ stack = Stack.new :environment => @opts[:environment],
32
+ :name => @opts[:name],
31
33
  :config => config,
32
34
  :logger => logger
33
35
 
34
- jj stack.events opts[:count]
36
+ rescue_stackster_exceptions_and_exit do
37
+ jj stack.events @opts[:count]
38
+ end
39
+ end
40
+
41
+ def logger
42
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
35
43
  end
44
+
45
+ def command_summary
46
+ "Show events for a stack"
47
+ end
48
+
36
49
  end
50
+
37
51
  end
38
52
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Execute
7
+ include Shared
8
+
6
9
  def execute
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -33,25 +36,38 @@ EOS
33
36
  opt :sudo, "Execute command with sudo"
34
37
  end
35
38
 
36
- CLI::Shared.valid_options? :provided => opts,
37
- :required => [:environment, :name]
38
-
39
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
39
+ valid_options? :provided => @opts,
40
+ :required => [:environment, :name]
40
41
 
41
- opts[:name].each do |name|
42
+ @opts[:name].each do |name|
42
43
  notifier = Notifier.new :stack_name => name,
43
- :environment => opts[:environment],
44
+ :environment => @opts[:environment],
44
45
  :logger => logger
45
46
 
46
- stack = Stack.new :environment => opts[:environment],
47
+ stack = Stack.new :environment => @opts[:environment],
47
48
  :name => name,
48
49
  :logger => logger,
49
- :internal => opts[:internal]
50
+ :internal => @opts[:internal]
50
51
 
51
- stack.execute :command => opts[:command],
52
- :sudo => opts[:sudo]
52
+ begin
53
+ stack.execute :command => @opts[:command],
54
+ :sudo => @opts[:sudo]
55
+ rescue SimpleDeploy::Exceptions::NoInstances
56
+ logger.error "Stack has no running instances."
57
+ exit 1
58
+ end
53
59
  end
54
60
  end
61
+
62
+ def logger
63
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
64
+ end
65
+
66
+ def command_summary
67
+ 'Execute command on given stack(s)'
68
+ end
69
+
55
70
  end
71
+
56
72
  end
57
73
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Instances
7
+ include Shared
8
+
6
9
  def list
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -19,29 +22,37 @@ EOS
19
22
  opt :internal, "Use internal IP for ssh commands"
20
23
  end
21
24
 
22
- CLI::Shared.valid_options? :provided => opts,
23
- :required => [:environment, :name]
24
-
25
- config = Config.new.environment opts[:environment]
25
+ valid_options? :provided => @opts,
26
+ :required => [:environment, :name]
26
27
 
27
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
28
+ config = Config.new.environment @opts[:environment]
28
29
 
29
- stack = Stack.new :environment => opts[:environment],
30
- :name => opts[:name],
30
+ stack = Stack.new :environment => @opts[:environment],
31
+ :name => @opts[:name],
31
32
  :config => config,
32
33
  :logger => logger,
33
- :internal => opts[:internal]
34
+ :internal => @opts[:internal]
34
35
 
35
36
  exit 1 unless stack.exists?
36
37
 
37
38
  instances = stack.instances
38
39
 
39
40
  if instances.nil? || instances.empty?
40
- logger.info "Stack '#{opts[:name]}' does not have any instances."
41
+ logger.info "Stack '#{@opts[:name]}' does not have any instances."
41
42
  else
42
- jj stack.instances
43
+ puts stack.instances
43
44
  end
44
45
  end
46
+
47
+ def logger
48
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
49
+ end
50
+
51
+ def command_summary
52
+ 'List instances for stack'
53
+ end
54
+
45
55
  end
56
+
46
57
  end
47
58
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class List
7
+ include Shared
8
+
6
9
  def stacks
7
- opts = Trollop::options do
10
+ @opts = Trollop::options do
8
11
  version SimpleDeploy::VERSION
9
12
  banner <<-EOS
10
13
 
@@ -14,40 +17,33 @@ simple_deploy list -e ENVIRONMENT
14
17
 
15
18
  EOS
16
19
  opt :environment, "Set the target environment", :type => :string
17
- opt :log_level, "Log level: debug, info, warn, error", :type => :string,
20
+ opt :log_level, "Log level: debug, info, warn, error", :type => :string,
18
21
  :default => 'info'
19
22
  opt :help, "Display Help"
20
23
  end
21
24
 
22
- CLI::Shared.valid_options? :provided => opts,
23
- :required => [:environment]
25
+ valid_options? :provided => @opts,
26
+ :required => [:environment]
24
27
 
25
- config = Config.new.environment opts[:environment]
28
+ config = Config.new.environment @opts[:environment]
26
29
  stacks = Stackster::StackLister.new(:config => config).all.sort
27
30
 
28
- logger = SimpleDeployLogger.new :log_level => opts[:log_level]
29
-
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
  puts stacks
35
36
  end
36
37
 
37
- def environments
38
- opts = Trollop::options do
39
- version SimpleDeploy::VERSION
40
- banner <<-EOS
41
-
42
- List environments
43
-
44
- simple_deploy environments
38
+ def logger
39
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
40
+ end
45
41
 
46
- EOS
47
- opt :help, "Display Help"
48
- end
49
- Config.new.environments.keys.each { |e| puts e }
42
+ def command_summary
43
+ 'List stacks in an environment'
50
44
  end
45
+
51
46
  end
47
+
52
48
  end
53
49
  end
@@ -2,9 +2,12 @@ require 'trollop'
2
2
 
3
3
  module SimpleDeploy
4
4
  module CLI
5
+
5
6
  class Outputs
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,26 +23,36 @@ 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
- # we need a little whitespace
36
- puts
36
+ rescue_stackster_exceptions_and_exit do
37
+ outputs = stack.outputs
37
38
 
38
- outputs = stack.outputs
39
- outputs.each do |hash|
40
- puts "%s: %s" % [hash['OutputKey'], hash['OutputValue']]
39
+ logger.info "No outputs." unless outputs.any?
40
+
41
+ outputs.each do |hash|
42
+ puts "%s: %s" % [hash['OutputKey'], hash['OutputValue']]
43
+ end
41
44
  end
42
45
  end
46
+
47
+ def logger
48
+ @logger ||= SimpleDeployLogger.new :log_level => @opts[:log_level]
49
+ end
50
+
51
+ def command_summary
52
+ 'Show outputs of a stack'
53
+ end
54
+
43
55
  end
56
+
44
57
  end
45
58
  end