Class: DevDock::DevBinds
- Inherits:
-
Object
- Object
- DevDock::DevBinds
- Defined in:
- lib/dev_dock/binds.rb
Instance Method Summary collapse
-
#container? ⇒ Boolean
check if we’re currently running inside of a container.
- #create ⇒ Object
-
#initialize(list) ⇒ DevBinds
constructor
A new instance of DevBinds.
- #internal_volumes ⇒ Object
- #list ⇒ Object
- #push(item) ⇒ Object
Constructor Details
#initialize(list) ⇒ DevBinds
Returns a new instance of DevBinds.
61 62 63 64 65 |
# File 'lib/dev_dock/binds.rb', line 61 def initialize(list) @internal_volumes = nil @container = nil @list = list end |
Instance Method Details
#container? ⇒ Boolean
check if we’re currently running inside of a container
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/dev_dock/binds.rb', line 94 def container? if @container.nil? if File.exist?('/proc/1/cgroup') @container = File.read('/proc/1/cgroup').include?('docker') else @container = false end end @container end |
#create ⇒ Object
105 106 107 108 109 |
# File 'lib/dev_dock/binds.rb', line 105 def create list.each do |bind| bind.create end end |
#internal_volumes ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dev_dock/binds.rb', line 67 def internal_volumes if container? and @internal_volumes.nil? container_id = File.read('/proc/1/cgroup') .lines .find { |cgroup| cgroup.include?('docker') } .split('/') .last .strip container = Docker::Container.get(container_id) @internal_volumes = container.json['Volumes'] end @internal_volumes end |
#list ⇒ Object
82 83 84 85 86 87 |
# File 'lib/dev_dock/binds.rb', line 82 def list @list.map do |item| source, target, = item.split(':') DevBind.new(internal_volumes, source, target, ) end end |
#push(item) ⇒ Object
89 90 91 |
# File 'lib/dev_dock/binds.rb', line 89 def push(item) @list.push(item) end |