Class: Cyclid::API::Plugins::Docker

Inherits:
Builder show all
Includes:
Helpers::Docker
Defined in:
app/cyclid/plugins/builder/docker.rb

Overview

Docker builder, uses the Docker API to create a build host container

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Docker

#create_container, #get_container, #load_docker_config

Methods inherited from Builder

human_name

Methods inherited from Base

author, config?, config_schema, default_config, get_config, homepage, human_name, license, register_plugin, set_config, update_config, version

Constructor Details

#initializeDocker

Returns a new instance of Docker.



35
36
37
38
39
40
# File 'app/cyclid/plugins/builder/docker.rb', line 35

def initialize
  @config = load_docker_config(
    Cyclid.config.plugins
  )
  ::Docker.url = @config[:api]
end

Class Method Details

.metadataObject

Plugin metadata



88
89
90
91
92
93
# File 'app/cyclid/plugins/builder/docker.rb', line 88

def self.
  super.merge!(version: Cyclid::Api::VERSION,
               license: 'Apache-2.0',
               author: 'Liqwyd Ltd.',
               homepage: 'http://docs.cyclid.io')
end

Instance Method Details

#get(args = {}) ⇒ Object

Create and return a build host



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/cyclid/plugins/builder/docker.rb', line 43

def get(args = {})
  args.symbolize_keys!

  Cyclid.logger.debug "docker: args=#{args}"

  # If there is one, split the 'os' into a 'distro' and 'release'
  if args.key? :os
    match = args[:os].match(/\A(\w*)_(.*)\Z/)
    distro = match[1] if match
    release = match[2] if match
  else
    # No OS was specified; use the default
    # XXX Defaults should be configurable
    distro = 'ubuntu'
    release = 'trusty'
  end

  # Find the image for the given distribution & release
  image_alias = "#{distro}:#{release}"
  Cyclid.logger.debug "image_alias=#{image_alias}"

  # Create a new instance
  name = create_name
  container = create_container(name, image_alias)

  Cyclid.logger.debug "container=#{container}"

  # Create a buildhost from the container details
  DockerHost.new(
    host: container.id,
    name: name,
    username: 'root',
    workspace: '/root',
    distro: distro,
    release: release
  )
end

#release(_transport, buildhost) ⇒ Object

Destroy the container when done



82
83
84
85
# File 'app/cyclid/plugins/builder/docker.rb', line 82

def release(_transport, buildhost)
  container = get_container(buildhost[:host])
  container.delete(force: true)
end