docker-api 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docker/exec.rb +1 -1
- data/lib/docker/util.rb +45 -16
- data/lib/docker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc1628fd247f468eade6265726036edfe62cf330a3f0be35f24359af395dc4b4
|
4
|
+
data.tar.gz: 29a503b4ac556125534508256dbea71f6acc1a3612b24c1ae204cbd93a83ba04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e0478393e9624e3b206c4578a1a2449843da15bcbceb70520a708ce4a9e8a493a13dd5c6d0e8d3b2b71e1256a4770eb3cb1568471985fd3f52fb703e03ac20e
|
7
|
+
data.tar.gz: 14022d379e3e2dade67ffcd6ce12e56f9e12b65eb00e1906e579561262963fde36181b955526bfbd24c47baba3b4dfee15475c980e7f5bda4bff64ecf8e36859
|
data/lib/docker/exec.rb
CHANGED
@@ -21,7 +21,7 @@ class Docker::Exec
|
|
21
21
|
container = options.delete('Container')
|
22
22
|
|
23
23
|
# Podman does not attach these by default but does require them to be attached
|
24
|
-
if ::Docker.podman?
|
24
|
+
if ::Docker.podman?(conn)
|
25
25
|
options['AttachStderr'] = true if options['AttachStderr'].nil?
|
26
26
|
options['AttachStdout'] = true if options['AttachStdout'].nil?
|
27
27
|
end
|
data/lib/docker/util.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
# This module holds shared logic that doesn't really belong anywhere else in the
|
2
4
|
# gem.
|
3
5
|
module Docker::Util
|
4
6
|
# http://www.tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm#STANDARD-WILDCARDS
|
5
|
-
GLOB_WILDCARDS = /[\?\*\[\{]/
|
7
|
+
GLOB_WILDCARDS = /[\?\*\[\{\]\}]/
|
6
8
|
|
7
9
|
include Docker::Error
|
8
10
|
|
@@ -142,10 +144,35 @@ module Docker::Util
|
|
142
144
|
File.new(tempfile.path, 'r')
|
143
145
|
end
|
144
146
|
|
147
|
+
|
148
|
+
# return the set of files that form the docker context
|
149
|
+
# implement this logic https://docs.docker.com/engine/reference/builder/#dockerignore-file
|
150
|
+
def docker_context(directory)
|
151
|
+
all_files = glob_all_files(File.join(directory, "**/*"))
|
152
|
+
dockerignore = File.join(directory, '.dockerignore')
|
153
|
+
return all_files unless all_files.include?(dockerignore)
|
154
|
+
|
155
|
+
# Iterate over valid lines, starting with the initial glob as working set
|
156
|
+
File
|
157
|
+
.read(dockerignore) # https://docs.docker.com/engine/reference/builder/#dockerignore-file
|
158
|
+
.each_line # "a newline-separated list of patterns"
|
159
|
+
.map(&:strip) # "A preprocessing step removes leading and trailing whitespace"
|
160
|
+
.reject(&:empty?) # "Lines that are blank after preprocessing are ignored"
|
161
|
+
.reject { |p| p.start_with?('#') } # "if [a line starts with `#`], then this line is considered as a comment"
|
162
|
+
.each_with_object(Set.new(all_files)) do |p, working_set|
|
163
|
+
# determine the pattern (p) and whether it is to be added or removed from context
|
164
|
+
add = p.start_with?("!")
|
165
|
+
# strip leading "!" from pattern p, then prepend the base directory
|
166
|
+
matches = dockerignore_compatible_glob(File.join(directory, add ? p[1..-1] : p))
|
167
|
+
# add or remove the matched items as indicated in the ignore file
|
168
|
+
add ? working_set.merge(matches) : working_set.replace(working_set.difference(matches))
|
169
|
+
end
|
170
|
+
.to_a
|
171
|
+
end
|
172
|
+
|
145
173
|
def create_relative_dir_tar(directory, output)
|
146
174
|
Gem::Package::TarWriter.new(output) do |tar|
|
147
|
-
files =
|
148
|
-
remove_ignored_files!(directory, files)
|
175
|
+
files = docker_context(directory)
|
149
176
|
|
150
177
|
files.each do |prefixed_file_name|
|
151
178
|
stat = File.stat(prefixed_file_name)
|
@@ -259,21 +286,23 @@ module Docker::Util
|
|
259
286
|
}
|
260
287
|
end
|
261
288
|
|
262
|
-
|
263
|
-
|
289
|
+
# do a directory glob that matches .dockerignore behavior
|
290
|
+
# specifically: matched directories are considered a recursive match
|
291
|
+
def dockerignore_compatible_glob(pattern)
|
292
|
+
begin
|
293
|
+
some_dirs, some_files = glob_all_files(pattern).partition { |f| File.directory?(f) }
|
294
|
+
# since all directories will be re-processed with a /**/* glob, we can preemptively
|
295
|
+
# eliminate any whose parent directory is already in this set. This saves significant time.
|
296
|
+
some_files + some_dirs.reject { |d| some_dirs.any? { |pd| d.start_with?(pd) && d != pd } }
|
297
|
+
end.each_with_object(Set.new) do |f, acc|
|
298
|
+
# expand any directories by globbing; flatten results
|
299
|
+
acc.merge(File.directory?(f) ? glob_all_files("#{f}/**/*") : [f])
|
300
|
+
end
|
264
301
|
end
|
265
302
|
|
266
|
-
def
|
267
|
-
|
268
|
-
|
269
|
-
ignored_files(directory, ignore).each { |f| files.delete(f) }
|
303
|
+
def glob_all_files(pattern)
|
304
|
+
# globs of "a_dir/**/*" can return "a_dir/.", so explicitly reject those
|
305
|
+
(Dir.glob(pattern, File::FNM_DOTMATCH) - ['..', '.']).reject { |p| p.end_with?("/.") }
|
270
306
|
end
|
271
307
|
|
272
|
-
def ignored_files(directory, ignore_file)
|
273
|
-
patterns = File.read(ignore_file).split("\n").each(&:strip!)
|
274
|
-
patterns.reject! { |p| p.empty? || p.start_with?('#') }
|
275
|
-
patterns.map! { |p| File.join(directory, p) }
|
276
|
-
patterns.map! { |p| File.directory?(p) ? "#{p}/**/*" : p }
|
277
|
-
patterns.flat_map { |p| p =~ GLOB_WILDCARDS ? glob_all_files(p) : p }
|
278
|
-
end
|
279
308
|
end
|
data/lib/docker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Swipely, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|