docker_core 0.0.21 → 0.0.25
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 +78 -39
- 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: a1aa25b8f032a45928140b7f29a149f6dfd9e5b658775027a68c0af0149c3a56
|
4
|
+
data.tar.gz: 0e7384b6cfacba90eaea5a6fcc1c95fad176a350b644030a82aecb01ca41710d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1152e77399f32f7339b421a8f7a589d2c14545a40ca6670459a56a190e6e73749d01d055649dbc12c2c091aa67690101524ea9e890428a76f8a0217a35adc59b
|
7
|
+
data.tar.gz: 31bb09aa3c9c01d053764efd20264fc21453e6bb0a0f3c8d26ea71e7804f23f7b90bf190339a7dc91cb382a45cf151eca488bd2f37b595f080b2625e50b4eb66
|
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,50 +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
|
110
|
-
# @param [Boolean]
|
111
|
-
# @param [Boolean]
|
132
|
+
# @param [Boolean, String] sudo
|
133
|
+
# @param [Boolean] throw
|
134
|
+
# @param [Numeric] wait
|
112
135
|
# @param [Boolean] strip
|
113
|
-
# @param [Boolean]
|
114
|
-
def self.capture(*arguments,
|
136
|
+
# @param [Boolean] echo
|
137
|
+
def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false)
|
115
138
|
begin
|
116
|
-
command = self.command(*arguments,
|
139
|
+
command = self.command(*arguments, sudo: sudo)
|
117
140
|
|
118
|
-
if
|
119
|
-
Color.echo("
|
141
|
+
if echo
|
142
|
+
Color.echo(": #{command}", Color::YELLOW)
|
120
143
|
end
|
121
144
|
|
122
145
|
data = `#{command}`
|
123
|
-
|
146
|
+
result = strip ? "#{data}".strip : data
|
147
|
+
self.wait(wait)
|
148
|
+
return result
|
124
149
|
rescue
|
125
|
-
raise unless
|
150
|
+
raise unless throw
|
126
151
|
return ''
|
127
152
|
end
|
128
153
|
end
|
129
154
|
|
130
155
|
# @param [Array] arguments
|
131
|
-
# @param [Boolean]
|
132
|
-
# @param [Boolean]
|
133
|
-
|
134
|
-
|
135
|
-
|
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, sudo: sudo)
|
162
|
+
|
163
|
+
if echo
|
164
|
+
Color.echo("+ #{command}", Color::GREEN)
|
165
|
+
end
|
166
|
+
|
167
|
+
result = system(command, exception: throw)
|
168
|
+
self.wait(wait)
|
169
|
+
return result
|
136
170
|
end
|
137
171
|
|
138
172
|
# @param [Array] arguments
|
139
|
-
# @param [Boolean]
|
140
|
-
def self.execute(*arguments,
|
141
|
-
command = self.command(*arguments,
|
142
|
-
|
173
|
+
# @param [Boolean, String] sudo
|
174
|
+
def self.execute(*arguments, sudo: SUDO, echo: true)
|
175
|
+
command = self.command(*arguments, sudo: sudo)
|
176
|
+
|
177
|
+
if echo
|
178
|
+
Color.echo("= #{command}", Color::CYAN)
|
179
|
+
end
|
180
|
+
|
143
181
|
exec(command)
|
144
182
|
end
|
145
183
|
|
@@ -255,8 +293,8 @@ module DockerCore
|
|
255
293
|
|
256
294
|
# @param [Object] io
|
257
295
|
# @param [String] path
|
258
|
-
# @param [Boolean]
|
259
|
-
def self.unpack_archive(io, path,
|
296
|
+
# @param [Boolean] echo
|
297
|
+
def self.unpack_archive(io, path, echo: false)
|
260
298
|
Gem::Package::TarReader.new(io) do
|
261
299
|
|
262
300
|
# @type [Gem::Package::TarReader] reader
|
@@ -268,7 +306,7 @@ module DockerCore
|
|
268
306
|
mode = header.mode
|
269
307
|
file = File.join(path, entry.full_name)
|
270
308
|
|
271
|
-
if
|
309
|
+
if echo
|
272
310
|
Color.echo(": #{file}", Color::GREEN)
|
273
311
|
end
|
274
312
|
|
@@ -289,19 +327,19 @@ module DockerCore
|
|
289
327
|
|
290
328
|
# @param [String] file
|
291
329
|
# @param [String] path
|
292
|
-
# @param [Boolean]
|
293
|
-
def self.inflate_file(file, path,
|
330
|
+
# @param [Boolean] echo
|
331
|
+
def self.inflate_file(file, path, echo: false)
|
294
332
|
Zlib::GzipReader.open(file) do
|
295
333
|
|
296
334
|
# @type [Zlib::GzipReader] reader
|
297
335
|
|reader|
|
298
|
-
self.unpack_archive(reader, path,
|
336
|
+
self.unpack_archive(reader, path, echo: echo)
|
299
337
|
end
|
300
338
|
end
|
301
339
|
|
302
340
|
# @param [String] path
|
303
|
-
# @param [Boolean]
|
304
|
-
def self.tape_archive(path,
|
341
|
+
# @param [Boolean] echo
|
342
|
+
def self.tape_archive(path, echo: false)
|
305
343
|
io = StringIO.new('')
|
306
344
|
offset = path.size + 1
|
307
345
|
|
@@ -313,7 +351,7 @@ module DockerCore
|
|
313
351
|
mode = File.stat(name).mode
|
314
352
|
file = name.slice(offset ..)
|
315
353
|
|
316
|
-
if
|
354
|
+
if echo
|
317
355
|
Color.echo(": #{file}", Color::GREEN)
|
318
356
|
end
|
319
357
|
|
@@ -337,13 +375,13 @@ module DockerCore
|
|
337
375
|
|
338
376
|
# @param [String] file
|
339
377
|
# @param [String] path
|
340
|
-
# @param [Boolean]
|
341
|
-
def self.deflate_file(file, path,
|
378
|
+
# @param [Boolean] echo
|
379
|
+
def self.deflate_file(file, path, echo: false)
|
342
380
|
Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
|
343
381
|
|
344
382
|
# @type [Zlib::GzipWriter] writer
|
345
383
|
|writer|
|
346
|
-
writer.write(self.tape_archive(path,
|
384
|
+
writer.write(self.tape_archive(path, echo: echo))
|
347
385
|
end
|
348
386
|
end
|
349
387
|
|
@@ -352,8 +390,9 @@ module DockerCore
|
|
352
390
|
def self.update_user(uid: 500, gid: 500)
|
353
391
|
uid = ENV.fetch('DOCKER_CORE_UID', uid)
|
354
392
|
gid = ENV.fetch('DOCKER_CORE_GID', gid)
|
355
|
-
|
356
|
-
Process.run('
|
393
|
+
|
394
|
+
Process.run('deluser', USER, throw: false)
|
395
|
+
Process.run('delgroup', GROUP, throw: false)
|
357
396
|
Process.run('addgroup', { system: true, gid: gid }, GROUP)
|
358
397
|
Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
|
359
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.25
|
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
|