Class: MobyDerp::Pod
- Inherits:
-
Object
- Object
- MobyDerp::Pod
- Includes:
- LoggingHelpers
- Defined in:
- lib/moby_derp/pod.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #common_environment ⇒ Object
- #common_labels ⇒ Object
- #common_mounts ⇒ Object
- #expose ⇒ Object
- #hostname ⇒ Object
-
#initialize(pod_config) ⇒ Pod
constructor
A new instance of Pod.
- #mount_root ⇒ Object
- #name ⇒ Object
- #network_name ⇒ Object
- #root_container_id ⇒ Object
- #root_labels ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(pod_config) ⇒ Pod
Returns a new instance of Pod.
10 11 12 13 |
# File 'lib/moby_derp/pod.rb', line 10 def initialize(pod_config) @config = pod_config @logger = pod_config.logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/moby_derp/pod.rb', line 8 def logger @logger end |
Instance Method Details
#common_environment ⇒ Object
69 70 71 |
# File 'lib/moby_derp/pod.rb', line 69 def common_environment @config.common_environment end |
#common_labels ⇒ Object
61 62 63 |
# File 'lib/moby_derp/pod.rb', line 61 def common_labels @config.common_labels end |
#common_mounts ⇒ Object
73 74 75 |
# File 'lib/moby_derp/pod.rb', line 73 def common_mounts @config.common_mounts end |
#expose ⇒ Object
89 90 91 |
# File 'lib/moby_derp/pod.rb', line 89 def expose @config.expose end |
#hostname ⇒ Object
85 86 87 |
# File 'lib/moby_derp/pod.rb', line 85 def hostname @config.hostname end |
#mount_root ⇒ Object
77 78 79 |
# File 'lib/moby_derp/pod.rb', line 77 def mount_root @config.mount_root end |
#name ⇒ Object
48 49 50 |
# File 'lib/moby_derp/pod.rb', line 48 def name @config.name end |
#network_name ⇒ Object
81 82 83 |
# File 'lib/moby_derp/pod.rb', line 81 def network_name @config.network_name end |
#root_container_id ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/moby_derp/pod.rb', line 52 def root_container_id if @root_container_id.nil? raise MobyDerp::BugError, "root_container_id requested before root container was spawned" else @root_container_id end end |
#root_labels ⇒ Object
65 66 67 |
# File 'lib/moby_derp/pod.rb', line 65 def root_labels @config.root_labels end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/moby_derp/pod.rb', line 15 def run @logger.info(logloc) { "Checking root container" } @root_container_id = root_container.run @logger.debug(logloc) { "Root container ID is #{@root_container_id}" } desired_container_names = @config.containers.map(&:name) Docker::Container.all(all: true).each do |c| c_name = c.info["Names"].first.sub(/^\//, '') if c.info["Labels"]["org.hezmatt.moby-derp.pod-name"] == name && !c.info["Labels"]["org.hezmatt.moby-derp.root-container-id"].nil? && !desired_container_names.include?(c_name) @logger.info(logloc) { "Removing stale container #{c_name}" } c.stop c.delete end end @config.containers.each do |cfg| @logger.info(logloc) { "Checking container #{cfg.name}" } begin MobyDerp::Container.new(pod: self, container_config: cfg).run rescue MobyDerp::ContainerError => ex @logger.error(logloc) { (["Error while running container #{cfg.name}: #{ex.}"] + ex.backtrace.map { |l| " #{l}" }).join("\n") } end end end |