shelly 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shelly/cli/main.rb +55 -8
- data/lib/shelly/helpers.rb +14 -2
- data/lib/shelly/structure_validator.rb +44 -12
- data/lib/shelly/version.rb +1 -1
- data/spec/helpers.rb +4 -0
- data/spec/shelly/cli/main_spec.rb +59 -14
- data/spec/shelly/structure_validator_spec.rb +36 -30
- metadata +2 -2
data/lib/shelly/cli/main.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require "shelly/cli/command"
|
2
3
|
require "shelly/cli/user"
|
3
4
|
require "shelly/cli/backup"
|
@@ -81,6 +82,7 @@ module Shelly
|
|
81
82
|
desc "add", "Add a new cloud"
|
82
83
|
def add
|
83
84
|
check_options(options)
|
85
|
+
return unless check(verbose = false)
|
84
86
|
app = Shelly::App.new
|
85
87
|
app.code_name = options["code-name"] || ask_for_code_name
|
86
88
|
app.databases = options["databases"] || ask_for_databases
|
@@ -345,14 +347,59 @@ We have been notified about it. We will be adding new resources shortly}
|
|
345
347
|
say_error "Cloud #{app} is not running. Cannot run console."
|
346
348
|
end
|
347
349
|
|
348
|
-
desc "check", "
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
350
|
+
desc "check", "Check if application fulfills Shelly Cloud requirements"
|
351
|
+
# Public: Check if application fulfills shelly's requirements
|
352
|
+
# and print them
|
353
|
+
# verbose - when true all requirements will be printed out
|
354
|
+
# together with header and a summary at the end
|
355
|
+
# when false only not fulfilled requirements will be
|
356
|
+
# printed
|
357
|
+
# When any requirements is not fulfilled header and summary will
|
358
|
+
# be displayed regardless of verbose value
|
359
|
+
def check(verbose = true)
|
360
|
+
structure = Shelly::StructureValidator.new
|
361
|
+
|
362
|
+
if verbose or structure.invalid? or structure.warnings?
|
363
|
+
say "Checking Shelly Cloud requirements\n\n"
|
364
|
+
end
|
365
|
+
|
366
|
+
print_check(structure.gemfile?, "Gemfile is present",
|
367
|
+
"Gemfile is missing in git repository",
|
368
|
+
:show_fulfilled => verbose)
|
369
|
+
|
370
|
+
print_check(structure.gemfile_lock?, "Gemfile.lock is present",
|
371
|
+
"Gemfile.lock is missing in git repository",
|
372
|
+
:show_fulfilled => verbose)
|
373
|
+
|
374
|
+
print_check(structure.gem?("shelly-dependencies"),
|
375
|
+
"Gem 'shelly-dependencies' is present",
|
376
|
+
"Gem 'shelly-dependencies' is missing, we recommend to install it\n See more at https://shellycloud.com/documentation/requirements#shelly-dependencies",
|
377
|
+
:show_fulfilled => verbose || structure.warnings?, :failure_level => :warning)
|
378
|
+
|
379
|
+
print_check(structure.gem?("thin"), "Gem 'thin' is present",
|
380
|
+
"Gem 'thin' is missing in the Gemfile", :show_fulfilled => verbose)
|
381
|
+
|
382
|
+
print_check(structure.gem?("rake"), "Gem 'rake' is present",
|
383
|
+
"Gem 'rake' is missing in the Gemfile", :show_fulfilled => verbose)
|
384
|
+
|
385
|
+
print_check(structure.config_ru?, "File config.ru is present",
|
386
|
+
"File config.ru is missing",
|
387
|
+
:show_fulfilled => verbose)
|
388
|
+
|
389
|
+
print_check(!structure.gem?("mysql") && !structure.gem?("mysql2"),"",
|
390
|
+
"mysql driver present in the Gemfile (not supported on Shelly Cloud)",
|
391
|
+
:show_fulfilled => false)
|
392
|
+
|
393
|
+
if structure.valid?
|
394
|
+
if verbose
|
395
|
+
say "\nGreat! Your application is ready to run on Shelly Cloud"
|
396
|
+
end
|
397
|
+
else
|
398
|
+
say "\nFix points marked with #{red("✗")} to run your application on the Shelly Cloud"
|
399
|
+
say "See more about requirements on https://shellycloud.com/documentation/requirements"
|
400
|
+
end
|
401
|
+
|
402
|
+
structure.valid?
|
356
403
|
rescue Bundler::BundlerError => e
|
357
404
|
say_new_line
|
358
405
|
say_error e.message, :with_exit => false
|
data/lib/shelly/helpers.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module Shelly
|
2
3
|
module Helpers
|
3
4
|
def echo_disabled
|
@@ -129,8 +130,19 @@ module Shelly
|
|
129
130
|
"\e[31m#{string}\e[0m"
|
130
131
|
end
|
131
132
|
|
132
|
-
def
|
133
|
-
|
133
|
+
def yellow(string)
|
134
|
+
"\e[0;33m#{string}\e[0m"
|
135
|
+
end
|
136
|
+
|
137
|
+
def print_check(check, success_message, failure_message, options = {})
|
138
|
+
return if check && !options[:show_fulfilled]
|
139
|
+
message = check ? success_message : failure_message
|
140
|
+
indicator = if check
|
141
|
+
green("✓")
|
142
|
+
else
|
143
|
+
options[:failure_level] == :warning ? yellow("ϟ") : red("✗")
|
144
|
+
end
|
145
|
+
say " #{indicator} #{message}"
|
134
146
|
end
|
135
147
|
end
|
136
148
|
end
|
@@ -3,26 +3,58 @@ require 'bundler'
|
|
3
3
|
|
4
4
|
module Shelly
|
5
5
|
class StructureValidator
|
6
|
-
|
6
|
+
def initialize
|
7
|
+
@gemfile_path = "Gemfile"
|
8
|
+
@gemfile_lock_path = "Gemfile.lock"
|
9
|
+
end
|
10
|
+
|
11
|
+
def gemfile?
|
12
|
+
repo_paths.include?(@gemfile_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def gemfile_lock?
|
16
|
+
repo_paths.include?(@gemfile_lock_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def config_ru?
|
20
|
+
repo_paths.include?("config.ru")
|
21
|
+
end
|
22
|
+
|
23
|
+
def gem?(name)
|
24
|
+
gems.include?(name)
|
25
|
+
end
|
7
26
|
|
8
|
-
|
9
|
-
|
10
|
-
|
27
|
+
# Public: Check all requirements that app has to fulfill
|
28
|
+
def valid?
|
29
|
+
gemfile? && gemfile_lock? && gem?("thin") &&
|
30
|
+
gem?("rake") && config_ru?
|
11
31
|
end
|
12
32
|
|
13
|
-
def
|
14
|
-
|
33
|
+
def invalid?
|
34
|
+
!valid?
|
15
35
|
end
|
16
36
|
|
17
|
-
|
18
|
-
|
19
|
-
|
37
|
+
# Public: Check if there are any warnings regarding app
|
38
|
+
# structure, these warning don't prevent from deploying
|
39
|
+
# to shelly
|
40
|
+
def warnings?
|
41
|
+
!gem?("shelly-dependencies")
|
20
42
|
end
|
21
43
|
|
44
|
+
private
|
45
|
+
|
22
46
|
def gems
|
23
|
-
return [] unless
|
24
|
-
|
25
|
-
|
47
|
+
return [] unless gemfile? or gemfile_lock?
|
48
|
+
definition = Bundler::Definition.build(@gemfile_path,
|
49
|
+
@gemfile_lock_path, nil)
|
50
|
+
@gems ||= definition.specs.map(&:name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def repo_paths
|
54
|
+
@repo_paths ||= begin
|
55
|
+
repo = Grit::Repo.new(".")
|
56
|
+
repo.status.map(&:path)
|
57
|
+
end
|
26
58
|
end
|
27
59
|
end
|
28
60
|
end
|
data/lib/shelly/version.rb
CHANGED
data/spec/helpers.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require "spec_helper"
|
2
3
|
require "shelly/cli/main"
|
3
4
|
require "grit"
|
@@ -27,7 +28,7 @@ describe Shelly::CLI::Main do
|
|
27
28
|
Tasks:
|
28
29
|
shelly add # Add a new cloud
|
29
30
|
shelly backup <command> # Manage database backups
|
30
|
-
shelly check #
|
31
|
+
shelly check # Check if application fulfills Shelly Cloud requirements
|
31
32
|
shelly config <command> # Manage application configuration files
|
32
33
|
shelly console # Open application console
|
33
34
|
shelly delete # Delete the cloud
|
@@ -287,6 +288,7 @@ OUT
|
|
287
288
|
@client.stub(:token).and_return("abc")
|
288
289
|
@app.stub(:attributes).and_return({"trial" => false})
|
289
290
|
@app.stub(:git_remote_exist?).and_return(false)
|
291
|
+
@main.stub(:check => true)
|
290
292
|
end
|
291
293
|
|
292
294
|
# This spec tests inside_git_repository? hook
|
@@ -497,6 +499,24 @@ OUT
|
|
497
499
|
invoke(@main, :add)
|
498
500
|
end
|
499
501
|
end
|
502
|
+
|
503
|
+
it "should check shelly requirements" do
|
504
|
+
$stdout.should_receive(:puts) \
|
505
|
+
.with("\e[32mWhen you make sure all settings are correct please issue following commands:\e[0m")
|
506
|
+
@main.should_receive(:check).with(false).and_return(true)
|
507
|
+
fake_stdin(["foooo", "none"]) do
|
508
|
+
invoke(@main, :add)
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
it "should abort when shelly requirements are not met" do
|
513
|
+
$stdout.should_not_receive(:puts) \
|
514
|
+
.with("\e[32mWhen you make sure all settings are correct please issue following commands:\e[0m")
|
515
|
+
@main.should_receive(:check).with(false).and_return(false)
|
516
|
+
fake_stdin(["foooo", "none"]) do
|
517
|
+
invoke(@main, :add)
|
518
|
+
end
|
519
|
+
end
|
500
520
|
end
|
501
521
|
|
502
522
|
describe "#list" do
|
@@ -1268,9 +1288,10 @@ We have been notified about it. We will be adding new resources shortly")
|
|
1268
1288
|
describe "#check" do
|
1269
1289
|
before do
|
1270
1290
|
Shelly::App.stub(:inside_git_repository?).and_return(true)
|
1271
|
-
Bundler::Definition.stub_chain(:build, :specs, :map)
|
1272
|
-
|
1273
|
-
|
1291
|
+
Bundler::Definition.stub_chain(:build, :specs, :map) \
|
1292
|
+
.and_return(["thin"])
|
1293
|
+
Grit::Repo.stub_chain(:new, :status, :map) \
|
1294
|
+
.and_return(["config.ru", "Gemfile", "Gemfile.lock"])
|
1274
1295
|
end
|
1275
1296
|
|
1276
1297
|
it "should ensure user is in git repository" do
|
@@ -1279,37 +1300,52 @@ We have been notified about it. We will be adding new resources shortly")
|
|
1279
1300
|
|
1280
1301
|
context "when gemfile exists" do
|
1281
1302
|
it "should show that Gemfile exists" do
|
1282
|
-
$stdout.should_receive(:puts).with(" #{green("
|
1303
|
+
$stdout.should_receive(:puts).with(" #{green("✓")} Gemfile is present")
|
1304
|
+
invoke(@main, :check)
|
1305
|
+
end
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
context "when gemfile doesn't exist" do
|
1309
|
+
it "should show that Gemfile doesn't exist" do
|
1310
|
+
Grit::Repo.stub_chain(:new, :status, :map).and_return([])
|
1311
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} Gemfile is missing in git repository")
|
1312
|
+
invoke(@main, :check)
|
1313
|
+
end
|
1314
|
+
end
|
1315
|
+
|
1316
|
+
context "when gemfile exists" do
|
1317
|
+
it "should show that Gemfile exists" do
|
1318
|
+
$stdout.should_receive(:puts).with(" #{green("✓")} Gemfile is present")
|
1283
1319
|
invoke(@main, :check)
|
1284
1320
|
end
|
1285
1321
|
end
|
1286
1322
|
|
1287
1323
|
context "when gemfile doesn't exist" do
|
1288
1324
|
it "should show that Gemfile doesn't exist" do
|
1289
|
-
|
1290
|
-
$stdout.should_receive(:puts).with(" #{red("
|
1325
|
+
Grit::Repo.stub_chain(:new, :status, :map).and_return([])
|
1326
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} Gemfile is missing in git repository")
|
1291
1327
|
invoke(@main, :check)
|
1292
1328
|
end
|
1293
1329
|
end
|
1294
1330
|
|
1295
1331
|
context "when thin gem exists" do
|
1296
1332
|
it "should show that necessary gem exists" do
|
1297
|
-
$stdout.should_receive(:puts).with(" #{green("
|
1333
|
+
$stdout.should_receive(:puts).with(" #{green("✓")} Gem 'thin' is present")
|
1298
1334
|
invoke(@main, :check)
|
1299
1335
|
end
|
1300
1336
|
end
|
1301
1337
|
|
1302
1338
|
context "when thin gem doesn't exist" do
|
1303
|
-
it "should show that necessary gem
|
1339
|
+
it "should show that necessary gem doesn't exist" do
|
1304
1340
|
Bundler::Definition.stub_chain(:build, :specs, :map).and_return([])
|
1305
|
-
$stdout.should_receive(:puts).with(" #{red("
|
1341
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} Gem 'thin' is missing in the Gemfile")
|
1306
1342
|
invoke(@main, :check)
|
1307
1343
|
end
|
1308
1344
|
end
|
1309
1345
|
|
1310
1346
|
context "when config.ru exists" do
|
1311
1347
|
it "should show that config.ru exists" do
|
1312
|
-
$stdout.should_receive(:puts).with(" #{green("
|
1348
|
+
$stdout.should_receive(:puts).with(" #{green("✓")} File config.ru is present")
|
1313
1349
|
invoke(@main, :check)
|
1314
1350
|
end
|
1315
1351
|
end
|
@@ -1317,7 +1353,7 @@ We have been notified about it. We will be adding new resources shortly")
|
|
1317
1353
|
context "when config.ru doesn't exist" do
|
1318
1354
|
it "should show that config.ru is neccessary" do
|
1319
1355
|
Grit::Repo.stub_chain(:new, :status, :map).and_return([])
|
1320
|
-
$stdout.should_receive(:puts).with(" #{red("
|
1356
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} File config.ru is missing")
|
1321
1357
|
invoke(@main, :check)
|
1322
1358
|
end
|
1323
1359
|
end
|
@@ -1325,13 +1361,13 @@ We have been notified about it. We will be adding new resources shortly")
|
|
1325
1361
|
context "when mysql gem exists" do
|
1326
1362
|
it "should show that mysql gem is not supported by Shelly Cloud" do
|
1327
1363
|
Bundler::Definition.stub_chain(:build, :specs, :map).and_return(["mysql"])
|
1328
|
-
$stdout.should_receive(:puts).with(" #{red("
|
1364
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} mysql driver present in the Gemfile (not supported on Shelly Cloud)")
|
1329
1365
|
invoke(@main, :check)
|
1330
1366
|
end
|
1331
1367
|
|
1332
1368
|
it "should show that mysql2 gem is not supported by Shelly Cloud" do
|
1333
1369
|
Bundler::Definition.stub_chain(:build, :specs, :map).and_return(["mysql2"])
|
1334
|
-
$stdout.should_receive(:puts).with(" #{red("
|
1370
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} mysql driver present in the Gemfile (not supported on Shelly Cloud)")
|
1335
1371
|
invoke(@main, :check)
|
1336
1372
|
end
|
1337
1373
|
end
|
@@ -1347,5 +1383,14 @@ We have been notified about it. We will be adding new resources shortly")
|
|
1347
1383
|
}.should raise_error(SystemExit)
|
1348
1384
|
end
|
1349
1385
|
end
|
1386
|
+
|
1387
|
+
it "should display only errors and warnings when in verbose mode" do
|
1388
|
+
$stdout.should_not_receive(:puts).with(" #{green("✓")} Gem 'thin' is present")
|
1389
|
+
$stdout.should_receive(:puts).with(" #{yellow("ϟ")} Gem 'shelly-dependencies' is missing, we recommend to install it\n See more at https://shellycloud.com/documentation/requirements#shelly-dependencies")
|
1390
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} Gem 'rake' is missing in the Gemfile")
|
1391
|
+
$stdout.should_receive(:puts).with("\nFix points marked with #{red("✗")} to run your application on the Shelly Cloud")
|
1392
|
+
$stdout.should_receive(:puts).with("See more about requirements on https://shellycloud.com/documentation/requirements")
|
1393
|
+
@main.check(false)
|
1394
|
+
end
|
1350
1395
|
end
|
1351
1396
|
end
|
@@ -2,71 +2,77 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Shelly::StructureValidator do
|
4
4
|
before do
|
5
|
-
File.open("Gemfile", 'w')
|
6
|
-
File.open("config.ru", 'w')
|
7
5
|
@validator = Shelly::StructureValidator.new
|
6
|
+
Grit::Repo.stub_chain(:new, :status).and_return([
|
7
|
+
mock(:path => "Gemfile"), mock(:path => "Gemfile.lock")
|
8
|
+
])
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
describe "#gemfile?" do
|
12
|
+
context "when Gemfile exists" do
|
13
|
+
it "should return true" do
|
14
|
+
@validator.gemfile?.should == true
|
15
|
+
end
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
context "when Gemfile doesn't exist" do
|
19
|
+
it "should return false" do
|
20
|
+
Grit::Repo.stub_chain(:new, :status) \
|
21
|
+
.and_return([mock(:path => "Gemfile.lock")])
|
22
|
+
@validator.gemfile?.should == false
|
23
|
+
end
|
24
|
+
end
|
16
25
|
end
|
17
26
|
|
18
|
-
describe "#
|
19
|
-
context "when Gemfile exists" do
|
27
|
+
describe "#gemfile_lock?" do
|
28
|
+
context "when Gemfile.lock exists" do
|
20
29
|
it "should return true" do
|
21
|
-
@validator.
|
30
|
+
@validator.gemfile_lock?.should == true
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
|
-
context "when Gemfile doesn't exist" do
|
34
|
+
context "when Gemfile.lock doesn't exist" do
|
26
35
|
it "should return false" do
|
27
|
-
|
28
|
-
|
36
|
+
Grit::Repo.stub_chain(:new, :status) \
|
37
|
+
.and_return([mock(:path => "Gemfile")])
|
38
|
+
@validator.gemfile_lock?.should == false
|
29
39
|
end
|
30
40
|
end
|
31
41
|
end
|
32
42
|
|
33
|
-
describe "#
|
43
|
+
describe "#config_ru?" do
|
34
44
|
before do
|
35
|
-
|
36
|
-
|
45
|
+
Grit::Repo.stub_chain(:new, :status) \
|
46
|
+
.and_return([mock(:path => "config.ru")])
|
37
47
|
end
|
38
48
|
|
39
49
|
context "when config.ru exists" do
|
40
50
|
it "should return true" do
|
41
|
-
@validator.
|
51
|
+
@validator.config_ru?.should == true
|
42
52
|
end
|
43
53
|
end
|
44
54
|
|
45
55
|
context "when config.ru doesn't exist" do
|
46
56
|
it "should return false" do
|
47
57
|
Grit::Repo.stub_chain(:new, :status).and_return([])
|
48
|
-
@validator.
|
58
|
+
@validator.config_ru?.should == false
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end
|
52
62
|
|
53
|
-
describe "#
|
63
|
+
describe "#gem?" do
|
54
64
|
before do
|
55
|
-
@
|
56
|
-
|
65
|
+
@validator.stub(:gemfile? => true, :gemfile_lock? => true)
|
66
|
+
Bundler::Definition.stub_chain(:build, :specs).and_return(
|
67
|
+
[mock(:name => "thin"), mock(:name => "mysql")])
|
57
68
|
end
|
58
69
|
|
59
|
-
it "should return
|
60
|
-
|
61
|
-
Bundler::Definition.should_receive(:build).with("Gemfile", "Gemfile.lock", nil)
|
62
|
-
@validator.gems.should == ["thin", "mysql"]
|
70
|
+
it "should return true if gem is present" do
|
71
|
+
@validator.gem?("thin").should be_true
|
63
72
|
end
|
64
73
|
|
65
|
-
|
66
|
-
|
67
|
-
File.delete("Gemfile")
|
68
|
-
@validator.gems.should == []
|
69
|
-
end
|
74
|
+
it "should return false if gem is missing" do
|
75
|
+
@validator.gem?("rake").should be_false
|
70
76
|
end
|
71
77
|
end
|
72
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shelly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|