opsicle 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTQxYzNhNDc2ODIzNjhiZjBjMTZjZmE4M2EwZmYxOGIyMDQ0YTY2Yg==
4
+ ZjljYjQ5NzE0M2NhZDU3MWM2MTdjYjFjNzY2NzQ4MmU1MzU2YmE3OA==
5
5
  data.tar.gz: !binary |-
6
- MGU2ODEzNzlkODk2MzI5NzljMTQyOTAxYzE4YThkMjgzY2I3YmY4NA==
6
+ NzQxZmI2NTY1MGVjZjIzMjA2NzdjNWRhZjFkMDQxMDUzZTFhZDYyOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDAwMDQ2Y2FkZGY0NjcwZGQ5MzQ1NGYwYTg5MjI3MDVjOGYxMjMzYTViMWVi
10
- ZDVhYWEzOGE3NWQ1NzcxNGUxZTE5OTZhNmFlNDc2Y2ViNTQzMGI3MGZmNjEy
11
- N2EyMDZmNjA5MDkxOGNkNmFmNGU2N2Y5MmY1MjBjMDI5ZWFkYjE=
9
+ OTAzMjJiODFkMjVjZDc5MTYyMGU4NTg4YzdlMjM2YmJjNmRjMTcyYTBlZDY1
10
+ MjVhNWNiOWU1NjljZjAzOGZhZTk5NjBhMDE0NThkNDkwOGNhZDk5ZGFjNmUw
11
+ ZjQ1ZmYwNjQzYzU2OWZhY2M4NjUwMmYzN2U2NWY1YzRlMmRiY2E=
12
12
  data.tar.gz: !binary |-
13
- MGNlYjBhYzQ1YmI2MGU1NjNhMTNmYTliMGEzZTEzYzI4MjIyOWU5MTc5MjE2
14
- M2FlOTkyNDdkMjRlOGIyN2Y5ZTM2NjM1NjUxNDAxNWNhNjJjNmY0NDU5ODkz
15
- NmZkNjA0MDcxY2YwYmZjYzVjYmVlYWU5ZTE4YzhmNTEwNmYxNTQ=
13
+ OTdiNDgwZmM3MjQxNmM0MWE3NTJiMzlmZDY1NTIyYTg2NDcxOTBiNmJmOGE4
14
+ ZjIxNzIyZGIyMDc5Y2IyNTkxYTI4ZDVjMGE2YmZkYTk5OTljOTVhMjUxZmE4
15
+ YzRkNzM4ZmNiMTlkMWEyZGU4MDRjMTJkZGJmYmFhNWRlMzQzNjQ=
data/README.markdown CHANGED
@@ -69,8 +69,9 @@ opsicle deploy staging
69
69
  opsicle deploy production
70
70
 
71
71
  ```
72
- You may also use `-m or --monitor` to open the Opsicle Stack Monitor, or
73
- `-b or --browser` to open the OpsWorks deployments screen for that app when deploying.
72
+ By default, deploying opens the Opsicle Stack Monitor.
73
+ You may also use `--browser` to open the OpsWorks deployments screen instead,
74
+ or `--no-monitor` to ignore both monitoring options
74
75
 
75
76
  ### SSH
76
77
  ```bash
data/bin/opsicle CHANGED
@@ -1,85 +1,117 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
- require 'commander/import'
3
+ require 'gli'
4
4
  require 'opsicle'
5
5
 
6
- # :name is optional, otherwise uses the basename of this executable
7
- program :name, 'opsicle'
8
- program :version, Opsicle::VERSION
9
- program :description, 'Opsworks Command Line Utility Belt'
10
- program :help, 'Documentation', 'For documentation and help in setting up your configuration files, '\
11
- 'see Opsicle\'s GitHub repo: https://github.com/sportngin/opsicle'
6
+ include GLI::App
12
7
 
13
- global_option('--verbose'){ $verbose = true }
8
+ program_desc 'Opsworks Command Line Utility Belt'
9
+ version Opsicle::VERSION
14
10
 
15
- if ENV['DEBUG']
16
- always_trace!
17
- $debug = true
18
- else
19
- never_trace!
20
- end
21
- $verbose = true if ENV['VERBOSE']
11
+ wrap_help_text :verbatim
12
+
13
+ program_long_desc """
14
+ DOCUMENTATION
15
+ For documentation and help in setting up your configuration files,
16
+ see Opsicle's GitHub repo: https://github.com/sportngin/opsicle
17
+ """
18
+
19
+ switch :verbose, :desc => 'Enable Verbose mode for more logging', :negatable => false
20
+ switch :debug, :desc => 'Enable Debug mode for detailed logs and backtraces', :negatable => false
21
+ switch :color, :desc => 'Use colored output', :default_value => true
22
22
 
23
+ pre do |global_options, command, options, args|
24
+ $verbose = global_options[:verbose]
25
+ $debug = global_options[:debug]
26
+ $color = global_options[:color]
27
+ ENV['GLI_DEBUG'] = $debug.to_s
28
+ true
29
+ end
23
30
 
24
- default_command :help
31
+ on_error do |exception|
32
+ exit(0) if exception.is_a?(Opsicle::Monitor::QuitMonitor)
33
+ true
34
+ end
25
35
 
36
+ desc "Deploy your current app to the given environment stack"
37
+ arg_name '<environment>'
26
38
  command :deploy do |c|
27
- c.syntax = "opsicle deploy <environment>"
28
- c.description = "Deploy your current app to the given environment stack"
29
- c.option "-b", "--browser", "Open the OpsWorks deployments screen for this stack on deploy"
30
- c.option "-m", "--monitor", "Open the Opsicle Stack Monitor for this stack on deploy"
31
- c.action do |args, options|
32
- raise ArgumentError, "Environment is required" unless args.first
33
- Opsicle::Deploy.new(args.first).execute(options.__hash__)
39
+ c.switch [:b, :browser], :desc => "Open the OpsWorks deployments screen for this stack on deploy"
40
+ c.switch [:m, :monitor], :desc => "Run the Stack Monitor on deploy", :default_value => true
41
+ c.action do |global_options, options, args|
42
+ raise ArgumentError, 'You must specify an environment' unless args.first
43
+ Opsicle::Deploy.new(args.first).execute global_options.merge(options)
34
44
  end
35
45
  end
36
46
 
47
+ desc "List all apps in the given environment stack"
48
+ arg_name '<environment>'
37
49
  command :list do |c|
38
- c.syntax = "opsicle list <environment>"
39
- c.description = "List all apps in the given environment stack"
40
- c.action do |args, options|
50
+ c.action do |global_options, options, args|
41
51
  raise ArgumentError, "Environment is required" unless args.first
42
- Opsicle::List.new(args.first).execute(options.__hash__)
52
+ Opsicle::List.new(args.first).execute global_options.merge options
43
53
  end
44
54
  end
45
55
 
56
+ desc "SSH access to instances in the given environment stack"
57
+ arg_name '<environment>'
46
58
  command :ssh do |c|
47
- c.syntax = "opsicle ssh <environment>"
48
- c.description = "SSH access to instances in the given environment stack"
49
- c.action do |args, options|
59
+ c.action do |global_options, options, args|
50
60
  raise ArgumentError, "Environment is required" unless args.first
51
- Opsicle::SSH.new(args.first).execute(options.__hash__)
61
+ Opsicle::SSH.new(args.first).execute global_options.merge(options)
52
62
  end
53
63
  end
54
64
 
65
+ desc "Set your user SSH key (PUBLIC KEY) for OpsWorks"
66
+ arg_name '<environment> <key-file>'
55
67
  command 'ssh-key' do |c|
56
- c.syntax = "opsicle ssh-key <environment> <key-file>"
57
- c.description = "Set your user SSH key (PUBLIC KEY) for OpsWorks"
58
- c.action do |args, options|
68
+ c.action do |global_options, options, args|
59
69
  raise ArgumentError, "Environment is required" unless args.first
60
70
  raise ArgumentError, "ssh public key-file is required" unless args[1]
61
- Opsicle::SSHKey.new(*args).execute(options.__hash__)
71
+ Opsicle::SSHKey.new(*args).execute global_options.merge(options)
62
72
  end
63
73
  end
64
74
 
75
+ desc "Launch the Opsicle Stack Monitor for the given environment stack"
76
+ arg_name '<environment>'
65
77
  command 'monitor' do |c|
66
- c.syntax = "opsicle monitor <environment>"
67
- c.description = "Launch the Opsicle Stack Monitor for the given environment stack"
68
- c.action do |args, options|
78
+ c.action do |global_options, options, args|
69
79
  raise ArgumentError, "Environment is required" unless args.first
70
80
 
71
- @monitor = Opsicle::Monitor::App.new(args.first, options.__hash__)
81
+ @monitor = Opsicle::Monitor::App.new(args.first, global_options.merge(options))
82
+ @monitor.start
83
+ end
84
+ end
85
+
86
+ desc "Show the OpsWorks URL for the given environment stack"
87
+ long_desc """
88
+ Shows the full OpsWorks URL to a page in the web interface.
72
89
 
73
- begin
74
- @monitor.start
75
- rescue => e
76
- say "<%= color('Uh oh, an error occurred while starting the Opsicle Stack Monitor.', RED) %>"
77
- say "<%= color('Use --trace to view stack trace.', RED) %>"
90
+ Acceptable arguments to --page include:
91
+ stack (default)
92
+ layers
93
+ instances
94
+ apps
95
+ deployments
96
+ monitoring
97
+ resources
98
+ permissions
78
99
 
79
- if options.trace
80
- raise
81
- end
82
- end
100
+ Example: 'opsicle opsworks-url staging --page=deployments'
101
+ """
102
+ arg_name '<environment>'
103
+ command 'opsworks-url' do |c|
104
+ opsworks_pages = %w[stack, layers, instances, apps, deployments, monitoring, resources, permissions]
105
+ c.flag [:p, :page],
106
+ :desc => 'Request a specific page in the OpsWorks web interface',
107
+ :must_match => opsworks_pages,
108
+ :default_value => 'stack'
109
+ c.action do |global_options, options, args|
110
+ raise ArgumentError, "Environment is required" unless args.first
111
+
112
+ url = "#{Opsicle::Client.new(args.first).opsworks_url}/#{options[:page]}"
113
+ Opsicle::Output.say url
83
114
  end
84
115
  end
85
- alias_command :'top', :'monitor'
116
+
117
+ exit run(ARGV)
data/lib/opsicle.rb CHANGED
@@ -4,6 +4,7 @@ Signal.trap("INT") do
4
4
  exit 1
5
5
  end
6
6
 
7
+ require "opsicle/output"
7
8
  require "opsicle/version"
8
9
  require "opsicle/commands"
9
10
  require "opsicle/monitor"
@@ -19,6 +19,10 @@ module Opsicle
19
19
  aws_client.public_send(command, options)
20
20
  end
21
21
 
22
+ def opsworks_url
23
+ "https://console.aws.amazon.com/opsworks/home?#/stack/#{@config.opsworks_config[:stack_id]}"
24
+ end
25
+
22
26
  def command_options(command, options={})
23
27
  config.opsworks_config.merge(options).merge({ command: { name: command } })
24
28
  end
@@ -7,34 +7,28 @@ module Opsicle
7
7
  @client = Client.new(environment)
8
8
  end
9
9
 
10
- def execute(options={})
10
+ def execute(options={ monitor: true })
11
+ Output.say "Starting OpsWorks deploy..."
11
12
  response = client.run_command('deploy')
12
13
 
14
+ # Monitoring preferences
13
15
  if options[:browser]
14
16
  open_deploy(response[:deployment_id])
15
- end
16
-
17
- if options[:monitor]
17
+ elsif options[:monitor] # Default option
18
+ Output.say_verbose "Starting Stack Monitor..."
18
19
  @monitor = Opsicle::Monitor::App.new(@environment, options)
19
-
20
- begin
21
- @monitor.start
22
- rescue => e
23
- say "<%= color('Uh oh, an error occurred while starting the Opsicle Stack Monitor.', RED) %>"
24
- say "<%= color('Use --trace to view stack trace.', RED) %>"
25
-
26
- if options.trace
27
- raise
28
- end
29
- end
20
+ @monitor.start
30
21
  end
22
+
31
23
  end
32
24
 
33
25
  def open_deploy(deployment_id)
34
26
  if deployment_id
35
- exec "open 'https://console.aws.amazon.com/opsworks/home?#/stack/#{client.config.opsworks_config[:stack_id]}/deployments'"
27
+ command = "open 'https://console.aws.amazon.com/opsworks/home?#/stack/#{client.config.opsworks_config[:stack_id]}/deployments'"
28
+ Output.say_verbose "Executing shell command: #{command}"
29
+ %x(#{command})
36
30
  else
37
- puts 'deploy failed'
31
+ Output.say "Deploy failed. No deployment_id was received from OpsWorks", "RED"
38
32
  end
39
33
  end
40
34
  end
@@ -10,9 +10,9 @@ module Opsicle
10
10
  if instances.length == 1
11
11
  choice = 1
12
12
  else
13
- say "Choose an Opsworks instance: \n"
13
+ Output.say "Choose an Opsworks instance:"
14
14
  instances.each_index do |x|
15
- say "#{x+1}) #{instances[x][:hostname]}"
15
+ Output.say "#{x+1}) #{instances[x][:hostname]}"
16
16
  end
17
17
  choice = ask("? ", Integer) { |q| q.in = 1..instances.length }
18
18
  end
@@ -20,7 +20,7 @@ module Opsicle
20
20
  instance_ip = instances[choice-1][:elastic_ip] || instances[choice-1][:public_ip]
21
21
 
22
22
  command = "ssh #{ssh_username}@#{instance_ip}"
23
- say "<%= color('Executing shell command: #{command}', YELLOW) %>" if $verbose
23
+ Output.say_verbose "Executing shell command: #{command}"
24
24
  system(command)
25
25
  end
26
26
 
@@ -9,7 +9,7 @@ module Opsicle
9
9
  def execute(options={})
10
10
  validate!
11
11
  update
12
- say "ssh-key updated successfully"
12
+ Output.say "ssh-key updated successfully"
13
13
  end
14
14
 
15
15
  def validate!
@@ -56,7 +56,7 @@ module Opsicle
56
56
  @screen.close
57
57
  @screen = nil # Ruby curses lib doesn't have closed?(), so we set to nil, just in case
58
58
 
59
- exit 0
59
+ raise QuitMonitor
60
60
  end
61
61
 
62
62
  def restart
@@ -143,5 +143,6 @@ module Opsicle
143
143
  %x(open 'https://console.aws.amazon.com/opsworks/home?#/stack/#{App.client.config.opsworks_config[:stack_id]}')
144
144
  end
145
145
  end
146
+ QuitMonitor = Class.new(StandardError)
146
147
  end
147
148
  end
@@ -0,0 +1,17 @@
1
+ require 'highline/import'
2
+
3
+ module Opsicle
4
+ module Output
5
+ def self.say(msg, color_requested=nil)
6
+ if $color && color_requested
7
+ super "<%= color('#{msg}', #{color_requested}) %>"
8
+ else
9
+ super msg
10
+ end
11
+ end
12
+
13
+ def self.say_verbose(msg, color="MAGENTA")
14
+ self.say "<%= color('#{msg}', #{color}) %>" if $verbose
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/opsicle.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "aws-sdk", "~> 1.30"
22
- spec.add_dependency "commander", "~> 4.1.6"
22
+ spec.add_dependency "gli"
23
+ spec.add_dependency "highline"
23
24
  spec.add_dependency "terminal-table"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/client"
2
+ require "opsicle"
3
3
 
4
4
  module Opsicle
5
5
  describe Client do
@@ -1,6 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/commands/deploy"
3
- require "opsicle/monitor"
2
+ require "opsicle"
4
3
 
5
4
  module Opsicle
6
5
  describe Deploy do
@@ -15,30 +14,32 @@ module Opsicle
15
14
 
16
15
  allow(Monitor::App).to receive(:new).and_return(monitor)
17
16
  allow(monitor).to receive(:start)
17
+
18
+ allow(Output).to receive(:say)
19
+ allow(Output).to receive(:say_verbose)
18
20
  end
19
21
 
20
- it "creates a new deployment" do
22
+ it "creates a new deployment and opens stack monitor" do
21
23
  expect(client).to receive(:run_command).with('deploy').and_return({deployment_id: 'derp'})
22
24
  expect(subject).to_not receive(:open_deploy)
23
- expect(Monitor::App).to_not receive(:new)
25
+ expect(Monitor::App).to receive(:new)
24
26
 
25
27
  subject.execute
26
28
  end
27
29
 
28
- it "runs the Opsicle Stack Monitor if monitor option is given" do
29
- expect(Monitor::App).to receive(:new).and_return(monitor)
30
- expect(monitor).to receive(:start)
31
- expect(subject).to_not receive(:open_deploy)
32
-
33
- subject.execute({ monitor: true })
34
- end
35
-
36
30
  it "opens the OpsWorks deployments screen if browser option is given" do
37
31
  expect(subject).to receive(:open_deploy)
38
32
  expect(Monitor::App).to_not receive(:new)
39
33
 
40
34
  subject.execute({ browser: true })
41
35
  end
36
+
37
+ it "doesn't open the stack monitor or open the browser window when no-monitor option is given" do
38
+ expect(subject).to_not receive(:open_deploy)
39
+ expect(Monitor::App).to_not receive(:new)
40
+
41
+ subject.execute({ monitor: false })
42
+ end
42
43
  end
43
44
 
44
45
  context "#client" do
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/commands/list"
2
+ require "opsicle"
3
3
 
4
4
  module Opsicle
5
5
  describe List do
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/commands/ssh_key"
2
+ require "opsicle"
3
3
 
4
4
  module Opsicle
5
5
  describe SSHKey do
@@ -16,14 +16,14 @@ module Opsicle
16
16
  context "valid ssh key" do
17
17
  it "confirms that the given file is a public ssh key" do
18
18
  expect(subject).to receive(:validate!)
19
- expect(subject).to receive(:say).with(/success/)
19
+ expect(Output).to receive(:say).with(/success/)
20
20
  allow(subject).to receive(:update)
21
21
  subject.execute
22
22
  end
23
23
 
24
24
  it "updates the user's ssh-key on opsworks" do
25
25
  allow(subject).to receive(:validate!)
26
- expect(subject).to receive(:say).with(/success/)
26
+ expect(Output).to receive(:say).with(/success/)
27
27
  expect(subject).to receive(:update)
28
28
  subject.execute
29
29
  end
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/commands/ssh"
2
+ require "opsicle"
3
3
 
4
4
  module Opsicle
5
5
  describe SSH do
@@ -12,7 +12,8 @@ module Opsicle
12
12
 
13
13
  context "#execute" do
14
14
  before do
15
- allow(subject).to receive(:say) { "What instance do you want, huh?" }
15
+ allow(Output).to receive(:say)
16
+ allow(Output).to receive(:say_verbose)
16
17
  allow(subject).to receive(:ask).and_return(2)
17
18
  allow(subject).to receive(:ssh_username) {"mrderpyman2014"}
18
19
  end
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/config"
2
+ require "opsicle"
3
3
 
4
4
  module Opsicle
5
5
  describe Config do
@@ -1,6 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/monitor/app"
3
- require "opsicle/monitor/screen"
2
+ require "opsicle"
4
3
 
5
4
  describe Opsicle::Monitor::App do
6
5
 
@@ -1,8 +1,7 @@
1
1
  require "spec_helper"
2
- require "opsicle/monitor/panel"
2
+ require "opsicle"
3
3
  require "curses"
4
4
 
5
-
6
5
  describe Opsicle::Monitor::Panel do
7
6
 
8
7
  before do
@@ -1,9 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/monitor/screen"
3
- require "opsicle/monitor/panels/header"
4
- require "opsicle/monitor/panels/deployments"
5
- require "opsicle/monitor/panels/help"
6
-
2
+ require "opsicle"
7
3
 
8
4
  describe Opsicle::Monitor::Screen do
9
5
 
@@ -1,9 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'opsicle/deployments'
3
- require 'opsicle/monitor/spy/dataspyable'
4
- require 'opsicle/monitor/translatable'
5
- require 'opsicle/monitor/spy/deployments'
6
- require 'opsicle/monitor/app'
2
+ require 'opsicle'
7
3
 
8
4
  describe Opsicle::Monitor::Spy::Deployments do
9
5
  before do
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require "opsicle/monitor/subpanel"
2
+ require "opsicle"
3
3
 
4
4
 
5
5
  describe Opsicle::Monitor::Subpanel do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsicle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Fleener
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-03 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -25,19 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.30'
27
27
  - !ruby/object:Gem::Dependency
28
- name: commander
28
+ name: gli
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.1.6
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.1.6
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: terminal-table
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +176,7 @@ files:
162
176
  - lib/opsicle/monitor/spy/deployments.rb
163
177
  - lib/opsicle/monitor/subpanel.rb
164
178
  - lib/opsicle/monitor/translatable.rb
179
+ - lib/opsicle/output.rb
165
180
  - lib/opsicle/stack.rb
166
181
  - lib/opsicle/version.rb
167
182
  - opsicle.gemspec