Sha256: 3e3ce25e246c8cddb8d2ecea5ceda8be65b5e412e2a1d99c783918ae56373f90

Contents?: true

Size: 1.75 KB

Versions: 13

Compression:

Stored size: 1.75 KB

Contents

class Indocker::ContainerDeployer
  attr_reader :server_pool

  def initialize(configuration:, logger:)
    @configuration = configuration
    @logger = logger

    @server_pool = Indocker::ServerPools::DeployServerPool.new(
      configuration: @configuration,
      logger: logger
    )

    @deployed_containers = Hash.new(false)
    @deployed_servers = {}
  end

  def deploy(container, force_restart, skip_force_restart, progress)
    return if @deployed_containers[container]

    container.servers.each do |server|
      progress.start_deploying_container(container, server)

      exec_proc = if !container.is_daemonized?
        Proc.new do |&block|
          block.call
        end
      else
        Proc.new do |&block|
          Thread.new do
            block.call
          end
        end
      end

      exec_proc.call do
        deploy_server = @server_pool.create_connection!(server)
        @logger.info("Deploying container: #{container.name.to_s.green} to #{server.user}@#{server.host}")

        result = deploy_server
          .run_container_remotely(
            configuration_name: Indocker.configuration_name,
            container_name:     container.name,
            force_restart:      force_restart && !skip_force_restart.include?(container.name)
          )

        if result.exit_code != 0
          exit 1 
        end
        
        @logger.info("Container deployment to #{server.user}@#{server.host} finished: #{container.name.to_s.green}")

        deploy_server.close_session
        progress.finish_deploying_container(container, server)
      end
    end

    @deployed_containers[container] = true
  end

  def close_sessions
    @server_pool.close_sessions
  rescue => e
    @logger.error("error during closing sessions #{e.inspect}")
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
indocker-0.3.7 lib/indocker/container_deployer.rb
indocker-0.3.6 lib/indocker/container_deployer.rb
indocker-0.3.5 lib/indocker/container_deployer.rb
indocker-0.3.4 lib/indocker/container_deployer.rb
indocker-0.3.3 lib/indocker/container_deployer.rb
indocker-0.3.2 lib/indocker/container_deployer.rb
indocker-0.1.18 lib/indocker/container_deployer.rb
indocker-0.3.1 lib/indocker/container_deployer.rb
indocker-0.3.0 lib/indocker/container_deployer.rb
indocker-0.1.17 lib/indocker/container_deployer.rb
indocker-0.1.16 lib/indocker/container_deployer.rb
indocker-0.1.14 lib/indocker/container_deployer.rb
indocker-0.1.13 lib/indocker/container_deployer.rb