shelly 0.0.7 → 0.0.8
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.
- data/lib/shelly/app.rb +26 -3
- data/lib/shelly/cli/apps.rb +23 -15
- data/lib/shelly/client.rb +5 -1
- data/lib/shelly/version.rb +1 -1
- data/spec/shelly/app_spec.rb +23 -0
- data/spec/shelly/cli/apps_spec.rb +26 -6
- data/spec/shelly/client_spec.rb +12 -5
- metadata +4 -4
data/lib/shelly/app.rb
CHANGED
@@ -4,20 +4,43 @@ require 'launchy'
|
|
4
4
|
module Shelly
|
5
5
|
class App < Base
|
6
6
|
DATABASE_KINDS = %w(postgresql mongodb redis none)
|
7
|
-
attr_accessor :purpose, :code_name, :databases
|
7
|
+
attr_accessor :purpose, :code_name, :databases, :ruby_version, :environment
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@ruby_version = "MRI-1.9.2"
|
11
|
+
end
|
8
12
|
|
9
13
|
def add_git_remote
|
10
|
-
system("git remote add #{purpose}
|
14
|
+
system("git remote add #{purpose} #{git_url}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def git_url
|
18
|
+
"git@git.shellycloud.com:#{code_name}.git"
|
11
19
|
end
|
12
20
|
|
13
21
|
def generate_cloudfile
|
14
22
|
@email = current_user.email
|
15
23
|
@databases = databases
|
16
|
-
template = File.read(
|
24
|
+
template = File.read(cloudfile_template_path)
|
17
25
|
cloudfile = ERB.new(template, 0, "%<>-")
|
18
26
|
cloudfile.result(binding)
|
19
27
|
end
|
20
28
|
|
29
|
+
def cloudfile_template_path
|
30
|
+
File.join(File.dirname(__FILE__), "templates", "Cloudfile.erb")
|
31
|
+
end
|
32
|
+
|
33
|
+
def create
|
34
|
+
attributes = {
|
35
|
+
:name => code_name,
|
36
|
+
:code_name => code_name,
|
37
|
+
:environment => purpose,
|
38
|
+
:ruby_version => ruby_version,
|
39
|
+
:domain_name => "#{code_name}.shellycloud.com"
|
40
|
+
}
|
41
|
+
shelly.create_app(attributes)
|
42
|
+
end
|
43
|
+
|
21
44
|
def create_cloudfile
|
22
45
|
content = generate_cloudfile
|
23
46
|
File.open(cloudfile_path, "a+") { |f| f << content }
|
data/lib/shelly/cli/apps.rb
CHANGED
@@ -3,6 +3,7 @@ require "shelly/app"
|
|
3
3
|
module Shelly
|
4
4
|
module CLI
|
5
5
|
class Apps < Thor
|
6
|
+
include Helpers
|
6
7
|
namespace :apps
|
7
8
|
|
8
9
|
desc "add", "Adds new application to Shelly Cloud"
|
@@ -11,19 +12,23 @@ module Shelly
|
|
11
12
|
@app.purpose = ask_for_purpose
|
12
13
|
@app.code_name = ask_for_code_name
|
13
14
|
@app.databases = ask_for_databases
|
15
|
+
@app.create
|
16
|
+
say "Adding remote #{@app.purpose} #{@app.git_url}", :green
|
14
17
|
@app.add_git_remote
|
18
|
+
say "Creating Cloudfile", :green
|
15
19
|
@app.create_cloudfile
|
16
|
-
|
20
|
+
say "Provide billing details. Opening browser...", :green
|
21
|
+
@app.open_billing_page
|
17
22
|
info_adding_cloudfile_to_repository
|
18
23
|
info_deploying_to_shellycloud
|
24
|
+
rescue Client::APIError => e
|
25
|
+
if e.message == "Validation Failed"
|
26
|
+
e.errors.each { |error| say "#{error.first} #{error.last}" }
|
27
|
+
exit 1
|
28
|
+
end
|
19
29
|
end
|
20
30
|
|
21
31
|
no_tasks do
|
22
|
-
def open_billing_page
|
23
|
-
say "Provide billing details. Opening browser..."
|
24
|
-
@app.open_billing_page
|
25
|
-
end
|
26
|
-
|
27
32
|
def ask_for_purpose
|
28
33
|
purpose = ask("How will you use this system (production - default,staging):")
|
29
34
|
purpose.blank? ? "production" : purpose
|
@@ -49,18 +54,21 @@ module Shelly
|
|
49
54
|
end
|
50
55
|
|
51
56
|
def info_adding_cloudfile_to_repository
|
52
|
-
|
53
|
-
say
|
54
|
-
say
|
57
|
+
say_new_line
|
58
|
+
say "Project is now configured for use with Shell Cloud:", :green
|
59
|
+
say "You can review changes using", :green
|
60
|
+
say " git diff"
|
55
61
|
end
|
56
62
|
|
57
63
|
def info_deploying_to_shellycloud
|
58
|
-
|
59
|
-
say
|
60
|
-
say
|
61
|
-
say
|
62
|
-
say
|
63
|
-
|
64
|
+
say_new_line
|
65
|
+
say "When you make sure all settings are correct please issue following commands:", :green
|
66
|
+
say " git add ."
|
67
|
+
say ' git commit -m "Application added to Shelly Cloud"'
|
68
|
+
say " git push"
|
69
|
+
say_new_line
|
70
|
+
say "Deploy to #{@app.purpose} using:", :green
|
71
|
+
say " git push #{@app.purpose} master"
|
64
72
|
end
|
65
73
|
end
|
66
74
|
end
|
data/lib/shelly/client.rb
CHANGED
@@ -37,6 +37,10 @@ module Shelly
|
|
37
37
|
get("/token")
|
38
38
|
end
|
39
39
|
|
40
|
+
def create_app(attributes)
|
41
|
+
post("/apps", :app => attributes)
|
42
|
+
end
|
43
|
+
|
40
44
|
def post(path, params = {})
|
41
45
|
request(path, :post, params)
|
42
46
|
end
|
@@ -59,7 +63,7 @@ module Shelly
|
|
59
63
|
end
|
60
64
|
|
61
65
|
def http_basic_auth_options
|
62
|
-
@email ? {:
|
66
|
+
@email ? {:user => @email, :password => @password} : {}
|
63
67
|
end
|
64
68
|
|
65
69
|
def request_parameters(path, method, params = {})
|
data/lib/shelly/version.rb
CHANGED
data/spec/shelly/app_spec.rb
CHANGED
@@ -5,6 +5,8 @@ describe Shelly::App do
|
|
5
5
|
before do
|
6
6
|
FileUtils.mkdir_p("/projects/foo")
|
7
7
|
Dir.chdir("/projects/foo")
|
8
|
+
@client = mock(:api_url => "https://api.example.com")
|
9
|
+
Shelly::Client.stub(:new).and_return(@client)
|
8
10
|
@app = Shelly::App.new
|
9
11
|
@app.purpose = "staging"
|
10
12
|
@app.code_name = "foo-staging"
|
@@ -89,4 +91,25 @@ config
|
|
89
91
|
@app.open_billing_page
|
90
92
|
end
|
91
93
|
end
|
94
|
+
|
95
|
+
describe "#git_url" do
|
96
|
+
it "should return URL to git repository on shelly" do
|
97
|
+
@app.git_url.should == "git@git.shellycloud.com:foo-staging.git"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#create" do
|
102
|
+
it "should create the app on shelly cloud via API client" do
|
103
|
+
@app.purpose = "dev"
|
104
|
+
@app.code_name = "fooo"
|
105
|
+
@client.should_receive(:create_app).with({
|
106
|
+
:code_name => "fooo",
|
107
|
+
:name => "fooo",
|
108
|
+
:environment => "dev",
|
109
|
+
:ruby_version => "MRI-1.9.2",
|
110
|
+
:domain_name => "fooo.shellycloud.com"
|
111
|
+
})
|
112
|
+
@app.create
|
113
|
+
end
|
114
|
+
end
|
92
115
|
end
|
@@ -14,6 +14,7 @@ describe Shelly::CLI::Apps do
|
|
14
14
|
Dir.chdir("/projects/foo")
|
15
15
|
@app = Shelly::App.new
|
16
16
|
@app.stub(:add_git_remote)
|
17
|
+
@app.stub(:create)
|
17
18
|
@app.stub(:generate_cloudfile).and_return("Example Cloudfile")
|
18
19
|
@app.stub(:open_billing_page)
|
19
20
|
Shelly::App.stub(:new).and_return(@app)
|
@@ -64,7 +65,7 @@ describe Shelly::CLI::Apps do
|
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
67
|
-
it "should
|
68
|
+
it "should ask again for databases if unsupported kind typed" do
|
68
69
|
$stdout.should_receive(:print).with("Which database do you want to use postgresql, mongodb, redis, none (postgresql - default): ")
|
69
70
|
$stdout.should_receive(:print).with("Unknown database kind. Supported are: postgresql, mongodb, redis, none: ")
|
70
71
|
fake_stdin(["staging", "", "postgresql,doesnt-exist", "none"]) do
|
@@ -81,6 +82,25 @@ describe Shelly::CLI::Apps do
|
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
85
|
+
it "should create the app on shelly cloud" do
|
86
|
+
@app.should_receive(:create)
|
87
|
+
fake_stdin(["", "", ""]) do
|
88
|
+
@apps.add
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should display validation errors if they are any" do
|
93
|
+
response = {"message" => "Validation Failed", "errors" => [["code_name", "has been already taken"]]}
|
94
|
+
exception = Shelly::Client::APIError.new(response)
|
95
|
+
@app.should_receive(:create).and_raise(exception)
|
96
|
+
$stdout.should_receive(:puts).with("code_name has been already taken")
|
97
|
+
lambda {
|
98
|
+
fake_stdin(["", "", ""]) do
|
99
|
+
@apps.add
|
100
|
+
end
|
101
|
+
}.should raise_error(SystemExit)
|
102
|
+
end
|
103
|
+
|
84
104
|
it "should add git remote" do
|
85
105
|
@app.should_receive(:add_git_remote)
|
86
106
|
fake_stdin(["staging", "foooo", ""]) do
|
@@ -97,7 +117,7 @@ describe Shelly::CLI::Apps do
|
|
97
117
|
end
|
98
118
|
|
99
119
|
it "should browser window with link to edit billing information" do
|
100
|
-
$stdout.should_receive(:puts).with("
|
120
|
+
$stdout.should_receive(:puts).with("\e[32mProvide billing details. Opening browser...\e[0m")
|
101
121
|
@app.should_receive(:open_billing_page)
|
102
122
|
fake_stdin(["staging", "foooo", ""]) do
|
103
123
|
@apps.add
|
@@ -105,8 +125,8 @@ describe Shelly::CLI::Apps do
|
|
105
125
|
end
|
106
126
|
|
107
127
|
it "should display info about adding Cloudfile to repository" do
|
108
|
-
$stdout.should_receive(:puts).with("
|
109
|
-
$stdout.should_receive(:puts).with("
|
128
|
+
$stdout.should_receive(:puts).with("\e[32mProject is now configured for use with Shell Cloud:\e[0m")
|
129
|
+
$stdout.should_receive(:puts).with("\e[32mYou can review changes using\e[0m")
|
110
130
|
$stdout.should_receive(:puts).with(" git diff")
|
111
131
|
fake_stdin(["staging", "foooo", "none"]) do
|
112
132
|
@apps.add
|
@@ -114,11 +134,11 @@ describe Shelly::CLI::Apps do
|
|
114
134
|
end
|
115
135
|
|
116
136
|
it "should display info on how to deploy to ShellyCloud" do
|
117
|
-
$stdout.should_receive(:puts).with("
|
137
|
+
$stdout.should_receive(:puts).with("\e[32mWhen you make sure all settings are correct please issue following commands:\e[0m")
|
118
138
|
$stdout.should_receive(:puts).with(" git add .")
|
119
139
|
$stdout.should_receive(:puts).with(' git commit -m "Application added to Shelly Cloud"')
|
120
140
|
$stdout.should_receive(:puts).with(" git push")
|
121
|
-
$stdout.should_receive(:puts).with("
|
141
|
+
$stdout.should_receive(:puts).with("\e[32mDeploy to staging using:\e[0m")
|
122
142
|
$stdout.should_receive(:puts).with(" git push staging master")
|
123
143
|
fake_stdin(["staging", "foooo", "none"]) do
|
124
144
|
@apps.add
|
data/spec/shelly/client_spec.rb
CHANGED
@@ -45,14 +45,21 @@ describe Shelly::Client do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
describe "#create_app" do
|
49
|
+
it "should send post with app's attributes" do
|
50
|
+
@client.should_receive(:post).with("/apps", :app => {:code_name => "foo", :ruby_version => "1.9.2"})
|
51
|
+
@client.create_app(:code_name => "foo", :ruby_version => "1.9.2")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
48
55
|
describe "#request_parameters" do
|
49
56
|
it "should return hash of resquest parameters" do
|
50
57
|
expected = {
|
51
|
-
:method
|
52
|
-
:url
|
53
|
-
:headers
|
54
|
-
:payload
|
55
|
-
:
|
58
|
+
:method => :post,
|
59
|
+
:url => "#{@client.api_url}/account",
|
60
|
+
:headers => @client.headers,
|
61
|
+
:payload => {:name => "bob"}.to_json,
|
62
|
+
:user => "bob@example.com",
|
56
63
|
:password => "secret"
|
57
64
|
}
|
58
65
|
@client.request_parameters("/account", :post, :name => "bob").should == expected
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shelly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shelly Cloud team
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-04 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|