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
# File 'lib/armada/deploy/parallel.rb', line 6

def initialize(project, environment, options)
  @project     = project
  @environment = environment
  @options     = Armada::Configuration.load!(project, environment, options)
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



12
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
# File 'lib/armada/deploy/parallel.rb', line 12

def run
  Armada.ui.info "Deploying the following image [#{@options[:image]}:#{@options[:tag]}] to these host(s) #{@options[:hosts].join(', ')} in PARALLEL"

  begin
    @options[:hosts].each_in_parallel do |host|
      docker_host = Armada::Host.create(host, options)
      image = docker_host.get_image @options[:image], @options[:tag], @options
      image.pull

      container = Armada::Container.new(image, docker_host, @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(
          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! - #{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