manifests-vmc-plugin 0.2.2 → 0.2.3

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.
@@ -1,5 +1,5 @@
1
1
  require "vmc/plugin"
2
- require File.expand_path("../../manifests-vmc-plugin", __FILE__)
2
+ require "manifests-vmc-plugin"
3
3
 
4
4
  VMC.Plugin do
5
5
  class_option :manifest,
@@ -14,8 +14,7 @@ VMC.Plugin(VMC::App) do
14
14
 
15
15
  # basic commands that, when given no args, act on the
16
16
  # app(s) described by the manifest, in dependency-order
17
- [:start, :instances, :scale, :logs,
18
- :file, :files, :health, :stats].each do |wrap|
17
+ [:start, :instances, :logs, :file, :files, :health, :stats].each do |wrap|
19
18
  around(wrap) do |cmd, args|
20
19
  if args.empty? && !passed_value(:name)
21
20
  each_app do |a|
@@ -100,64 +99,63 @@ VMC.Plugin(VMC::App) do
100
99
  around(:push) do |push, args|
101
100
  name = passed_value(:name) || args.first
102
101
 
102
+ use_name =
103
+ if apps = manifest["applications"]
104
+ apps.size == 1
105
+ else
106
+ # legacy single-app manifest
107
+ true
108
+ end
109
+
103
110
  all_pushed =
104
- each_app do |a|
105
- next if name && a["name"] != name
106
-
107
- app = client.app(a["name"])
108
- updating = app.exists?
109
-
110
- sync_changes(a)
111
- push.call(
112
- :name => a["name"],
113
- :start => false,
114
- :bind_services => false,
115
- :create_services => false)
116
-
117
- unless updating
118
- app.env = a["env"]
119
-
120
- if input(:start)
121
- with_inputs(:name => a["name"]) do
122
- start
123
- end
124
- else
125
- app.update!
126
- end
111
+ each_app do |info|
112
+ next if !use_name && name && info["name"] != name
113
+
114
+ app_name = use_name ? name : info["name"]
115
+
116
+ app = client.app(app_name)
117
+
118
+ sync_changes(info)
119
+
120
+ with_filters(:push_app => proc { |a| setup_app(a, info); a }) do
121
+ push.call(
122
+ :name => app_name,
123
+ :bind_services => false,
124
+ :create_services => false)
127
125
  end
128
126
 
129
127
  puts "" unless simple_output?
130
128
  end
131
129
 
132
130
  unless all_pushed
133
- begin
131
+ bound = []
132
+
133
+ with_filters(:push_app => proc { |a| ask_to_save(a); a}) do
134
134
  push.call
135
- ensure
136
- meta = {
137
- "name" => passed_value(:name) || args.first,
138
- "framework" => passed_value(:framework),
139
- "runtime" => passed_value(:runtime),
140
- "memory" => passed_value(:memory),
141
- "instances" => passed_value(:instances).to_i,
142
- "url" => passed_value(:url)
143
- }
144
-
145
- if cmd = passed_value(:command)
146
- meta["command"] = cmd
147
- end
135
+ end
136
+ end
137
+ end
148
138
 
149
- unless manifest_file || meta.any? { |k, v| v.nil? }
150
- puts ""
139
+ # need to do this specially so it doesn't call it with the instance/memory
140
+ # flags set (via each_app), which would cause it to do nothing
141
+ around(:scale) do |cmd, args|
142
+ if args.empty? && !passed_value(:name)
143
+ apps = []
144
+ has_manifest =
145
+ each_app do |a|
146
+ apps << a["name"]
147
+ end
151
148
 
152
- if ask("Save configuration?", :default => false)
153
- File.open("manifest.yml", "w") do |io|
154
- YAML.dump(
155
- {"applications" => {(options[:path] || ".") => meta}},
156
- io)
157
- end
158
- end
149
+ if has_manifest
150
+ apps.each do |name|
151
+ cmd.call(:name => name)
152
+ puts "" unless simple_output?
159
153
  end
154
+ else
155
+ cmd.call
160
156
  end
157
+ else
158
+ cmd.call
161
159
  end
162
160
  end
163
161
  end
@@ -1,3 +1,3 @@
1
1
  module VMCManifests
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -209,14 +209,15 @@ module VMCManifests
209
209
  # inputs for each app
210
210
  def each_app
211
211
  given_path = passed_value(:path)
212
+ full_path = given_path && File.expand_path(given_path)
212
213
 
213
214
  if manifest and all_apps = manifest["applications"]
215
+ use_inputs = all_apps.size == 1
216
+
214
217
  # given a specific application
215
218
  if given_path
216
- full_path = File.expand_path(given_path)
217
-
218
219
  if info = app_info(full_path)
219
- with_app(full_path, info) do
220
+ with_app(full_path, info, use_inputs) do
220
221
  yield info
221
222
  end
222
223
  else
@@ -228,7 +229,7 @@ module VMCManifests
228
229
  app = File.expand_path(path, File.dirname(manifest_file))
229
230
  info = app_info(app)
230
231
 
231
- with_app(app, info) do
232
+ with_app(app, info, use_inputs) do
232
233
  yield info
233
234
  end
234
235
  end
@@ -238,7 +239,7 @@ module VMCManifests
238
239
 
239
240
  # manually created or legacy single-app manifest
240
241
  elsif single = toplevel_attributes
241
- with_app(full_path || ".", single) do
242
+ with_app(full_path || ".", single, true) do
242
243
  yield single
243
244
  end
244
245
 
@@ -252,14 +253,16 @@ module VMCManifests
252
253
  private
253
254
 
254
255
  # call the block as if the app info and path were given as flags
255
- def with_app(path, info, &blk)
256
+ def with_app(path, info, use_inputs = false, &blk)
256
257
  inputs = {:path => path}
257
258
  info.each do |k, v|
258
- if k == "mem"
259
- k = "memory"
259
+ input = k.to_sym
260
+
261
+ if input == :mem
262
+ input = :memory
260
263
  end
261
264
 
262
- inputs[k.to_sym] = v
265
+ inputs[input] = use_inputs && passed_value(input) || v
263
266
  end
264
267
 
265
268
  with_inputs(inputs, &blk)
@@ -319,14 +322,15 @@ module VMCManifests
319
322
  case k
320
323
  when /ur[li]s?/
321
324
  old = app.urls
322
- if old != Array(v)
323
- diff[k] = [old, v]
324
- app.urls = Array(v)
325
+ new = Array(v)
326
+ if old != new
327
+ diff["urls"] = [old.inspect, new.inspect]
328
+ app.urls = new
325
329
  end
326
330
  when "env"
327
331
  old = app.env
328
332
  if old != v
329
- diff[k] = [old, v]
333
+ diff[k] = [old.inspect, v.inspect]
330
334
  app.env = v
331
335
  end
332
336
  when "framework", "runtime", "command"
@@ -345,8 +349,9 @@ module VMCManifests
345
349
  when "mem", "memory"
346
350
  old = app.memory
347
351
  new = megabytes(v)
352
+
348
353
  if old != new
349
- diff["memory"] = [old, new]
354
+ diff["memory"] = [human_size(old * 1024 * 1024, 0), v]
350
355
  app.memory = new
351
356
  end
352
357
  end
@@ -359,7 +364,7 @@ module VMCManifests
359
364
  diff.each do |k, d|
360
365
  old, new = d
361
366
  label = c(k, need_restage.include?(k) ? :bad : :good)
362
- puts " #{label}: #{old.inspect} #{c("->", :dim)} #{new.inspect}"
367
+ puts " #{label}: #{old} #{c("->", :dim)} #{new}"
363
368
  end
364
369
 
365
370
  puts ""
@@ -389,4 +394,72 @@ module VMCManifests
389
394
  end
390
395
  end
391
396
  end
397
+
398
+ def ask_to_save(app)
399
+ return if manifest_file
400
+
401
+ services = app.services.collect { |name| client.service(name) }
402
+
403
+ meta = {
404
+ "name" => app.name,
405
+ "framework" => app.framework,
406
+ "runtime" => app.runtime,
407
+ "memory" => human_size(app.memory, 0),
408
+ "instances" => app.total_instances,
409
+ "url" => app.url
410
+ }
411
+
412
+ unless services.empty?
413
+ meta["services"] = {}
414
+
415
+ services.each do |s|
416
+ meta["services"][s.name] = {
417
+ "vendor" => s.vendor,
418
+ "version" => s.version
419
+ }
420
+ end
421
+ end
422
+
423
+ if cmd = app.command
424
+ meta["command"] = cmd
425
+ end
426
+
427
+ if ask("Save configuration?", :default => false)
428
+ File.open("manifest.yml", "w") do |io|
429
+ YAML.dump(
430
+ {"applications" => {(options[:path] || ".") => meta}},
431
+ io)
432
+ end
433
+
434
+ puts "Saved to #{c("manifest.yml", :name)}."
435
+ end
436
+ end
437
+
438
+ def setup_app(app, info)
439
+ app.env = info["env"]
440
+
441
+ return if !info["services"] || info["services"].empty?
442
+
443
+ services = client.system_services
444
+
445
+ info["services"].each do |name, svc|
446
+ service = client.service(name)
447
+
448
+ unless service.exists?
449
+ service.vendor = svc["vendor"] || svc["type"]
450
+
451
+ service_meta = services[service.vendor]
452
+
453
+ service.type = service_meta[:type]
454
+ service.version = svc["version"] || service_meta[:versions].first
455
+ service.tier = "free"
456
+
457
+ with_progress("Creating service #{c(service.name, :name)}") do
458
+ service.create!
459
+ end
460
+ end
461
+ end
462
+
463
+ app.services = info["services"].keys
464
+ end
392
465
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manifests-vmc-plugin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-14 00:00:00 Z
18
+ date: 2012-06-21 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: