-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec_helper.rb
More file actions
35 lines (29 loc) · 1.03 KB
/
spec_helper.rb
File metadata and controls
35 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Helpers
def create_image(version)
puts "Building image..."
@image = Docker::Image.build_from_dir("#{version}/")
set :os, :family => 'debian'
set :backend, :docker
set :docker_image, @image.id
puts "Running tests..."
end
def delete_image
puts "Deleting image..."
# Stop and remove only containers created from this image
Docker::Container.all(:all => true).each do |container|
container_image = container.info['Image']
container_image_id = container.info['ImageID']
# Match image IDs - container IDs may have sha256: prefix and be full hashes
# while @image.id is the short ID
if container_image&.include?(@image.id) || container_image_id&.include?(@image.id)
begin
container.stop unless container.info['State'] == 'exited'
container.delete(:force => true)
rescue Docker::Error::NotModifiedError
# Container already stopped, ignore
end
end
end
@image.remove(:force => true)
end
end