Module: Cyclid::API::Plugins::Helpers::Docker

Included in:
Docker, DockerApi
Defined in:
app/cyclid/plugins/helpers/docker.rb

Overview

Module for Docker related bits within Cyclid

Instance Method Summary collapse

Instance Method Details

#create_container(name, image) ⇒ Object

Actually create the container



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/cyclid/plugins/helpers/docker.rb', line 28

def create_container(name, image)
  # Pull a suitable image
  Cyclid.logger.debug "Creating image '#{image}'"
  ::Docker::Image.create('fromImage' => image)

  # Create the container
  # XXX How do we (reliably) know what to run? /sbin/init is a good
  # guess but not bullet proof
  Cyclid.logger.debug "Creating container '#{name}'"
  container = ::Docker::Container.create('Name' => name,
                                         'Image' => image,
                                         'Cmd' => ['/sbin/init'])
  container.start

  return container
end

#get_container(id) ⇒ Object

Get information about a container



46
47
48
# File 'app/cyclid/plugins/helpers/docker.rb', line 46

def get_container(id)
  ::Docker::Container.get(id)
end

#load_docker_config(config) ⇒ Object

Load the config for the docker builder



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/cyclid/plugins/helpers/docker.rb', line 13

def load_docker_config(config)
  config.symbolize_keys!

  docker_config = config[:docker] || {}
  Cyclid.logger.debug "docker: config=#{docker_config}"

  docker_config[:api] = 'unix:///var/run/docker.sock' \
    unless docker_config.key? :api
  docker_config[:instance_name] = 'cyclid-build' \
    unless docker_config.key? :instance_name

  docker_config
end