Class: Navy::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/navy/container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Container

Returns a new instance of Container.



4
5
6
7
8
# File 'lib/navy/container.rb', line 4

def initialize(options = {})
  @specification = options[:specification] || {}
  @dependencies = options[:dependencies] || []
  @logger = options[:logger] || Navy::Logger.new
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



2
3
4
# File 'lib/navy/container.rb', line 2

def dependencies
  @dependencies
end

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/navy/container.rb', line 2

def options
  @options
end

#specificationObject (readonly)

Returns the value of attribute specification.



2
3
4
# File 'lib/navy/container.rb', line 2

def specification
  @specification
end

Instance Method Details

#appObject



18
19
20
# File 'lib/navy/container.rb', line 18

def app
  specification[:name]
end

#can_be_started?(etcd) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/navy/container.rb', line 22

def can_be_started?(etcd)
  dependencies.each do |dep|
    return false unless desired?(etcd, dep)
  end
  true
end

#can_never_be_started?(etcd) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/navy/container.rb', line 29

def can_never_be_started?(etcd)
  dependencies.each do |dep|
    return true if errored?(etcd, dep)
  end
  false
end

#daemon?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/navy/container.rb', line 10

def daemon?
  specification[:type] == "application"
end

#nameObject



14
15
16
# File 'lib/navy/container.rb', line 14

def name
  specification[:container_name]
end

#startObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/navy/container.rb', line 36

def start
  if daemon?
    cmd = command_builder.build
    Navy::Runner.launch(cmd)
  else
    commands.each do |command|
      cmd = command_builder.build :command => command
      success = Navy::Runner.launch(cmd, :logger => @logger)
      return false unless success
    end
    true
  end
end

#stopObject



50
51
52
53
# File 'lib/navy/container.rb', line 50

def stop
  cmd = ["docker rm -f", name]
  Navy::Runner.launch(cmd)
end