-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.kitchen_patch.rb
56 lines (51 loc) · 1.79 KB
/
.kitchen_patch.rb
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
require 'kitchen/driver/docker'
require 'kitchen/transport/docker'
require 'kitchen/docker/helpers/image_helper'
module Kitchen
module Driver
module DockerExt
def verify_dependencies
# rubocop:disable Chef/Deprecations/UsesRunCommandHelper
# rubocop:disable Chef/Deprecations/ChefSugarHelpers
run_command("#{config[:binary]} --version >> #{dev_null} 2>&1", quiet: true, use_sudo: config[:use_sudo])
# rubocop:enable Chef/Deprecations/UsesRunCommandHelper
# rubocop:enable Chef/Deprecations/ChefSugarHelpers
rescue
raise UserError, 'You must first install the Docker CLI tool https://www.docker.com/get-started'
end
end
end
module Transport
# extend Connection with custom login_command
module ConnectionExt
# add support for kitchen login
def login_command
LoginCommand.new 'docker', [
'exec', '-it', options[:container_id], 'su', '-', 'kitchen'
]
end
end
end
module Docker
module Helpers
module ImageHelper
def parse_image_id(output)
output.each_line do |line|
if line =~ /writing image (sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i
img_id = line[/writing image (sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i, 1]
return img_id
end
if line =~ /image id|build successful|successfully (?:built|tagged)/i
img_id = line.split(/\s+/).last
return img_id
end
end
raise ActionFailed, 'Could not parse Docker build output for image ID'
end
end
end
end
end
Kitchen::Driver::Docker.include Kitchen::Driver::DockerExt
Kitchen::Transport::Docker::Connection.include Kitchen::Transport::ConnectionExt