mirror of
https://github.com/inspec/inspec
synced 2024-11-27 15:10:44 +00:00
commit
0b2d14894a
1 changed files with 10 additions and 10 deletions
|
@ -20,7 +20,8 @@ class DockerRunner
|
|||
end
|
||||
|
||||
@images = docker_images_by_tag
|
||||
@image_pull = Concurrent::Promise.execute { true }
|
||||
@image_pull_tickets = Concurrent::Semaphore.new(2)
|
||||
@docker_run_tickets = Concurrent::Semaphore.new(5)
|
||||
end
|
||||
|
||||
def run_all(&block)
|
||||
|
@ -87,22 +88,18 @@ class DockerRunner
|
|||
version ||= 'latest'
|
||||
name = "#{name}:#{version}"
|
||||
end
|
||||
puts "--> schedule docker #{name}"
|
||||
|
||||
image = @images[name]
|
||||
if image.nil?
|
||||
puts "\033[35;1m--> pull docker images #{name} "\
|
||||
"(this may take a while)\033[0m"
|
||||
|
||||
pull = @image_pull.then do
|
||||
@image_pull_tickets.acquire(1)
|
||||
puts "... start pull image #{name}"
|
||||
Docker::Image.create('fromImage' => name)
|
||||
end
|
||||
cur = pull.rescue { nil }
|
||||
@image_pull = cur
|
||||
image = Docker::Image.create('fromImage' => name)
|
||||
@image_pull_tickets.release(1)
|
||||
|
||||
sleep(0.1) until cur.fulfilled?
|
||||
|
||||
image = cur.value
|
||||
unless image.nil?
|
||||
puts "\033[35;1m--> pull docker images finished for #{name}\033[0m"
|
||||
end
|
||||
|
@ -112,6 +109,8 @@ class DockerRunner
|
|||
|
||||
image, scripts = bootstrap_image(name, image)
|
||||
|
||||
@docker_run_tickets.acquire(1)
|
||||
|
||||
puts "--> start docker #{name}"
|
||||
container = Docker::Container.create(
|
||||
'Cmd' => %w{sleep 3600},
|
||||
|
@ -129,6 +128,7 @@ class DockerRunner
|
|||
end
|
||||
|
||||
def stop_container(container)
|
||||
@docker_run_tickets.release(1)
|
||||
puts "--> killrm docker #{container.id}"
|
||||
container.kill
|
||||
container.delete(force: true)
|
||||
|
|
Loading…
Reference in a new issue