peas-cli 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e21b1eaec8ee7ce0d7a7b76dbf2a0912c6eaa3c
4
- data.tar.gz: 13c9d9ce95cfbebcea8cfb787ca9e0661f3c444a
3
+ metadata.gz: f22ef195adddaf91d900dfb57ca2fac5b0244586
4
+ data.tar.gz: 15b42a3e4009b3697a4a71cb484ba6610f1a72fb
5
5
  SHA512:
6
- metadata.gz: 7405ef69c589de7140e5c463356b77d06f3836bd3788eca36401c74465ab6ced6ddc534f8bf362e69f26be829976d3d03466bb3511aa3c9a03ed491cd98064df
7
- data.tar.gz: e377db4f59cc014a5cd10363d83d2235d11c55ea25c1cca358b8e833f68202d29283ba38b514acb75141239ded9f5f2f24cc311eb2f623a61699a3e8f755cf7f
6
+ metadata.gz: 3c6e24d63753037320e8f30672f8c72f0d9fb38ec1c40bfe415b59886b6743991f9a77853b02a74f731e3aead6d005fd65ee770100fe814aedf1927ff6914e7b
7
+ data.tar.gz: 840321e330c30f9ef42e8ca21730b9769c0595d003cab8cc11109452c9fedeb44d6d096f24cb521c68c20e896352319d199092ecfe297b43847a295db80c13af
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- addressable (2.3.5)
4
+ addressable (2.3.6)
5
5
  builder (3.2.2)
6
6
  crack (0.4.2)
7
7
  safe_yaml (~> 1.0.0)
@@ -10,7 +10,7 @@ GEM
10
10
  diff-lcs (1.2.5)
11
11
  faraday (0.9.0)
12
12
  multipart-post (>= 1.2, < 3)
13
- git (1.2.6)
13
+ git (1.2.7)
14
14
  github_api (0.11.3)
15
15
  addressable (~> 2.3)
16
16
  descendants_tracker (~> 0.0.1)
@@ -19,10 +19,10 @@ GEM
19
19
  multi_json (>= 1.7.5, < 2.0)
20
20
  nokogiri (~> 1.6.0)
21
21
  oauth2
22
- gli (2.9.0)
23
- hashie (2.0.5)
22
+ gli (2.11.0)
23
+ hashie (3.1.0)
24
24
  highline (1.6.21)
25
- httparty (0.12.0)
25
+ httparty (0.13.1)
26
26
  json (~> 1.8)
27
27
  multi_xml (>= 0.5.2)
28
28
  jeweler (2.0.1)
@@ -35,37 +35,40 @@ GEM
35
35
  rake
36
36
  rdoc
37
37
  json (1.8.1)
38
- jwt (0.1.11)
39
- multi_json (>= 1.5)
40
- mini_portile (0.5.3)
41
- multi_json (1.9.2)
38
+ jwt (1.0.0)
39
+ mini_portile (0.6.0)
40
+ multi_json (1.10.1)
42
41
  multi_xml (0.5.5)
43
42
  multipart-post (2.0.0)
44
- nokogiri (1.6.1)
45
- mini_portile (~> 0.5.0)
46
- oauth2 (0.9.3)
43
+ nokogiri (1.6.2.1)
44
+ mini_portile (= 0.6.0)
45
+ oauth2 (0.9.4)
47
46
  faraday (>= 0.8, < 0.10)
48
- jwt (~> 0.1.8)
47
+ jwt (~> 1.0)
49
48
  multi_json (~> 1.3)
50
49
  multi_xml (~> 0.5)
51
50
  rack (~> 1.2)
52
51
  rack (1.5.2)
53
52
  rainbow (2.0.0)
54
- rake (10.2.2)
53
+ rake (10.3.2)
55
54
  rdoc (4.1.1)
56
55
  json (~> 1.4)
57
- rspec (2.14.1)
58
- rspec-core (~> 2.14.0)
59
- rspec-expectations (~> 2.14.0)
60
- rspec-mocks (~> 2.14.0)
61
- rspec-core (2.14.8)
62
- rspec-expectations (2.14.5)
63
- diff-lcs (>= 1.1.3, < 2.0)
64
- rspec-mocks (2.14.6)
65
- safe_yaml (1.0.1)
66
- thread_safe (0.3.2)
67
- webmock (1.17.4)
68
- addressable (>= 2.2.7)
56
+ rspec (3.0.0)
57
+ rspec-core (~> 3.0.0)
58
+ rspec-expectations (~> 3.0.0)
59
+ rspec-mocks (~> 3.0.0)
60
+ rspec-core (3.0.2)
61
+ rspec-support (~> 3.0.0)
62
+ rspec-expectations (3.0.2)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.0.0)
65
+ rspec-mocks (3.0.2)
66
+ rspec-support (~> 3.0.0)
67
+ rspec-support (3.0.2)
68
+ safe_yaml (1.0.3)
69
+ thread_safe (0.3.4)
70
+ webmock (1.18.0)
71
+ addressable (>= 2.3.6)
69
72
  crack (>= 0.3.2)
70
73
 
71
74
  PLATFORMS
data/Rakefile CHANGED
@@ -24,6 +24,8 @@ Jeweler::Tasks.new do |gem|
24
24
  gem.email = "tom@tombh.co.uk"
25
25
  gem.authors = ["Tom Buckley-Houston"]
26
26
  gem.files.include 'VERSION'
27
+ # Don't include peas-dev
28
+ gem.executables = ['peas']
27
29
  gem.files.exclude 'bin/peas-dev'
28
30
  # dependencies defined in Gemfile
29
31
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/bin/peas CHANGED
@@ -36,7 +36,7 @@ on_error do |exception|
36
36
  # Show a custom error message with backtrace if it's not a GLI error
37
37
  if exception.class.to_s.split('::').first != 'GLI'
38
38
  if exception.class == Errno::ECONNREFUSED
39
- Peas.error_message "Couldn't connect to the Peas API. The current endpoint is '#{Peas.config['domain']}', make " +
39
+ Peas.error_message "Couldn't connect to the Peas API. The current endpoint is '#{Peas.api_domain}', make " +
40
40
  "sure it is up and accessible."
41
41
  else
42
42
  Peas.error_message "Unexpected error: #{exception.class}"
data/lib/peas/api.rb CHANGED
@@ -24,8 +24,8 @@ class API
24
24
  raise json['error'].color(:red) if json.has_key? 'error'
25
25
  # Successful responses
26
26
  if json.has_key? 'job'
27
- # Long-running jobs need to poll a job status endpoint
28
- long_running_output json['job']
27
+ # Long-running jobs need to stream from the Switchboard server
28
+ API.stream_job json['job']
29
29
  else
30
30
  # Check CLI client is up to date.
31
31
  # Only check major and minor versions
@@ -49,45 +49,38 @@ class API
49
49
  end
50
50
  end
51
51
 
52
- # Rudimentary long-polling to stream the status of a job.
53
- def long_running_output job
54
- count = 0
55
- begin
56
- sleep LONG_POLL_INTERVAL
57
- # API request to the /status endpoint
58
- status = JSON.parse self.class.send(:get, '/status', {query: {job: job}}).body
59
- if status['status'] != 'failed'
60
- if status['output']
61
- # Don't output the accumulated progress log every time. Just output the difference
62
- output_diff status['output']
63
- end
64
- # Theoretically all worker errors should be caught and handled gracefully
65
- if status['error']
66
- puts
67
- raise status['error'].color(:red)
68
- end
69
- else
70
- # Uncaught error or production environment error
71
- raise "Long-running job failed. See worker logs for details.".color(:red)
72
- end
73
- count += 1
74
- end while status['status'] == 'working' && (count * LONG_POLL_INTERVAL) < LONG_POLL_TIMEOUT
52
+ def self.switchboard_connection
53
+ TCPSocket.new Peas.host, Peas::SWITCHBOARD_PORT
75
54
  end
76
55
 
77
- # The Sidekiq status gem allows you to set custom variables associated with a job. So the worker
78
- # appends to an 'output' variable that accumulates the total log data. So we don't want to output
79
- # the 'total' output on every long-polled request. We just want to output any *new* log lines.
80
- def output_diff log_so_far
81
- @accumulated_output ||= ''
82
- old_count = @accumulated_output.lines.count
83
- new_count = log_so_far.lines.count
84
- diff = log_so_far.lines.to_a[old_count..new_count]
85
- @accumulated_output = log_so_far
86
- puts diff.join if diff.length > 0
56
+ # Stream the output of a Switchboard job
57
+ def self.stream_job job
58
+ API.stream_output "subscribe.job_progress.#{job}" do |line|
59
+ if line.has_key? 'status'
60
+ if line['status'] == 'failed'
61
+ raise line['body']
62
+ elsif line['status'] == 'complete'
63
+ break
64
+ end
65
+ end
66
+ puts line['body'] if line['body']
67
+ end
87
68
  end
88
69
 
89
- def self.switchboard_connection
90
- TCPSocket.new Peas.host, Peas::SWITCHBOARD_PORT
70
+ # Stream data from the Switchboard server
71
+ def self.stream_output switchboard_command
72
+ socket = API.switchboard_connection
73
+ socket.puts switchboard_command
74
+ begin
75
+ while line = socket.gets
76
+ if block_given?
77
+ yield JSON.parse line
78
+ else
79
+ puts line
80
+ end
81
+ end
82
+ rescue Interrupt, Errno::ECONNRESET
83
+ end
91
84
  end
92
85
 
93
86
  end
@@ -1,13 +1,6 @@
1
1
  desc 'Show logs for an app'
2
2
  command :logs do |c|
3
3
  c.action do |global_options, options, args|
4
- socket = API.switchboard_connection
5
- socket.puts "stream_logs.#{Git.first_sha}"
6
- begin
7
- while line = socket.gets
8
- puts line
9
- end
10
- rescue Interrupt, Errno::ECONNRESET
11
- end
4
+ API.stream_output "stream_logs.#{Git.first_sha}"
12
5
  end
13
6
  end
data/peas-cli.gemspec CHANGED
@@ -2,19 +2,19 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: peas-cli 0.1.1 ruby lib
5
+ # stub: peas-cli 0.1.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "peas-cli"
9
- s.version = "0.1.1"
9
+ s.version = "0.1.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Tom Buckley-Houston"]
14
- s.date = "2014-06-14"
14
+ s.date = "2014-07-08"
15
15
  s.description = "Peas is an open source Heroku-style PaaS written in Ruby and using Docker"
16
16
  s.email = "tom@tombh.co.uk"
17
- s.executables = ["peas", "peas-dev"]
17
+ s.executables = ["peas"]
18
18
  s.extra_rdoc_files = [
19
19
  "README.md"
20
20
  ]
data/spec/cli_spec.rb CHANGED
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Peas CLI' do
4
4
  before :each do
5
- Git.stub(:sh).and_return(nil)
6
- Git.stub(:remote).and_return('git@github.com:test/test.git')
7
- Git.stub(:first_sha).and_return('fakesha')
8
- API.any_instance.stub(:sleep).and_return(nil)
9
- Peas.stub(:config_file).and_return('/tmp/.peas')
5
+ allow(Git).to receive(:sh).and_return(nil)
6
+ allow(Git).to receive(:remote).and_return('git@github.com:test/test.git')
7
+ allow(Git).to receive(:first_sha).and_return('fakesha')
8
+ allow_any_instance_of(API).to receive(:sleep).and_return(nil)
9
+ allow(Peas).to receive(:config_file).and_return('/tmp/.peas')
10
10
  File.delete '/tmp/.peas' if File.exists? '/tmp/.peas'
11
11
  end
12
12
 
@@ -36,22 +36,26 @@ describe 'Peas CLI' do
36
36
  expect(output).to eq "App 'test' successfully created\n"
37
37
  end
38
38
 
39
- it 'should deploy an app' do
39
+ it 'should deploy an app', :with_socket do
40
40
  stub_request(:get, /deploy/).to_return(body: '{"job": "123"}')
41
- stub_request(:get, /status/).to_return(
42
- {body: '{"status": "working", "output": "deploying\n"}'}
41
+ allow(@socket).to receive(:gets).and_return(
42
+ '{"body":"doing"}',
43
+ '{"body":"something"}',
44
+ '{"body":"done"}',
45
+ '{"status":"complete"}'
43
46
  )
44
- output = cli ['deploy']
45
- expect(output).to eq "deploying\n"
47
+ output = cli %w(deploy)
48
+ expect(output).to eq "doing\nsomething\ndone\n"
46
49
  end
47
50
 
48
- it 'should scale an app' do
51
+ it 'should scale an app', :with_socket do
49
52
  stub_request(
50
53
  :put,
51
54
  TEST_DOMAIN + '/app/fakesha/scale?scaling_hash=%7B%22web%22:%223%22,%22worker%22:%222%22%7D'
52
55
  ).to_return(body: '{"job": "123"}')
53
- stub_request(:get, /status/).to_return(
54
- {body: '{"status": "working", "output": "scaling\n"}'}
56
+ allow(@socket).to receive(:gets).and_return(
57
+ '{"body":"scaling"}',
58
+ '{"status":"complete"}'
55
59
  )
56
60
  output = cli %w(scale web=3 worker=2)
57
61
  expect(output).to eq "scaling\n"
@@ -83,31 +87,24 @@ describe 'Peas CLI' do
83
87
 
84
88
  describe 'Logs' do
85
89
  it 'should stream logs' do
86
- stub_const 'Peas::SWITCHBOARD_PORT', 79345
87
- Thread.new do
88
- server = TCPServer.new Peas.host, Peas::SWITCHBOARD_PORT
89
- if peer = server.accept
90
- peer.puts "Here's ya logs"
91
- peer.puts "MOAR logs"
92
- peer.close
93
- end
94
- end
95
- sleep 0.3
90
+ socket = double 'TCPSocket'
91
+ allow(socket).to receive(:puts)
92
+ allow(socket).to receive(:gets).and_return("Here's ya logs", "MOAR", false)
93
+ allow(TCPSocket).to receive(:new).and_return(socket)
96
94
  output = cli %w(logs)
97
- expect(output).to eq "Here's ya logs\nMOAR logs\n"
95
+ expect(output).to eq "Here's ya logs\nMOAR\n"
98
96
  end
99
97
  end
100
98
 
101
99
  it 'should retrieve and output a long-running command' do
102
- stub_request(:get, /deploy/).to_return(body: '{"job": "123"}')
103
- stub_request(:get, /status/).to_return(
104
- {body: '{"status": "working", "output": "doing\n"}'},
105
- {body: '{"status": "working", "output": "doing\nsomething\n"}'},
106
- {body: '{"status": "working", "output": "doing\nsomething\n"}'},
107
- {body: '{"status": "complete", "output": "doing\nsomething\ndone\n"}'}
108
- )
109
- output = cli ['deploy']
110
- expect(output).to eq "doing\nsomething\ndone\n"
100
+ socket = double 'TCPSocket'
101
+ expect(socket).to receive(:puts).with('subscribe.job_progress.123')
102
+ allow(socket).to receive(:gets).and_return("doing", "something", "done", false)
103
+ allow(TCPSocket).to receive(:new).and_return(socket)
104
+ expect(API).to receive(:puts).with "doing"
105
+ expect(API).to receive(:puts).with "something"
106
+ expect(API).to receive(:puts).with "done"
107
+ API.stream_output "subscribe.job_progress.123"
111
108
  end
112
109
 
113
110
  it 'should show a warning when there is a version mismatch' do
data/spec/spec_helper.rb CHANGED
@@ -9,10 +9,21 @@ ENV['GLI_ENV'] = 'test'
9
9
  ROOT = File.join(File.expand_path(File.dirname(__FILE__)), '..')
10
10
  $LOAD_PATH.unshift(File.join(ROOT, 'lib'))
11
11
  TEST_DOMAIN = 'http://localhost:4000'
12
+ SWITCHBOARD_TEST_PORT = 79345
12
13
 
13
14
  RSpec.configure do |config|
14
15
  config.mock_with :rspec
15
16
  config.expect_with :rspec
17
+
18
+ config.before(:each) do
19
+ stub_const('Peas::SWITCHBOARD_PORT', SWITCHBOARD_TEST_PORT)
20
+ end
21
+
22
+ config.before(:each, :with_socket) do
23
+ @socket = double 'TCPSocket'
24
+ expect(@socket).to receive(:puts).with('subscribe.job_progress.123')
25
+ allow(TCPSocket).to receive(:new).and_return(@socket)
26
+ end
16
27
  end
17
28
 
18
29
  # Execute a block that triggers STDOUT and test output
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peas-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Buckley-Houston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-14 00:00:00.000000000 Z
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -70,7 +70,6 @@ description: Peas is an open source Heroku-style PaaS written in Ruby and using
70
70
  email: tom@tombh.co.uk
71
71
  executables:
72
72
  - peas
73
- - peas-dev
74
73
  extensions: []
75
74
  extra_rdoc_files:
76
75
  - README.md
@@ -82,7 +81,6 @@ files:
82
81
  - Rakefile
83
82
  - VERSION
84
83
  - bin/peas
85
- - bin/peas-dev
86
84
  - lib/peas.rb
87
85
  - lib/peas/api.rb
88
86
  - lib/peas/commands/admin.rb
data/bin/peas-dev DELETED
@@ -1,8 +0,0 @@
1
- #!/bin/bash
2
- # This script lets you use the development version of the Peas CLI rather than the Rubygems version
3
- # installed via `gem install peas-cli`.
4
- # Install by symlinking this file into your executbales path, eg;
5
- # `sudo ln -s $(pwd)/peas-dev /usr/local/bin/peas-dev'
6
- set -e
7
- PEAS_ROOT="$(dirname "$(test -L "$0" && readlink "$0" || echo "$0")")/../.."
8
- BUNDLE_GEMFILE=$PEAS_ROOT/cli/Gemfile GLI_DEBUG=true bundle exec $PEAS_ROOT/cli/bin/peas $@