extended Docker::Container with utility methods
This commit is contained in:
1
config/initializers/mixins.rb
Normal file
1
config/initializers/mixins.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
Docker::Container::send(:include, DockerContainerMixin)
|
@ -62,11 +62,9 @@ class DockerClient
|
|||||||
|
|
||||||
def self.destroy_container(container)
|
def self.destroy_container(container)
|
||||||
container.stop.kill
|
container.stop.kill
|
||||||
if container.json['HostConfig']['PortBindings']
|
(container.port_bindings.try(:values) || []).each do |configuration|
|
||||||
container.json['HostConfig']['PortBindings'].values.each do |configuration|
|
port = configuration.first['HostPort'].to_i
|
||||||
port = configuration.first['HostPort'].to_i
|
PortPool.release(port)
|
||||||
PortPool.release(port)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
container.delete(force: true)
|
container.delete(force: true)
|
||||||
end
|
end
|
||||||
|
9
lib/docker_container_mixin.rb
Normal file
9
lib/docker_container_mixin.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module DockerContainerMixin
|
||||||
|
def binds
|
||||||
|
json['HostConfig']['Binds']
|
||||||
|
end
|
||||||
|
|
||||||
|
def port_bindings
|
||||||
|
json['HostConfig']['PortBindings']
|
||||||
|
end
|
||||||
|
end
|
11
spec/lib/docker_container_mixin_spec.rb
Normal file
11
spec/lib/docker_container_mixin_spec.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe DockerContainerMixin do
|
||||||
|
[:binds, :port_bindings].each do |method|
|
||||||
|
describe "##{method}" do
|
||||||
|
it 'is defined for Docker::Container' do
|
||||||
|
expect(Docker::Container.instance_methods).to include(method)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user