class Armada::Deploy::Parallel
Attributes
environment[R]
options[R]
project[R]
Public Class Methods
new(project, environment, options)
click to toggle source
# File lib/armada/deploy/parallel.rb, line 6 def initialize(project, environment, options) @project = project @environment = environment @options = Armada::Configuration.load!(project, environment, options) @declared_hostname = @options[:hostname] end
Public Instance Methods
run()
click to toggle source
# File lib/armada/deploy/parallel.rb, line 13 def run Armada.ui.info "Deploying the following image [#{@options[:image]}:#{@options[:tag]}] in PARALLEL" begin @options[:hosts].each_in_parallel do |host| if host.is_a? String docker_host_connect_string = host health_check_host = host.split(':')[0] else docker_host_connect_string = host[:docker_host] health_check_host = host[:health_check_host] end docker_host = Armada::Host.create(docker_host_connect_string, @options) image = docker_host.get_image @options[:image], @options[:tag], @options image.pull if @declared_hostname local_options = @options else local_options = @options.merge({:hostname => health_check_host}) end container = Armada::Container.new(image, docker_host, local_options) container.stop container.start if @options[:health_check] && @options[:health_check_port] ports = container.ports # if --net=host, then there will be no ports hash. The container has direct access to the host network if ports if ports.empty? raise "No ports exposed for this container. Please expose a port for the health check or use the --no-health-check option!" end begin health_check_port = ports["#{@options[:health_check_port]}/tcp"][0]["HostPort"] rescue Exception => e raise "Could not find the host port for [#{health_check_port}]. Make sure you put the container port as the :health_check_port." end else health_check_port = @options[:health_check_port] end health_check = Armada::Connection::HealthCheck.new( health_check_host, health_check_port, @options[:health_check_endpoint], @options[:health_check_delay], @options[:health_check_retries], @options[:ssh_gateway], @options[:ssh_gateway_user] ) raise "Health check failed! - #{health_check_host}" unless health_check.run end end rescue Exception => e Armada.ui.error "#{e.message} \n\n #{e.backtrace.join("\n")}" exit(1) end end