train 3.5.5 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/train/transports/docker.rb +41 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 704c34b6ad721a82fb9259b3f3c41a550e5bc626d694d0c9e83e61d09d2cdbeb
|
4
|
+
data.tar.gz: 9bfaf284eb3eef55fc30660cc986a6805cb5a6c5fcc6bc8874faf967da69b8bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 617b0f37fd9b14baa18bf8b6ae568e19870412116cd8cf82886e5c452452a42be066764e6b801b5756e20cb28cff09406f646044a10a7ab404a63fe65e76712e
|
7
|
+
data.tar.gz: 531f7fef3b970d54422985424acb67ff8bbc828174acfea4ceb73385d44d34719715d891abd880a687da374f0035b647acf7be45b1817f2c5f460539631e42f3
|
@@ -6,6 +6,7 @@ module Train::Transports
|
|
6
6
|
|
7
7
|
include_options Train::Extras::CommandWrapper
|
8
8
|
option :host, required: true
|
9
|
+
option :docker_url, required: false
|
9
10
|
|
10
11
|
def connection(state = {}, &block)
|
11
12
|
opts = merge_options(options, state || {})
|
@@ -53,10 +54,21 @@ class Train::Transports::Docker
|
|
53
54
|
def initialize(conf)
|
54
55
|
super(conf)
|
55
56
|
@id = options[:host]
|
57
|
+
|
58
|
+
docker_url = options[:docker_url]
|
59
|
+
if RUBY_PLATFORM =~ /windows|mswin|msys|mingw|cygwin/
|
60
|
+
# Docker Desktop for windows. Must override socket location.
|
61
|
+
# https://docs.docker.com/desktop/faqs/#how-do-i-connect-to-the-remote-docker-engine-api
|
62
|
+
# docker_socket ||= "npipe:////./pipe/docker_engine" # # Doesn't require a settings change, but also doesn't work
|
63
|
+
docker_url ||= "tcp://localhost:2375"
|
64
|
+
end
|
65
|
+
Docker.url = docker_url if docker_url
|
66
|
+
|
56
67
|
@container = ::Docker::Container.get(@id) ||
|
57
68
|
raise("Can't find Docker container #{@id}")
|
58
69
|
@cmd_wrapper = nil
|
59
70
|
@cmd_wrapper = CommandWrapper.load(self, @options)
|
71
|
+
@probably_windows = nil
|
60
72
|
end
|
61
73
|
|
62
74
|
def close
|
@@ -78,6 +90,8 @@ class Train::Transports::Docker
|
|
78
90
|
Train::File::Remote::Aix.new(self, path)
|
79
91
|
elsif os.solaris?
|
80
92
|
Train::File::Remote::Unix.new(self, path)
|
93
|
+
elsif os.windows?
|
94
|
+
Train::File::Remote::Windows.new(self, path)
|
81
95
|
else
|
82
96
|
Train::File::Remote::Linux.new(self, path)
|
83
97
|
end
|
@@ -85,10 +99,16 @@ class Train::Transports::Docker
|
|
85
99
|
|
86
100
|
def run_command_via_connection(cmd, &_data_handler)
|
87
101
|
cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil?
|
102
|
+
|
103
|
+
# Cannot use os.windows? here because it calls run_command_via_connection,
|
104
|
+
# causing infinite recursion during initial platform detection
|
105
|
+
if sniff_for_windows?
|
106
|
+
invocation = cmd_run_command(cmd)
|
107
|
+
else
|
108
|
+
invocation = sh_run_command(cmd)
|
109
|
+
end
|
88
110
|
stdout, stderr, exit_status = @container.exec(
|
89
|
-
[
|
90
|
-
"/bin/sh", "-c", cmd
|
91
|
-
], user: @options[:user]
|
111
|
+
invocation, user: @options[:user]
|
92
112
|
)
|
93
113
|
CommandResult.new(stdout.join, stderr.join, exit_status)
|
94
114
|
rescue ::Docker::Error::DockerError => _
|
@@ -97,5 +117,23 @@ class Train::Transports::Docker
|
|
97
117
|
# @TODO: differentiate any other error
|
98
118
|
raise
|
99
119
|
end
|
120
|
+
|
121
|
+
def sh_run_command(cmd)
|
122
|
+
["/bin/sh", "-c", cmd]
|
123
|
+
end
|
124
|
+
|
125
|
+
def cmd_run_command(cmd)
|
126
|
+
["cmd.exe", "/s", "/c", cmd]
|
127
|
+
end
|
128
|
+
|
129
|
+
def sniff_for_windows?
|
130
|
+
return @probably_windows unless @probably_windows.nil?
|
131
|
+
|
132
|
+
# Run a command using /bin/sh, which should fail under Windows
|
133
|
+
stdout, _stderr, _exit_status = @container.exec(
|
134
|
+
sh_run_command("true"), user: @options[:user]
|
135
|
+
)
|
136
|
+
@probably_windows = !!stdout.detect { |l| l.include? "failure in a Windows system call" }
|
137
|
+
end
|
100
138
|
end
|
101
139
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: train
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef InSpec Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.6.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: 3.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: train-winrm
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|