Class: Armada::Deploy::Parallel

Inherits:
Object
  • Object
show all
Defined in:
lib/armada/deploy/parallel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, environment, options) ⇒ Parallel

Returns a new instance of Parallel.



6
7
8
9
10
11
# 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

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



5
6
7
# File 'lib/armada/deploy/parallel.rb', line 5

def environment
  @environment
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/armada/deploy/parallel.rb', line 5

def options
  @options
end

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'lib/armada/deploy/parallel.rb', line 5

def project
  @project
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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
      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 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

        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