class BubBot::DeployManager
Public Instance Methods
branches(target_name)
click to toggle source
# File lib/bub_bot/deploy_manager.rb, line 53 def branches(target_name) Repo.branches(target(target_name)['git']) end
deploy(server, target_name, branch)
click to toggle source
# File lib/bub_bot/deploy_manager.rb, line 6 def deploy(server, target_name, branch) if DeployState[server, target_name].deploying? raise RespondableError.new("A deploy to #{target_name} on #{server} is already in progress. Not deploying.") end begin DeployState[server, target_name].set(true) target_config = target(target_name, server) unless deploy_config = target_config['deploy'] raise "Missing deploy config for #{target_name}" end locals = { server: server } # Handle each type of deploy here. # TODO: maybe handle multiple deploys for each target? Right now the # workaround to do that is to just have a script-type deploy that does that. if deploy_git_remote = deploy_config['git'] repo(target_name, server).push(branch, deploy_git_remote) elsif deploy_script = deploy_config['script'] puts "xdeploying web script #{deploy_script}" repo = repo(target_name, server) puts "Checking out..." repo.checkout(branch) puts "Pulling..." repo.pull puts "Running script..." success = Kernel.system("./#{deploy_script} #{repo.repo_dir} #{branch} #{server}") puts "Success = #{success}" unless success raise RespondableError.new("Deploy script failed for server #{server} and target #{target_name}") end elsif deploy_url = deploy_config['http'] raise RespondableError.new('Sorry, deploys by http request are not supported yet') end ensure DeployState[server, target_name].set(false) end end
target_names()
click to toggle source
# File lib/bub_bot/deploy_manager.rb, line 49 def target_names targets.keys - ['all'] end
Private Instance Methods
get_binding(variables)
click to toggle source
Gets a binding object with the given variables defined in it. You'd think there'd be a simpler way. Well, ok, there is, but there's no simpler way that doesn't also polute the binding with variables from the outer scope.
# File lib/bub_bot/deploy_manager.rb, line 77 def get_binding(variables) obj = Class.new { attr_accessor *variables.keys def get_binding(); binding end }.new variables.each { |name, value| obj.public_send(:"#{name}=", value) } obj.get_binding end
repo(target_name, server)
click to toggle source
# File lib/bub_bot/deploy_manager.rb, line 59 def repo(target_name, server) @repos ||= {} target = target(target_name, server) @repos[target_name + '__' + server] ||= Repo.new(target_name, target['git'], server) end
target(target_name, server = nil)
click to toggle source
Returns a hash of config data for the target with this name
# File lib/bub_bot/deploy_manager.rb, line 66 def target(target_name, server = nil) targets(server).find { |name, _| name == target_name }.last end
targets(server = nil)
click to toggle source
# File lib/bub_bot/deploy_manager.rb, line 70 def targets(server = nil) BubBot.configuration.deploy_targets(server: server) end