Sha256: 1238412ca69ab717a75997ed27b013158988f3d671eda8cb4c166041f0e806ff

Contents?: true

Size: 961 Bytes

Versions: 8

Compression:

Stored size: 961 Bytes

Contents

module Percheron
  class DockerConnection

    def initialize(config)
      @config = config
    end

    def setup!
      set_url!
      set_options!
    end

    private

      attr_reader :config

      def cert_path
        @cert_path ||= ENV['DOCKER_CERT_PATH'] ? File.expand_path(ENV['DOCKER_CERT_PATH']) : nil
      end

      def set_url!
        Docker.url = config.docker.host
      end

      def set_options!
        Docker.options = docker_options
      end

      def docker_options
        base_docker_options.merge(extra_docker_opts)
      end

      def base_docker_options
        { connect_timeout: config.docker.timeout }
      end

      def extra_docker_opts
        if cert_path
          {
            client_cert:  File.join(cert_path, 'cert.pem'),
            client_key:   File.join(cert_path, 'key.pem'),
            ssl_ca_file:  File.join(cert_path, 'ca.pem')
          }
        else
          {}
        end
      end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
percheron-0.6.4 lib/percheron/docker_connection.rb
percheron-0.6.3 lib/percheron/docker_connection.rb
percheron-0.6.2 lib/percheron/docker_connection.rb
percheron-0.6.1 lib/percheron/docker_connection.rb
percheron-0.6.0 lib/percheron/docker_connection.rb
percheron-0.5.0 lib/percheron/docker_connection.rb
percheron-0.4.0 lib/percheron/docker_connection.rb
percheron-0.3.2 lib/percheron/docker_connection.rb