Class: Deployinator::Controller
- Inherits:
-
Object
- Object
- Deployinator::Controller
- Defined in:
- lib/deployinator/controller.rb
Overview
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.
Instance Method Summary collapse
-
#run(options) ⇒ Object
Public: run the actual deploy from the given parameters.
-
#stage_to_method(stack, stage) ⇒ Object
Public: get the correct method name for the stage to deploy.
Instance Method Details
#run(options) ⇒ Object
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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/deployinator/controller.rb', line 84 def run() [:method] = stage_to_method([:stack], [:stage]) if [:method].nil? raise "No method defined for me to call: #{[:stack]}, #{[:stage]}" end # config pus needs :env populated here [:env] = { :username => [:username] } if Deployinator.get_stacks.include?([:stack]) require "stacks/#{[:stack]}" klass = "#{Mustache.classify([:stack])}Deploy" deploy_class = Deployinator::Stacks.const_get("#{klass}") else raise "No such stack #{[:stack]}" end deploy_instance = deploy_class.new() deploy_instance.register_plugins([:stack]) locked = deploy_instance.lock_pushes([:stack], [:username], [: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 #{[:method]}\n"; deploy_instance.link_stack_logfile(deploy_instance.get_filename, [:stack]) deploy_instance.raise_event(:deploy_start) begin state = deploy_instance.send([:method], ) 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 [:method].match(/config_push/) env = [:method].match(/prod/) ? "production" : "princess" elsif [:method].match(/force_builda/) env = "force asset rebuild" else env = [: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 #{[: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}', '#{[:stage]}');</script>") deploy_instance.unlock_pushes([:stack]) deploy_instance.move_stack_logfile([:stack]) return deploy_instance end |
#stage_to_method(stack, stage) ⇒ Object
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
70 71 72 |
# File 'lib/deployinator/controller.rb', line 70 def stage_to_method(stack, stage) "#{stack}_#{stage}" end |