class DockerApi

Attributes

connection[RW]

Public Class Methods

connection(host) click to toggle source

Build a connection to docker on a remote host. Need a connection to be able to make multiple docker calls within the app to different hosts. host: {address: “olex-qa2.openlogic.com”, docker_port: 4245 }

# File lib/support/docker_api.rb, line 29
def self.connection(host)
  cert_path = ENV['DOCKER_CERT_PATH']
  scheme = "http"
  scheme = "https" if (ENV['DOCKER_TLS_VERIFY'] == "1")
  
  docker_connection_opts = {:client_cert=>"#{cert_path}/cert.pem", :client_key=>"#{cert_path}/key.pem",
    :ssl_ca_file=>"#{cert_path}/ca.pem", :scheme => scheme}
  
  # docker_connection_opts = {:client_cert=>"/Users/mikemoore/.docker/machine/machines/dev/cert.pem", :client_key=>"/Users/mikemoore/.docker/machine/machines/dev/key.pem",
  #   :ssl_ca_file=>"/Users/mikemoore/.docker/machine/machines/dev/ca.pem", :scheme=>"https"}
  docker_connection_opts[:scheme] = "http" if (host[:ssl] == false)
  docker_connection = Docker::Connection.new("tcp://#{host[:address]}:#{host[:docker_port]}", docker_connection_opts)
  return docker_connection
end
new(url, secure = true) click to toggle source
# File lib/support/docker_api.rb, line 44
def initialize(url, secure = true)
  # Docker.logger = Logger.new(STDOUT)
  # Docker.logger.level = Logger::DEBUG
  address = url.split("//").last.split(":").first
  port = url.split(":").last
  host = {address: address, docker_port: port, ssl: secure}
  @connection = DockerApi.connection(host)
end

Public Instance Methods

find_container_with_name(wanted_name) click to toggle source
# File lib/support/docker_api.rb, line 53
def find_container_with_name(wanted_name)
  options = {
    all: true
  }
  all_containers = Docker::Container.all(options, @connection)
  all_containers.each do |container|
    json = container.json
    name = json['Name']
    return container if (name == "/#{wanted_name}")
  end
  return nil
end