peas-cli 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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 620734d8a5713490dbf9b4f79a669ebba23f0147
4
- data.tar.gz: f758e5a9bcf974c88c15a48f26839d6bcdd295fe
3
+ metadata.gz: ce1aa06662fc854dd4a33701bc818feb65fbb628
4
+ data.tar.gz: 7b31388468f79007654454249a62048977af84d8
5
5
  SHA512:
6
- metadata.gz: 7fa88458e995231523a05e1c9746956cf84f95901e515514c85478e9c63915bf080e6627f4b5b752e46341ddf93713b8a7864c7b0160d7bc1372d31b5ebeaedc
7
- data.tar.gz: 33395d9b38d39c016a244010e537e6eafaadce6084e5cd990920128e6aef47c4f9ee165d9100a221f1c343287f4a3f53099b870e30e205e4c074bb73a83d464c
6
+ metadata.gz: f8b5831ae013078332b0ec19d28d829b16936108d8b929b5082f2be7a1dcd1480a27b86abf6f2438c1afb6da26d867c431ed5d0a86a8b5f63d00f47764254b16
7
+ data.tar.gz: 4ebd57e18fcc038e098d26e36bc6fbc189f15df0093fa77b3958af764e4b7296929f6656213ac0d24102356b7aac602ed7e2d1642d605b9d7103ead0bf26ff9e
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'gli'
4
4
  gem 'httparty'
5
5
  gem 'rainbow'
6
+ gem 'addressable'
6
7
 
7
8
  group :test do
8
9
  gem 'rspec'
data/Gemfile.lock CHANGED
@@ -75,6 +75,7 @@ PLATFORMS
75
75
  ruby
76
76
 
77
77
  DEPENDENCIES
78
+ addressable
78
79
  gli
79
80
  httparty
80
81
  jeweler
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
data/lib/peas/api.rb CHANGED
@@ -48,6 +48,7 @@ class API
48
48
  else
49
49
  puts json['message']
50
50
  end
51
+ json
51
52
  end
52
53
  end
53
54
 
@@ -7,12 +7,21 @@ end
7
7
 
8
8
  desc 'Create an app'
9
9
  command :create do |c|
10
+ public_key_path = "#{ENV['HOME']}/.ssh/id_rsa.pub"
10
11
  c.action do |_global_options, _options, _args|
11
- @api.request(
12
+ unless Git.remote('peas').empty?
13
+ exit_now! "This repo already has an app (#{Git.name_from_remote}) associated with it.", 1
14
+ end
15
+ unless File.exist? public_key_path
16
+ exit_now! "Couldn't find an SSH public key", 1
17
+ end
18
+ response = @api.request(
12
19
  :post,
13
- "/app/#{Git.first_sha}",
14
- remote: Git.remote
20
+ '/app',
21
+ muse: Git.name_from_remote(Git.remote('origin')),
22
+ public_key: File.open(public_key_path).read
15
23
  )
24
+ Git.add_remote response['remote_uri']
16
25
  end
17
26
  end
18
27
 
@@ -21,15 +30,9 @@ command :destroy do |c|
21
30
  c.action do |_global_options, _options, _args|
22
31
  @api.request(
23
32
  :delete,
24
- "/app/#{Git.first_sha}"
33
+ "/app/#{Git.name_from_remote}"
25
34
  )
26
- end
27
- end
28
-
29
- desc 'Deploy an app'
30
- command :deploy do |c|
31
- c.action do |_global_options, _options, _args|
32
- @api.request :get, "/app/#{Git.first_sha}/deploy"
35
+ Git.remove_remote
33
36
  end
34
37
  end
35
38
 
@@ -40,7 +43,7 @@ EOF
40
43
  command :scale do |c|
41
44
  c.action do |_global_options, _options, args|
42
45
  if args.length == 0
43
- exit_now! "Please provide scaling arguments in the form: web=3 worker=2"
46
+ exit_now! "Please provide scaling arguments in the form: web=3 worker=2", 1
44
47
  end
45
48
  scaling_hash = {}
46
49
  args.each do |arg|
@@ -51,7 +54,7 @@ command :scale do |c|
51
54
  end
52
55
  @api.request(
53
56
  :put,
54
- "/app/#{Git.first_sha}/scale",
57
+ "/app/#{Git.name_from_remote}/scale",
55
58
  scaling_hash: scaling_hash.to_json
56
59
  )
57
60
  end
@@ -2,15 +2,17 @@ desc 'Add, remove and list config for an app'
2
2
  command :config do |c|
3
3
  c.default_desc 'List all config'
4
4
  c.action do |_global_options, _options, _args|
5
- @api.request :get, "/app/#{Git.first_sha}/config"
5
+ @api.request :get, "/app/#{Git.name_from_remote}/config"
6
6
  end
7
7
 
8
8
  c.desc 'Delete config by keys'
9
9
  c.command :rm do |sc|
10
10
  sc.action do |_global_options, _options, args|
11
- @api.request :delete, "/app/#{Git.first_sha}/config",
12
- keys: args.to_json
13
-
11
+ @api.request(
12
+ :delete,
13
+ "/app/#{Git.name_from_remote}/config",
14
+ keys: args.to_json
15
+ )
14
16
  end
15
17
  end
16
18
 
@@ -27,9 +29,11 @@ command :config do |c|
27
29
  value = parts[1]
28
30
  vars[key] = value
29
31
  end
30
- @api.request :put, "/app/#{Git.first_sha}/config",
31
- vars: vars.to_json
32
-
32
+ @api.request(
33
+ :put,
34
+ "/app/#{Git.name_from_remote}/config",
35
+ vars: vars.to_json
36
+ )
33
37
  end
34
38
  end
35
39
  end
@@ -1,6 +1,11 @@
1
1
  desc 'Show logs for an app'
2
2
  command :logs do |c|
3
- c.action do |_global_options, _options, _args|
4
- API.stream_output "stream_logs.#{Git.first_sha}"
3
+
4
+ c.desc "Follow logs as new lines are created"
5
+ c.switch [:f, :follow]
6
+
7
+ c.action do |_global_options, options, _args|
8
+ follow = options[:follow] ? 'follow' : ''
9
+ API.stream_output "stream_logs.#{Git.name_from_remote} #{follow}"
5
10
  end
6
11
  end
data/lib/peas/git.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "addressable/uri"
2
+
1
3
  class Git
2
4
  def self.sh(cmd)
3
5
  `#{cmd}`.strip
@@ -7,11 +9,22 @@ class Git
7
9
  sh 'git rev-parse --show-toplevel'
8
10
  end
9
11
 
10
- def self.remote
11
- sh 'git config --get remote.origin.url'
12
+ def self.remote(remote = 'peas')
13
+ sh "git config --get remote.#{remote}.url"
14
+ end
15
+
16
+ def self.add_remote(remote)
17
+ sh "git remote add peas #{remote}"
18
+ end
19
+
20
+ def self.remove_remote(remote = 'peas')
21
+ sh "git remote rm #{remote}"
12
22
  end
13
23
 
14
- def self.first_sha
15
- sh 'git rev-list --max-parents=0 HEAD | head -n1'
24
+ def self.name_from_remote(remote_uri = nil)
25
+ remote_uri = remote unless remote_uri
26
+ exit_now! "No Peas remote. I can't figure out what app this is.", 1 if remote_uri == ''
27
+ parts = Addressable::URI.parse remote_uri
28
+ parts.path.split('/').last.gsub('.git', '')
16
29
  end
17
30
  end
data/peas-cli.gemspec CHANGED
@@ -2,16 +2,16 @@
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.2.1 ruby lib
5
+ # stub: peas-cli 0.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "peas-cli"
9
- s.version = "0.2.1"
9
+ s.version = "0.3.0"
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-08-01"
14
+ s.date = "2014-08-23"
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
17
  s.executables = ["peas"]
@@ -51,17 +51,20 @@ Gem::Specification.new do |s|
51
51
  s.add_runtime_dependency(%q<gli>, [">= 0"])
52
52
  s.add_runtime_dependency(%q<httparty>, [">= 0"])
53
53
  s.add_runtime_dependency(%q<rainbow>, [">= 0"])
54
+ s.add_runtime_dependency(%q<addressable>, [">= 0"])
54
55
  s.add_development_dependency(%q<jeweler>, [">= 0"])
55
56
  else
56
57
  s.add_dependency(%q<gli>, [">= 0"])
57
58
  s.add_dependency(%q<httparty>, [">= 0"])
58
59
  s.add_dependency(%q<rainbow>, [">= 0"])
60
+ s.add_dependency(%q<addressable>, [">= 0"])
59
61
  s.add_dependency(%q<jeweler>, [">= 0"])
60
62
  end
61
63
  else
62
64
  s.add_dependency(%q<gli>, [">= 0"])
63
65
  s.add_dependency(%q<httparty>, [">= 0"])
64
66
  s.add_dependency(%q<rainbow>, [">= 0"])
67
+ s.add_dependency(%q<addressable>, [">= 0"])
65
68
  s.add_dependency(%q<jeweler>, [">= 0"])
66
69
  end
67
70
  end
data/spec/cli_spec.rb CHANGED
@@ -3,13 +3,19 @@ require 'spec_helper'
3
3
  describe 'Peas CLI' do
4
4
  before :each do
5
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')
6
+ allow(Git).to receive(:remote).and_return('git@github.com:test-test.git')
8
7
  allow_any_instance_of(API).to receive(:sleep).and_return(nil)
9
8
  allow(Peas).to receive(:config_file).and_return('/tmp/.peas')
10
9
  File.delete '/tmp/.peas' if File.exist? '/tmp/.peas'
11
10
  end
12
11
 
12
+ describe 'App name' do
13
+ it 'should get the app name from a remote URI' do
14
+ allow(Git).to receive(:remote).and_return('git@github.com:tombh-peas.git')
15
+ expect(Git.name_from_remote).to eq 'tombh-peas'
16
+ end
17
+ end
18
+
13
19
  describe 'Settings' do
14
20
  it 'should set and use the domain setting' do
15
21
  stub_request(:put, 'http://new-domain.com:4000/admin/settings?peas.domain=new-domain.com:4000')
@@ -43,36 +49,38 @@ describe 'Peas CLI' do
43
49
  expect(output).to eq "coolapp\n"
44
50
  end
45
51
 
46
- it 'should create an app' do
47
- stub_request(:post, TEST_DOMAIN + '/app/fakesha?remote=git@github.com:test/test.git')
48
- .to_return(body: response_mock("App 'test' successfully created"))
52
+ it 'should create an app and its remote' do
53
+ public_key_path = "#{ENV['HOME']}/.ssh/id_rsa.pub"
54
+ allow(File).to receive(:open).and_call_original
55
+ expect(File).to receive(:exist?).with(public_key_path) { true }
56
+ expect(File).to receive(:open).with(public_key_path) { double(read: 'apublickey') }
57
+ stub_request(:post, TEST_DOMAIN + '/app?muse=test-test&public_key=apublickey')
58
+ .to_return(
59
+ body: {
60
+ version: Peas::VERSION,
61
+ message: "App 'test-test' successfully created",
62
+ remote_uri: 'git@peas.io:test-test.git'
63
+ }.to_json
64
+ )
65
+ allow(Git).to receive(:remote).with('peas').and_return('')
66
+ allow(Git).to receive(:remote).with('origin').and_return('git@github.com:test-test.git')
67
+ expect(Git).to receive(:add_remote).with('git@peas.io:test-test.git')
49
68
  output = cli ['create']
50
- expect(output).to eq "App 'test' successfully created\n"
69
+ expect(output).to eq "App 'test-test' successfully created\n"
51
70
  end
52
71
 
53
72
  it 'should destroy an app' do
54
- stub_request(:delete, TEST_DOMAIN + '/app/fakesha')
73
+ stub_request(:delete, TEST_DOMAIN + '/app/test-test')
55
74
  .to_return(body: response_mock("App 'test' successfully destroyed"))
75
+ expect(Git).to receive(:remove_remote)
56
76
  output = cli ['destroy']
57
77
  expect(output).to eq "App 'test' successfully destroyed\n"
58
78
  end
59
79
 
60
- it 'should deploy an app', :with_socket do
61
- stub_request(:get, /deploy/).to_return(body: '{"job": "123"}')
62
- allow(@socket).to receive(:gets).and_return(
63
- '{"body":"doing"}',
64
- '{"body":"something"}',
65
- '{"body":"done"}',
66
- '{"status":"complete"}'
67
- )
68
- output = cli %w(deploy)
69
- expect(output).to eq "doing\nsomething\ndone\n"
70
- end
71
-
72
80
  it 'should scale an app', :with_socket do
73
81
  stub_request(
74
82
  :put,
75
- TEST_DOMAIN + '/app/fakesha/scale?scaling_hash=%7B%22web%22:%223%22,%22worker%22:%222%22%7D'
83
+ TEST_DOMAIN + '/app/test-test/scale?scaling_hash=%7B%22web%22:%223%22,%22worker%22:%222%22%7D'
76
84
  ).to_return(body: '{"job": "123"}')
77
85
  allow(@socket).to receive(:gets).and_return(
78
86
  '{"body":"scaling"}',
@@ -84,21 +92,21 @@ describe 'Peas CLI' do
84
92
 
85
93
  describe 'Config ENV vars' do
86
94
  it 'should set config for an app' do
87
- stub_request(:put, TEST_DOMAIN + '/app/fakesha/config?vars=%7B%22FOO%22:%22BAR%22%7D')
95
+ stub_request(:put, TEST_DOMAIN + '/app/test-test/config?vars=%7B%22FOO%22:%22BAR%22%7D')
88
96
  .to_return(body: response_mock("{'FOO' => 'BAR'}"))
89
97
  output = cli %w(config set FOO=BAR)
90
98
  expect(output).to eq "{'FOO' => 'BAR'}\n"
91
99
  end
92
100
 
93
101
  it 'delete config for an app' do
94
- stub_request(:delete, TEST_DOMAIN + '/app/fakesha/config?keys=%5B%22FOO%22%5D')
102
+ stub_request(:delete, TEST_DOMAIN + '/app/test-test/config?keys=%5B%22FOO%22%5D')
95
103
  .to_return(body: response_mock(nil))
96
104
  output = cli %w(config rm FOO)
97
105
  expect(output).to eq "\n"
98
106
  end
99
107
 
100
108
  it 'should list all config for an app' do
101
- stub_request(:get, TEST_DOMAIN + '/app/fakesha/config')
109
+ stub_request(:get, TEST_DOMAIN + '/app/test-test/config')
102
110
  .to_return(body: response_mock("{'FOO' => 'BAR'}\n{'MOO' => 'CAR'}"))
103
111
  output = cli %w(config)
104
112
  expect(output).to eq "{'FOO' => 'BAR'}\n{'MOO' => 'CAR'}\n"
@@ -129,7 +137,7 @@ describe 'Peas CLI' do
129
137
  end
130
138
 
131
139
  it 'should show a warning when there is a version mismatch' do
132
- stub_request(:get, TEST_DOMAIN + '/app/fakesha/config')
140
+ stub_request(:get, TEST_DOMAIN + '/app/test-test/config')
133
141
  .to_return(body: '{"version": "100000.1000000.100000"}')
134
142
  output = cli %w(config)
135
143
  expect(output).to include 'Your version of the CLI client is out of date'
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,7 @@ 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://vcap.me:4000'
12
- SWITCHBOARD_TEST_PORT = 79_345
12
+ SWITCHBOARD_TEST_PORT = 79345
13
13
 
14
14
  RSpec.configure do |config|
15
15
  config.mock_with :rspec
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.2.1
4
+ version: 0.3.0
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-08-01 00:00:00.000000000 Z
11
+ date: 2014-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: addressable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: jeweler
57
71
  requirement: !ruby/object:Gem::Requirement