docker_core 0.0.20 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/docker_core.rb +83 -42
- 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: 1ffc945fc5a13ce10567d97bdfda12a6f040ca26fb922f2e48b2537ae358aba6
|
4
|
+
data.tar.gz: 8814b75c42cf5e9793bbf4dcda92bde88d11e9bcf7cabd07cb14110d64bf6b7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcce5fd8318a6d5e3795ac2da04f1f33a0dc84213ca919c47207834e9189ac489a28b291391ec2c9ed3817fa69cdd75107424fa90e7064f5243c92effc3db74a
|
7
|
+
data.tar.gz: 941379233235b53f26b4b630166b64fcb2cce08b1db259e7ea6e4ba0a1d08ef4111c21899f167123c9a29919c7c5adb9ccd495e66d3b9f3c4e51884de748819d
|
data/lib/docker_core.rb
CHANGED
@@ -7,6 +7,7 @@ require('thor')
|
|
7
7
|
require('zlib')
|
8
8
|
|
9
9
|
module DockerCore
|
10
|
+
SUDO = false
|
10
11
|
USER = 'core'
|
11
12
|
GROUP = 'core'
|
12
13
|
|
@@ -56,15 +57,20 @@ module DockerCore
|
|
56
57
|
|
57
58
|
if hash.is_a?(Hash)
|
58
59
|
hash.each do |key, value|
|
59
|
-
|
60
|
+
short = 1 == key.length
|
61
|
+
prefix = short ? '-' : '--'
|
62
|
+
separator = short ? ' ' : '='
|
63
|
+
name = prefix + self.kebab(key)
|
60
64
|
|
61
65
|
if true == value
|
62
66
|
items << name
|
63
67
|
next
|
64
68
|
end
|
65
69
|
|
66
|
-
value
|
67
|
-
|
70
|
+
[value].flatten.each do |item|
|
71
|
+
item = "#{item}".gsub(/\\/, '\&\&').gsub('"', '\"')
|
72
|
+
items << %(#{name}#{separator}"#{item}")
|
73
|
+
end
|
68
74
|
next
|
69
75
|
end
|
70
76
|
end
|
@@ -96,48 +102,82 @@ module DockerCore
|
|
96
102
|
end
|
97
103
|
|
98
104
|
module Process
|
105
|
+
# @param [Numeric] second
|
106
|
+
def self.wait(second = 0)
|
107
|
+
if second.is_a?(Numeric)
|
108
|
+
if 0 > second
|
109
|
+
return sleep
|
110
|
+
end
|
111
|
+
if 0 < second
|
112
|
+
return sleep(second)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
99
117
|
# @param [Array] arguments
|
100
|
-
# @param [Boolean]
|
101
|
-
def self.command(*arguments,
|
102
|
-
if
|
103
|
-
arguments.unshift('
|
118
|
+
# @param [Boolean, String] sudo
|
119
|
+
def self.command(*arguments, sudo: SUDO)
|
120
|
+
if true == sudo
|
121
|
+
arguments.unshift('sudo')
|
122
|
+
end
|
123
|
+
|
124
|
+
if sudo.is_a?(String) && false == "#{sudo}".empty?
|
125
|
+
arguments.unshift('su-exec', sudo)
|
104
126
|
end
|
105
127
|
|
106
128
|
return Paser.arguments(*arguments).join(' ')
|
107
129
|
end
|
108
130
|
|
109
131
|
# @param [Array] arguments
|
132
|
+
# @param [Boolean, String] sudo
|
133
|
+
# @param [Boolean] throw
|
134
|
+
# @param [Numeric] wait
|
110
135
|
# @param [Boolean] strip
|
111
|
-
# @param [Boolean]
|
112
|
-
|
113
|
-
|
114
|
-
|
136
|
+
# @param [Boolean] echo
|
137
|
+
def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false)
|
138
|
+
begin
|
139
|
+
command = self.command(*arguments, substitute: sudo)
|
115
140
|
|
116
|
-
|
117
|
-
|
118
|
-
|
141
|
+
if echo
|
142
|
+
Color.echo(": #{command}", Color::YELLOW)
|
143
|
+
end
|
119
144
|
|
120
|
-
|
121
|
-
|
145
|
+
data = `#{command}`
|
146
|
+
result = strip ? "#{data}".strip : data
|
147
|
+
self.wait(wait)
|
148
|
+
return result
|
149
|
+
rescue
|
150
|
+
raise unless throw
|
151
|
+
return ''
|
152
|
+
end
|
122
153
|
end
|
123
154
|
|
124
155
|
# @param [Array] arguments
|
125
|
-
# @param [Boolean]
|
126
|
-
# @param [Boolean]
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
156
|
+
# @param [Boolean, String] sudo
|
157
|
+
# @param [Boolean] throw
|
158
|
+
# @param [Numeric] wait
|
159
|
+
# @param [Boolean] echo
|
160
|
+
def self.run(*arguments, sudo: SUDO, throw: true, wait: 0, echo: true)
|
161
|
+
command = self.command(*arguments, substitute: sudo)
|
162
|
+
|
163
|
+
if echo
|
164
|
+
Color.echo("+ #{command}", Color::GREEN)
|
133
165
|
end
|
166
|
+
|
167
|
+
result = system(command, exception: throw)
|
168
|
+
self.wait(wait)
|
169
|
+
return result
|
134
170
|
end
|
135
171
|
|
136
172
|
# @param [Array] arguments
|
137
|
-
# @param [Boolean]
|
138
|
-
def self.execute(*arguments,
|
139
|
-
command = self.command(*arguments, substitute:
|
140
|
-
|
173
|
+
# @param [Boolean, String] sudo
|
174
|
+
def self.execute(*arguments, sudo: SUDO, echo: true)
|
175
|
+
command = self.command(*arguments, substitute: sudo)
|
176
|
+
|
177
|
+
if echo
|
178
|
+
Color.echo("= #{command}", Color::CYAN)
|
179
|
+
end
|
180
|
+
|
141
181
|
exec(command)
|
142
182
|
end
|
143
183
|
|
@@ -253,8 +293,8 @@ module DockerCore
|
|
253
293
|
|
254
294
|
# @param [Object] io
|
255
295
|
# @param [String] path
|
256
|
-
# @param [Boolean]
|
257
|
-
def self.unpack_archive(io, path,
|
296
|
+
# @param [Boolean] echo
|
297
|
+
def self.unpack_archive(io, path, echo: false)
|
258
298
|
Gem::Package::TarReader.new(io) do
|
259
299
|
|
260
300
|
# @type [Gem::Package::TarReader] reader
|
@@ -266,7 +306,7 @@ module DockerCore
|
|
266
306
|
mode = header.mode
|
267
307
|
file = File.join(path, entry.full_name)
|
268
308
|
|
269
|
-
if
|
309
|
+
if echo
|
270
310
|
Color.echo(": #{file}", Color::GREEN)
|
271
311
|
end
|
272
312
|
|
@@ -287,19 +327,19 @@ module DockerCore
|
|
287
327
|
|
288
328
|
# @param [String] file
|
289
329
|
# @param [String] path
|
290
|
-
# @param [Boolean]
|
291
|
-
def self.inflate_file(file, path,
|
330
|
+
# @param [Boolean] echo
|
331
|
+
def self.inflate_file(file, path, echo: false)
|
292
332
|
Zlib::GzipReader.open(file) do
|
293
333
|
|
294
334
|
# @type [Zlib::GzipReader] reader
|
295
335
|
|reader|
|
296
|
-
self.unpack_archive(reader, path,
|
336
|
+
self.unpack_archive(reader, path, echo: echo)
|
297
337
|
end
|
298
338
|
end
|
299
339
|
|
300
340
|
# @param [String] path
|
301
|
-
# @param [Boolean]
|
302
|
-
def self.tape_archive(path,
|
341
|
+
# @param [Boolean] echo
|
342
|
+
def self.tape_archive(path, echo: false)
|
303
343
|
io = StringIO.new('')
|
304
344
|
offset = path.size + 1
|
305
345
|
|
@@ -311,7 +351,7 @@ module DockerCore
|
|
311
351
|
mode = File.stat(name).mode
|
312
352
|
file = name.slice(offset ..)
|
313
353
|
|
314
|
-
if
|
354
|
+
if echo
|
315
355
|
Color.echo(": #{file}", Color::GREEN)
|
316
356
|
end
|
317
357
|
|
@@ -335,13 +375,13 @@ module DockerCore
|
|
335
375
|
|
336
376
|
# @param [String] file
|
337
377
|
# @param [String] path
|
338
|
-
# @param [Boolean]
|
339
|
-
def self.deflate_file(file, path,
|
378
|
+
# @param [Boolean] echo
|
379
|
+
def self.deflate_file(file, path, echo: false)
|
340
380
|
Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
|
341
381
|
|
342
382
|
# @type [Zlib::GzipWriter] writer
|
343
383
|
|writer|
|
344
|
-
writer.write(self.tape_archive(path,
|
384
|
+
writer.write(self.tape_archive(path, echo: echo))
|
345
385
|
end
|
346
386
|
end
|
347
387
|
|
@@ -350,8 +390,9 @@ module DockerCore
|
|
350
390
|
def self.update_user(uid: 500, gid: 500)
|
351
391
|
uid = ENV.fetch('DOCKER_CORE_UID', uid)
|
352
392
|
gid = ENV.fetch('DOCKER_CORE_GID', gid)
|
353
|
-
|
354
|
-
Process.run('
|
393
|
+
|
394
|
+
Process.run('deluser', USER, throw: false)
|
395
|
+
Process.run('delgroup', GROUP, throw: false)
|
355
396
|
Process.run('addgroup', { system: true, gid: gid }, GROUP)
|
356
397
|
Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
|
357
398
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agrozyme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|