peas-cli 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +29 -26
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/bin/peas +1 -1
- data/lib/peas/api.rb +30 -37
- data/lib/peas/commands/logs.rb +1 -8
- data/peas-cli.gemspec +4 -4
- data/spec/cli_spec.rb +30 -33
- data/spec/spec_helper.rb +11 -0
- metadata +2 -4
- data/bin/peas-dev +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f22ef195adddaf91d900dfb57ca2fac5b0244586
|
4
|
+
data.tar.gz: 15b42a3e4009b3697a4a71cb484ba6610f1a72fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
23
|
-
hashie (
|
22
|
+
gli (2.11.0)
|
23
|
+
hashie (3.1.0)
|
24
24
|
highline (1.6.21)
|
25
|
-
httparty (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.
|
39
|
-
|
40
|
-
|
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 (
|
46
|
-
oauth2 (0.9.
|
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 (~>
|
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.
|
53
|
+
rake (10.3.2)
|
55
54
|
rdoc (4.1.1)
|
56
55
|
json (~> 1.4)
|
57
|
-
rspec (
|
58
|
-
rspec-core (~>
|
59
|
-
rspec-expectations (~>
|
60
|
-
rspec-mocks (~>
|
61
|
-
rspec-core (
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
+
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.
|
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
|
28
|
-
|
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
|
-
|
53
|
-
|
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
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
90
|
-
|
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
|
data/lib/peas/commands/logs.rb
CHANGED
@@ -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
|
-
|
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.
|
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.
|
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-
|
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"
|
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.
|
6
|
-
Git.
|
7
|
-
Git.
|
8
|
-
API.
|
9
|
-
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
|
-
|
42
|
-
|
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
|
45
|
-
expect(output).to eq "
|
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
|
-
|
54
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
)
|
109
|
-
|
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.
|
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-
|
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 $@
|