shelly 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2YwOTIzMzE5M2NiZWVkMTEwMWY5YWYxYjdjZThkMTNhODJhNTUzYw==
4
+ ZGJlZjY2MmJjZjJmNWNhYjgyODg3NjA2ODNhYzk2NzRmMjY0NzdjOQ==
5
5
  data.tar.gz: !binary |-
6
- Nzg1NGJjZWRmYmE4ZjEwOGY1MzI0MGVjZTI3ZGEzY2Q4NDhlM2RjYg==
6
+ MTNmY2VkZWUyMjhmYzU5MTFhZDRkYTNjMmM2ZTRiNGJkNzY4NWJhNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDY4OWM4MDExNWJmMTI4ZWJiODE0MzRmZDY0ZmI2ZDgyMzMxZjZhZTczOTY4
10
- MjQ0ZDU1Y2Y2NzZmM2VlMjU2ZjlhOTQ5MWQ1M2MwOTQ2YTU3ZDdlOGQ3MmU5
11
- NWNkNDQ2NmM5YzRmYjRhMTQwMjNhNzg5ODZmYWFhM2Q0Yjk4NDA=
9
+ YmU2NzhkNWJkYzNlMjMwNGFjMGIxN2ZhNWI0YTdlZjk3ZjVlOTk3M2I3MWNm
10
+ OTMxZDNlMWFjN2FlODQ2MTgxMWU4MDFkYmNkZDIyYjdhODhhMGFiNDkxODcy
11
+ YzMwYjVlZmQyZjk0MzNmYWQxYTRkNWIzNTZhYmQ1YzgwNzQ1NTA=
12
12
  data.tar.gz: !binary |-
13
- YzJiNWY1ZmViNzI1OWZlY2E5MDMwYzExNjVhMDA1Y2QzZTA2Yzg0NTBkYTA3
14
- ZjBlM2MyZDhiM2I4NzVhMzQ3ZjIxYTgwMTc5MjA0OWJjNjJiODEwZDc1NTVh
15
- OTE1NTA3NDBhNWM5NzYxNTllZjViOGI2ODIyYjlkODc1NWYwNWE=
13
+ ODdmZjg1NzcyNzI0YWE5ODI1MDc1MWE0MmVhYmRhNTI3YjJjMDA5OTgxMWNk
14
+ Njc5YjRkYWRmNmI3NDU5Y2Y5OWViOTMzOGZiNzBiYTFmNTQ3ZjFkNjFjZTI0
15
+ YjIyMjY4ZjgwZWI2NjJmNDk5Njg0YzExOTQyNWE1NzlkMjk0N2E=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.4.1 / 2013-08-26
2
+
3
+ * [feature] Upload existing config file with `shelly config upload PATH`
4
+ * [improvement] Reorganised displaying deploy logs
5
+ * [improvement] Show next action depending on cloud state when adding configuration file
6
+
1
7
  ## 0.4.0 / 2013-08-13
2
8
 
3
9
  * [feature] Added `shelly organization add` to create new organizations
data/lib/shelly/app.rb CHANGED
@@ -191,6 +191,10 @@ module Shelly
191
191
  shelly.app_delete_config(code_name, path)
192
192
  end
193
193
 
194
+ def config_exists?(path)
195
+ configs.any? { |config| config["path"] == path }
196
+ end
197
+
194
198
  def rake(task)
195
199
  ssh(:command => "rake_runner \"#{task}\"")
196
200
  end
@@ -243,6 +247,10 @@ module Shelly
243
247
  system("git status > /dev/null 2>&1")
244
248
  end
245
249
 
250
+ def turned_off?
251
+ state == 'turned_off'
252
+ end
253
+
246
254
  def to_s
247
255
  code_name
248
256
  end
@@ -6,8 +6,10 @@ module Shelly
6
6
  namespace :config
7
7
  include Helpers
8
8
 
9
- before_hook :logged_in?, :only => [:list, :show, :create, :new, :edit, :update, :delete]
10
- class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
9
+ before_hook :logged_in?, :only => [:list, :show, :create, :new, :edit,
10
+ :update, :upload, :delete]
11
+ class_option :cloud, :type => :string, :aliases => "-c",
12
+ :desc => "Specify cloud"
11
13
 
12
14
  desc "list", "List configuration files"
13
15
  def list
@@ -51,8 +53,7 @@ module Shelly
51
53
  app = multiple_clouds(options[:cloud], "create #{path}")
52
54
  app.create_config(path, output)
53
55
  say "File '#{path}' created.", :green
54
- say "To make changes to running application redeploy it using:"
55
- say "`shelly redeploy --cloud #{app}`"
56
+ next_action_info(app)
56
57
  rescue Client::ValidationException => e
57
58
  e.each_error { |error| say_error error, :with_exit => false }
58
59
  exit 1
@@ -67,8 +68,7 @@ module Shelly
67
68
  content = open_editor(config["path"], config["content"])
68
69
  app.update_config(path, content)
69
70
  say "File '#{config["path"]}' updated.", :green
70
- say "To make changes to running application redeploy it using:"
71
- say "`shelly redeploy --cloud #{app}`"
71
+ next_action_info(app)
72
72
  rescue Client::NotFoundException => e
73
73
  raise unless e.resource == :config
74
74
  say_error "Config '#{path}' not found", :with_exit => false
@@ -84,8 +84,7 @@ module Shelly
84
84
  if yes?("Are you sure you want to delete '#{path}' (yes/no):")
85
85
  app.delete_config(path)
86
86
  say "File '#{path}' deleted.", :green
87
- say "To make changes to running application redeploy it using:"
88
- say "`shelly redeploy --cloud #{app}`"
87
+ next_action_info(app)
89
88
  else
90
89
  say "File not deleted"
91
90
  end
@@ -95,7 +94,46 @@ module Shelly
95
94
  say_error "You can list available config files with `shelly config list --cloud #{app}`"
96
95
  end
97
96
 
97
+ desc "upload PATH [DESTINATION_PATH]", "Upload configuration file"
98
+ long_desc %{
99
+ Upload configuration file from local machine
100
+ PATH - Path to configuration file that will be uploaded
101
+ DESTINATION_PATH - Optional file path that file will be uploaded to. By default it's the same as PATH.
102
+ }
103
+ def upload(path, destination_path = nil)
104
+ app = multiple_clouds(options[:cloud], "config upload #{path}")
105
+ destination_path ||= path
106
+ if ::File.exists?(path)
107
+ content = ::File.read(path)
108
+ else
109
+ say_error "File '#{path}' doesn't exist."
110
+ end
111
+ if app.config_exists?(destination_path)
112
+ if yes?("Config file '#{destination_path}' exists, do you want to overwrite it (yes/no):")
113
+ app.update_config(destination_path, content)
114
+ say "File '#{path}' uploaded.", :green
115
+ next_action_info(app)
116
+ else
117
+ say "File not overwritten."
118
+ end
119
+ else
120
+ app.create_config(destination_path, content)
121
+ say "File '#{path}' uploaded.", :green
122
+ next_action_info(app)
123
+ end
124
+ end
125
+
98
126
  no_tasks do
127
+ def next_action_info(app)
128
+ if app.turned_off?
129
+ say "Changes will take affect when cloud is started"
130
+ say "`shelly start --cloud #{app}`"
131
+ else
132
+ say "To make changes to running cloud redeploy it using:"
133
+ say "`shelly redeploy --cloud #{app}`"
134
+ end
135
+ end
136
+
99
137
  def print_configs(configs)
100
138
  print_table(configs.map { |config|
101
139
  [" * ", config["path"]] })
@@ -43,12 +43,6 @@ module Shelly
43
43
  if content["bundle_install"]
44
44
  say("Starting bundle install", :green); say(content["bundle_install"])
45
45
  end
46
- if content["whenever"]
47
- say("Starting whenever", :green); say(content["whenever"])
48
- end
49
- if content["callbacks"]
50
- say("Starting callbacks", :green); say(content["callbacks"])
51
- end
52
46
  if content["delayed_job"]
53
47
  say("Starting delayed job", :green); say(content["delayed_job"])
54
48
  end
@@ -61,6 +55,12 @@ module Shelly
61
55
  if content["puma_restart"]
62
56
  say("Starting puma", :green); say(content["puma_restart"])
63
57
  end
58
+ if content["callbacks"]
59
+ say("Starting callbacks", :green); say(content["callbacks"])
60
+ end
61
+ if content["whenever"]
62
+ say("Starting whenever", :green); say(content["whenever"])
63
+ end
64
64
  else
65
65
  say_error("There was an error and log is not available", :with_exit => false)
66
66
  say_error("Please contact our support https://shellycloud.com/support")
@@ -1,3 +1,3 @@
1
1
  module Shelly
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -97,6 +97,20 @@ describe Shelly::App do
97
97
  @client.should_receive(:app_delete_config).with("foo-staging", "path")
98
98
  @app.delete_config("path")
99
99
  end
100
+
101
+ describe "#config_exists?" do
102
+ before do
103
+ @client.stub(:app_configs => config_response)
104
+ end
105
+
106
+ it "should return true when config exists" do
107
+ @app.config_exists?("user_created").should be_true
108
+ end
109
+
110
+ it "should return false when config doesn't exist" do
111
+ @app.config_exists?("some/config").should be_false
112
+ end
113
+ end
100
114
  end
101
115
 
102
116
  describe "#attributes" do
@@ -185,6 +199,13 @@ describe Shelly::App do
185
199
  end
186
200
  end
187
201
 
202
+ describe "#turned_off?" do
203
+ it "should return true if cloud state is turned_off" do
204
+ @client.should_receive(:app).and_return({'state' => 'turned_off'})
205
+ @app.turned_off?.should be_true
206
+ end
207
+ end
208
+
188
209
  describe "#deploy_logs" do
189
210
  it "should list deploy_logs" do
190
211
  @client.should_receive(:deploy_logs).with("foo-staging")
@@ -14,6 +14,7 @@ describe Shelly::CLI::Config do
14
14
  FileUtils.mkdir_p("/projects/foo")
15
15
  Dir.chdir("/projects/foo")
16
16
  @client.stub(:authorize!)
17
+ @client.stub(:app).and_return('state' => 'running')
17
18
  File.open("Cloudfile", 'w') {|f| f.write("foo-production:\n") }
18
19
  FileUtils.mkdir_p("/tmp")
19
20
  Dir.stub(:tmpdir).and_return("/tmp")
@@ -96,7 +97,6 @@ describe Shelly::CLI::Config do
96
97
  # multiple_clouds is tested in main_spec.rb in describe "#start" block
97
98
  it "should ensure multiple_clouds check" do
98
99
  @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
99
- @app = Shelly::App.new("foo-production")
100
100
  Shelly::App.stub(:new).and_return(@app)
101
101
  @client.should_receive(:app_create_config).with("foo-production", "path", "\n").and_return({})
102
102
  @config.should_receive(:multiple_clouds).and_return(@app)
@@ -109,13 +109,27 @@ describe Shelly::CLI::Config do
109
109
  lambda { invoke(@config, :create, "path") }.should raise_error(SystemExit)
110
110
  end
111
111
 
112
- it "should create file" do
113
- @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
114
- @client.should_receive(:app_create_config).with("foo-production", "path", "\n").and_return({})
115
- $stdout.should_receive(:puts).with(green "File 'path' created.")
116
- $stdout.should_receive(:puts).with("To make changes to running application redeploy it using:")
117
- $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-production`")
118
- invoke(@config, :create, "path")
112
+ context "cloud running" do
113
+ it "should create file" do
114
+ @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
115
+ @client.should_receive(:app_create_config).with("foo-production", "path", "\n").and_return({})
116
+ $stdout.should_receive(:puts).with(green "File 'path' created.")
117
+ $stdout.should_receive(:puts).with("To make changes to running cloud redeploy it using:")
118
+ $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-production`")
119
+ invoke(@config, :create, "path")
120
+ end
121
+ end
122
+
123
+ context "cloud turned off" do
124
+ it "should print " do
125
+ @client.stub(:app).and_return('state' => 'turned_off')
126
+ @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
127
+ @client.should_receive(:app_create_config).with("foo-production", "path", "\n").and_return({})
128
+ $stdout.should_receive(:puts).with(green "File 'path' created.")
129
+ $stdout.should_receive(:puts).with("Changes will take affect when cloud is started")
130
+ $stdout.should_receive(:puts).with("`shelly start --cloud foo-production`")
131
+ invoke(@config, :create, "path")
132
+ end
119
133
  end
120
134
 
121
135
  context "on validation errors" do
@@ -162,8 +176,7 @@ describe Shelly::CLI::Config do
162
176
  @config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
163
177
  @client.should_receive(:app_update_config).with("foo-production", "path", "example content\n").and_return({"path" => "test.rb", "content" => "example content"})
164
178
  $stdout.should_receive(:puts).with(green "File 'test.rb' updated.")
165
- $stdout.should_receive(:puts).with("To make changes to running application redeploy it using:")
166
- $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-production`")
179
+ @config.should_receive(:next_action_info)
167
180
  invoke(@config, :edit, "path")
168
181
  end
169
182
 
@@ -211,8 +224,7 @@ describe Shelly::CLI::Config do
211
224
  @client.should_receive(:app_delete_config).with("foo-production", "some-path").and_return({})
212
225
  $stdout.should_receive(:print).with("Are you sure you want to delete 'some-path' (yes/no): ")
213
226
  $stdout.should_receive(:puts).with(green "File 'some-path' deleted.")
214
- $stdout.should_receive(:puts).with("To make changes to running application redeploy it using:")
215
- $stdout.should_receive(:puts).with("`shelly redeploy --cloud foo-production`")
227
+ @config.should_receive(:next_action_info)
216
228
  fake_stdin(["y"]) do
217
229
  invoke(@config, :delete, "some-path")
218
230
  end
@@ -242,4 +254,53 @@ describe Shelly::CLI::Config do
242
254
  end
243
255
  end
244
256
  end
257
+
258
+ describe "#upload" do
259
+ before do
260
+ @config.stub(:multiple_clouds => @app)
261
+ end
262
+
263
+ it "should ensure user has logged in" do
264
+ hooks(@config, :upload).should include(:logged_in?)
265
+ end
266
+
267
+ it "should upload given configuration file" do
268
+ File.open("upload_me", "w") { |f| f << "upload_me_content" }
269
+ @app.stub(:config_exists? => false)
270
+ @app.should_receive(:create_config).with("upload_me", "upload_me_content").and_return({})
271
+ $stdout.should_receive(:puts).with(green "File 'upload_me' uploaded.")
272
+ invoke(@config, :upload, "upload_me")
273
+ end
274
+
275
+ context "when destination path given" do
276
+ it "should upload to given path" do
277
+ File.open("upload_me", "w") { |f| f << "upload_me_content" }
278
+ @app.stub(:config_exists? => false)
279
+ @app.should_receive(:create_config).with("put/it/here", "upload_me_content").and_return({})
280
+ $stdout.should_receive(:puts).with(green "File 'upload_me' uploaded.")
281
+ invoke(@config, :upload, "upload_me", "put/it/here")
282
+ end
283
+ end
284
+
285
+ context "when source path doesn't exist" do
286
+ it "should show error" do
287
+ @app.stub(:config_exists? => false)
288
+ @app.should_not_receive(:create_config)
289
+ $stdout.should_receive(:puts).with(red "File 'upload_me' doesn't exist.")
290
+ lambda { invoke(@config, :upload, "upload_me") }.should raise_error(SystemExit)
291
+ end
292
+ end
293
+
294
+ context "when destination path exists" do
295
+ it "should ask if overwrite" do
296
+ File.open("upload_me", "w") { |f| f << "upload_me_content" }
297
+ @app.stub(:config_exists? => true)
298
+ @app.should_receive(:update_config).with("upload_me", "upload_me_content").and_return({})
299
+ $stdout.should_receive(:puts).with(green "File 'upload_me' uploaded.")
300
+ fake_stdin(["y"]) do
301
+ invoke(@config, :upload, "upload_me")
302
+ end
303
+ end
304
+ end
305
+ end
245
306
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shelly Cloud team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-13 00:00:00.000000000 Z
11
+ date: 2013-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec