lib/stackfu/commands/deploy_command.rb in stackfu-0.1.2.2 vs lib/stackfu/commands/deploy_command.rb in stackfu-0.1.3
- old
+ new
@@ -60,11 +60,11 @@
return unless target and server
yield target
params = fill_values_from_options(target, options)
- names = target.controls.map(&:name)
+ names = target.controls ? target.controls.map(&:name) : []
review = params.any?
if (names - params.keys.map(&:to_s)).any?
puts "Please configure your deployment by answering the configuration settings below."
puts ""
@@ -92,33 +92,57 @@
end
server_id = server.id
server.id = server.slug
deployment = server.post(:deploy, {}, { :id => server_id, :script_id => target.slug, :params => params }.to_json)
+ deployment = JSON.parse(deployment.body)
if options[:"no-follow"]
puts "Your deployment have been submitted"
return
end
+
+ puts ""
+ puts "Waiting for the server..."
verbose = options[:verbose]
- # from = nil
- # while true
- # opts = {:formatted => "true", :from => from}
- # opts.merge!(:verbose => "true") if verbose
- #
- # status = spinner {
- # Deployment.find(deployment.id).get(:logs, opts)
- # }
- #
- # if status["id"]
- # show_log status["log"]
- # from = status["id"]
- # end
- #
- # break if status["state"] == "finished" or status["state"] == "failed"
- # end
+ from = nil
+ last_status = 'queued'
+ while true
+ opts = {}
+ opts['from_id'] = from if from
+
+ logs = spinner {
+ Deployment.new(:id => deployment['_id']).get(:logs, opts)
+ }
+
+ status = logs['status']
+ if status != last_status
+ if status == 'running'
+ puts ""
+ puts "---------- " + " SCRIPT STARTED ".foreground(:white).bright.background(:blue) + " ----------"
+ puts ""
+ elsif status == 'finished'
+ puts ""
+ puts "---------- " + " SCRIPT FINISHED ".foreground(:white).bright.background(:blue) + " ----------"
+ end
+ last_status = status
+ end
+
+ from = logs["last_id"]
+ print logs["contents"]
+
+ break if logs["status"] == "finished" or logs["status"] == "failed"
+ end
+
+ puts ""
+
+ if logs["status"] == 'finished'
+ puts "Deployment finished: " + " SUCCESS ".foreground(:white).bright.background(:green)
+ else
+ puts "Deployment failed".foreground(:red)
+ end
end
def show_log(logs)
logs.each do |s|
\ No newline at end of file