class Deployinator::Controller
Public: the main Controller
class knows how to extract options from the options argument it gets passed from its run method and then prepares the Deploy
class to be ready to deploy.
Public Instance Methods
run(options)
click to toggle source
Public: run the actual deploy from the given parameters
Params:
options - hash that includes at least the following fields: { :username => "name of the user that is deploying", :stack => "name of the stack to deploy", :stage => "name of the stage of the stack to deploy" }
Returns nothing
# File lib/deployinator/controller.rb, line 84 def run(options) options[:method] = stage_to_method(options[:stack], options[:stage]) if options[:method].nil? raise "No method defined for me to call: #{options[:stack]}, #{options[:stage]}" end # config pus needs :env populated here options[:env] = { :username => options[:username] } if Deployinator.get_stacks.include?(options[:stack]) require "stacks/#{options[:stack]}" klass = "#{Mustache.classify(options[:stack])}Deploy" deploy_class = Deployinator::Stacks.const_get("#{klass}") else raise "No such stack #{options[:stack]}" end deploy_instance = deploy_class.new(options) deploy_instance.register_plugins(options[:stack]) locked = deploy_instance.lock_pushes(options[:stack], options[:username], options[:method]) unless locked return deploy_instance end @start_time = Time.now deploy_instance.log_and_stream "Push started at #{@start_time.to_i}\n" deploy_instance.log_and_stream "Calling #{options[:method]}\n"; deploy_instance.link_stack_logfile(deploy_instance.get_filename, options[:stack]) deploy_instance.raise_event(:deploy_start) begin state = deploy_instance.send(options[:method], options) rescue Exception => e deploy_instance.log_error("There was an exception during this deploy. Aborted!", e) deploy_instance.raise_event(:deploy_error, {:exception => e}) end if state.nil? || !state.is_a?(Hash) state = {} end deploy_instance.raise_event(:deploy_end, state) if options[:method].match(/config_push/) env = options[:method].match(/prod/) ? "production" : "princess" elsif options[:method].match(/force_builda/) env = "force asset rebuild" else env = options[:method][/(dev|qa|production|princess|prod|webs|stage|config)/i, 1] || "other" env = "production" if env.match(/prod|webs/) end # display a message that the deploy is done and call the JavaScript # deploy done function msg = "<h4>#{env.to_s.upcase} deploy in #{options[:stack]} stack complete</h4>" deploy_instance.log_and_stream(msg+"<p class='output'>") deploy_instance.log_and_stream("<script id='deploy-done'>window.deploy_done('#{msg}', '#{options[:stage]}');</script>") deploy_instance.unlock_pushes(options[:stack]) deploy_instance.move_stack_logfile(options[:stack]) return deploy_instance end
stage_to_method(stack, stage)
click to toggle source
Public: get the correct method name for the stage to deploy. This allows us to call things princess and prod even though the methods in the stacks have crazy names.
Params:
stack - the name of the stack to deploy stage - the stage of the stack to deploy
Returns the name of the deploy method as a String
which then can be sent to the Deploy
class
# File lib/deployinator/controller.rb, line 70 def stage_to_method(stack, stage) "#{stack}_#{stage}" end