Class: AethernalAgent::Docker::ContainerSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/aethernal_agent/docker/container_settings.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject

Returns the value of attribute env.



4
5
6
# File 'lib/aethernal_agent/docker/container_settings.rb', line 4

def env
  @env
end

#port_bindingsObject

Returns the value of attribute port_bindings.



4
5
6
# File 'lib/aethernal_agent/docker/container_settings.rb', line 4

def port_bindings
  @port_bindings
end

#volumesObject

Returns the value of attribute volumes.



4
5
6
# File 'lib/aethernal_agent/docker/container_settings.rb', line 4

def volumes
  @volumes
end

Class Method Details

.build_from_options(manifest_options, opts) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/aethernal_agent/docker/container_settings.rb', line 5

def self.build_from_options(manifest_options, opts)
  container = ContainerSettings.new
  container.env = Env.create_from_options(manifest_options, opts).collect(&:to_docker)
  container.port_bindings = PortBinding.create_from_options(manifest_options, opts)
  container.volumes = Volume.create_from_options(manifest_options, opts).collect(&:to_docker)
  return container
end

Instance Method Details

#create_container(name, image) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aethernal_agent/docker/container_settings.rb', line 13

def create_container(name, image)
  AethernalAgent.logger.debug("Creating Docker container #{name} from image #{image} based on ContainerSettings")
  AethernalAgent.logger.debug("Env: #{self.env}, Ports; #{self.port_bindings}, Volumes: #{self.volumes}")

  ::Docker::Container.create(
    'name' => name,
    'Env' => self.env,
    'HostConfig' =>
    {
      'RestartPolicy' => {'Name' => 'unless-stopped'},
      'PortBindings' => self.port_bindings,
      'Binds' => self.volumes,
      'Volumes' => {"/data" => {},"/config" => {}},
    },
    'Image' => image,
    'Healthcheck' => {'Interval' => 120_000_000_000, 'StartPeriod' => 30_000_000_000}
  )
end