docker_core 0.0.19 → 0.0.23
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 +136 -82
- 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: 80affaf62801f9396342f5e34a9b4d7d9c60cbb7734eb072c53fd639a0128795
|
4
|
+
data.tar.gz: fb93776e06070bcf7633f4307d0c2fb16e0c1c447c1548dd57618319c61dd7aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357c0774652360108f2a5cc9773b482999a3f454b0af977ab609b80618fbe8a2157af83d8bc1041afa1e0056f2aa7e7b61ec2f5fa60b56a7caff996296b07d8e
|
7
|
+
data.tar.gz: 861b83b14df2c399f64a5a580dc61281414c0c581528118d38cbcdd044e09c79387fb334930c170b0197b3bd7f6c84a2739efb064112f60011131d26d034e926
|
data/lib/docker_core.rb
CHANGED
@@ -7,7 +7,30 @@ require('thor')
|
|
7
7
|
require('zlib')
|
8
8
|
|
9
9
|
module DockerCore
|
10
|
+
USER = 'core'
|
11
|
+
GROUP = 'core'
|
12
|
+
|
10
13
|
class Color < Thor::Shell::Color
|
14
|
+
# @param [String] text
|
15
|
+
# @param [Array<String>] colors
|
16
|
+
def self.echo(text, *colors)
|
17
|
+
if 0 == colors.size
|
18
|
+
return puts(text)
|
19
|
+
end
|
20
|
+
|
21
|
+
color = colors.map do |color|
|
22
|
+
if color.is_a?(Symbol)
|
23
|
+
next self.const_get(color.to_s.upcase)
|
24
|
+
end
|
25
|
+
|
26
|
+
next "#{color}"
|
27
|
+
end.join
|
28
|
+
|
29
|
+
return puts("#{color}#{text}#{self::CLEAR}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Runner < Thor
|
11
34
|
end
|
12
35
|
|
13
36
|
module Image
|
@@ -17,9 +40,9 @@ module DockerCore
|
|
17
40
|
end
|
18
41
|
|
19
42
|
module Paser
|
20
|
-
# @param [String]
|
21
|
-
def self.boolean(
|
22
|
-
return %w[true yes on].include?("#{
|
43
|
+
# @param [String] text
|
44
|
+
def self.boolean(text)
|
45
|
+
return %w[true yes on].include?("#{text}".strip.downcase)
|
23
46
|
end
|
24
47
|
|
25
48
|
# @param [String] text
|
@@ -28,104 +51,123 @@ module DockerCore
|
|
28
51
|
end
|
29
52
|
|
30
53
|
# @param [Hash] hash
|
31
|
-
def self.options(hash
|
54
|
+
def self.options(hash)
|
32
55
|
items = []
|
33
56
|
|
34
|
-
hash.
|
35
|
-
|
57
|
+
if hash.is_a?(Hash)
|
58
|
+
hash.each do |key, value|
|
59
|
+
short = 1 == key.length
|
60
|
+
prefix = short ? '-' : '--'
|
61
|
+
separator = short ? ' ' : '='
|
62
|
+
name = prefix + self.kebab(key)
|
36
63
|
|
37
|
-
|
38
|
-
|
64
|
+
if true == value
|
65
|
+
items << name
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
[value].flatten.each do |item|
|
70
|
+
item = "#{item}".gsub(/\\/, '\&\&').gsub('"', '\"')
|
71
|
+
items << %(#{name}#{separator}"#{item}")
|
72
|
+
end
|
39
73
|
next
|
40
74
|
end
|
41
|
-
|
42
|
-
value = "#{value}".gsub(/\\/, '\&\&').gsub('"', '\"')
|
43
|
-
items << %(#{name}="#{value}")
|
44
|
-
next
|
45
75
|
end
|
46
76
|
|
47
77
|
return items
|
48
78
|
end
|
49
79
|
|
50
|
-
|
51
|
-
|
80
|
+
# @param [Array] items
|
81
|
+
def self.arguments(*items)
|
82
|
+
list = []
|
52
83
|
|
53
|
-
|
84
|
+
items.each do |item|
|
54
85
|
if item.is_a?(Array)
|
55
|
-
|
86
|
+
list.concat(item.map { |value| "#{value}" })
|
56
87
|
next
|
57
88
|
end
|
58
89
|
|
59
90
|
if item.is_a?(Hash)
|
60
|
-
|
91
|
+
list.concat(self.options(item))
|
61
92
|
next
|
62
93
|
end
|
63
94
|
|
64
|
-
|
95
|
+
list << "#{item}"
|
65
96
|
next
|
66
97
|
end
|
67
98
|
|
68
|
-
return
|
99
|
+
return list
|
69
100
|
end
|
70
101
|
end
|
71
102
|
|
72
|
-
module
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
def self.echo(text, *colors)
|
79
|
-
if 0 == colors.size
|
80
|
-
return puts(text)
|
81
|
-
end
|
82
|
-
|
83
|
-
color = colors.map do |color|
|
84
|
-
if color.is_a?(Symbol)
|
85
|
-
next Color.const_get(color.to_s.upcase)
|
103
|
+
module Process
|
104
|
+
# @param [Numeric] duration
|
105
|
+
def self.wait(duration = 0)
|
106
|
+
if duration.is_a?(Numeric)
|
107
|
+
if 0 > duration
|
108
|
+
return sleep
|
86
109
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
return puts("#{color}#{text}#{Color::CLEAR}")
|
110
|
+
if 0 < duration
|
111
|
+
return sleep(duration)
|
112
|
+
end
|
113
|
+
end
|
92
114
|
end
|
93
115
|
|
116
|
+
# @param [Array] arguments
|
117
|
+
# @param [Boolean, String] substitute
|
94
118
|
def self.command(*arguments, substitute: false)
|
95
|
-
if substitute
|
96
|
-
arguments.unshift('
|
119
|
+
if true == substitute
|
120
|
+
arguments.unshift('sudo')
|
97
121
|
end
|
98
122
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
# @param [Boolean] strip
|
103
|
-
def self.capture(*arguments, strip: true, verbose: false, substitute: false)
|
104
|
-
command = self.command(*arguments, substitute: substitute)
|
105
|
-
|
106
|
-
if verbose
|
107
|
-
self.echo("+ #{command}", Color::GREEN)
|
123
|
+
if substitute.is_a?(String) && false == "#{substitute}".empty?
|
124
|
+
arguments.unshift('su-exec', substitute)
|
108
125
|
end
|
109
126
|
|
110
|
-
|
111
|
-
return strip ? "#{data}".strip : data
|
127
|
+
return Paser.arguments(*arguments).join(' ')
|
112
128
|
end
|
113
129
|
|
114
|
-
# @param [
|
115
|
-
|
130
|
+
# @param [Array] arguments
|
131
|
+
# @param [Boolean, String] substitute
|
132
|
+
# @param [Boolean] exception
|
133
|
+
# @param [Numeric] duration
|
134
|
+
# @param [Boolean] strip
|
135
|
+
# @param [Boolean] verbose
|
136
|
+
def self.capture(*arguments, substitute: false, exception: false, duration: 0, strip: true, verbose: false)
|
116
137
|
begin
|
117
|
-
|
118
|
-
|
138
|
+
command = self.command(*arguments, substitute: substitute)
|
139
|
+
|
140
|
+
if verbose
|
141
|
+
Color.echo("+ #{command}", Color::GREEN)
|
142
|
+
end
|
143
|
+
|
144
|
+
data = `#{command}`
|
145
|
+
result = strip ? "#{data}".strip : data
|
146
|
+
self.wait(duration)
|
147
|
+
return result
|
119
148
|
rescue
|
120
|
-
raise unless
|
149
|
+
raise unless exception
|
150
|
+
return ''
|
121
151
|
end
|
122
152
|
end
|
123
153
|
|
124
|
-
# @param [
|
125
|
-
# @param [String]
|
154
|
+
# @param [Array] arguments
|
155
|
+
# @param [Boolean, String] substitute
|
156
|
+
# @param [Boolean] exception
|
157
|
+
# @param [Numeric] duration
|
158
|
+
def self.run(*arguments, substitute: false, exception: true, duration: 0)
|
159
|
+
command = self.command(*arguments, substitute: substitute)
|
160
|
+
Color.echo("+ #{command}", Color::GREEN)
|
161
|
+
result = system(command, exception: exception)
|
162
|
+
self.wait(duration)
|
163
|
+
return result
|
164
|
+
end
|
165
|
+
|
166
|
+
# @param [Array] arguments
|
167
|
+
# @param [Boolean, String] substitute
|
126
168
|
def self.execute(*arguments, substitute: false)
|
127
169
|
command = self.command(*arguments, substitute: substitute)
|
128
|
-
|
170
|
+
Color.echo("= #{command}", Color::CYAN)
|
129
171
|
exec(command)
|
130
172
|
end
|
131
173
|
|
@@ -134,9 +176,18 @@ module DockerCore
|
|
134
176
|
# @param [Array] arguments
|
135
177
|
def self.invoke(title, delegate, *arguments)
|
136
178
|
color = Color::YELLOW
|
137
|
-
|
179
|
+
Color.echo("> #{title}", color)
|
138
180
|
delegate.call(*arguments)
|
139
|
-
|
181
|
+
Color.echo("< #{title}", color)
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
module Shell
|
187
|
+
def self.architecture
|
188
|
+
hash = { x86: '386', x86_64: 'amd64', armhf: 'armv6', armv7l: 'armv7', aarch64: 'arm64' }
|
189
|
+
machine = "#{Etc.uname[:machine]}"
|
190
|
+
return hash.fetch(machine.to_sym, machine)
|
140
191
|
end
|
141
192
|
|
142
193
|
# @param [Array<String>] arguments
|
@@ -159,6 +210,7 @@ module DockerCore
|
|
159
210
|
end
|
160
211
|
|
161
212
|
# @param [Array<String>] arguments
|
213
|
+
# @param [String, Integer] mode
|
162
214
|
def self.change_mode(mode, *arguments)
|
163
215
|
self.find_paths(*arguments).each do |path|
|
164
216
|
FileUtils.chmod_R(mode, path, force: true)
|
@@ -166,6 +218,7 @@ module DockerCore
|
|
166
218
|
end
|
167
219
|
|
168
220
|
# @param [Array<String>] arguments
|
221
|
+
# @param [Integer, nil] mode
|
169
222
|
def self.make_folders(*arguments, mode: nil)
|
170
223
|
stack = []
|
171
224
|
paths = arguments.map do |path|
|
@@ -198,8 +251,8 @@ module DockerCore
|
|
198
251
|
# @param [String, Array<String>] source
|
199
252
|
# @param [String] target
|
200
253
|
def self.move_paths(source, target)
|
201
|
-
|
202
|
-
FileUtils.mv(self.find_paths(*
|
254
|
+
paths = [source].flatten
|
255
|
+
FileUtils.mv(self.find_paths(*paths), target)
|
203
256
|
end
|
204
257
|
|
205
258
|
# @param [String] uri
|
@@ -228,9 +281,10 @@ module DockerCore
|
|
228
281
|
return File.binwrite(file, content)
|
229
282
|
end
|
230
283
|
|
284
|
+
# @param [Object] io
|
231
285
|
# @param [String] path
|
232
286
|
# @param [Boolean] verbose
|
233
|
-
def self.
|
287
|
+
def self.unpack_archive(io, path, verbose: false)
|
234
288
|
Gem::Package::TarReader.new(io) do
|
235
289
|
|
236
290
|
# @type [Gem::Package::TarReader] reader
|
@@ -243,7 +297,7 @@ module DockerCore
|
|
243
297
|
file = File.join(path, entry.full_name)
|
244
298
|
|
245
299
|
if verbose
|
246
|
-
|
300
|
+
Color.echo(": #{file}", Color::GREEN)
|
247
301
|
end
|
248
302
|
|
249
303
|
if entry.directory?
|
@@ -264,18 +318,18 @@ module DockerCore
|
|
264
318
|
# @param [String] file
|
265
319
|
# @param [String] path
|
266
320
|
# @param [Boolean] verbose
|
267
|
-
def self.
|
321
|
+
def self.inflate_file(file, path, verbose: false)
|
268
322
|
Zlib::GzipReader.open(file) do
|
269
323
|
|
270
324
|
# @type [Zlib::GzipReader] reader
|
271
325
|
|reader|
|
272
|
-
self.
|
326
|
+
self.unpack_archive(reader, path, verbose: verbose)
|
273
327
|
end
|
274
328
|
end
|
275
329
|
|
276
330
|
# @param [String] path
|
277
331
|
# @param [Boolean] verbose
|
278
|
-
def self.
|
332
|
+
def self.tape_archive(path, verbose: false)
|
279
333
|
io = StringIO.new('')
|
280
334
|
offset = path.size + 1
|
281
335
|
|
@@ -288,7 +342,7 @@ module DockerCore
|
|
288
342
|
file = name.slice(offset ..)
|
289
343
|
|
290
344
|
if verbose
|
291
|
-
|
345
|
+
Color.echo(": #{file}", Color::GREEN)
|
292
346
|
end
|
293
347
|
|
294
348
|
if File.directory?(name)
|
@@ -312,22 +366,24 @@ module DockerCore
|
|
312
366
|
# @param [String] file
|
313
367
|
# @param [String] path
|
314
368
|
# @param [Boolean] verbose
|
315
|
-
def self.
|
369
|
+
def self.deflate_file(file, path, verbose: false)
|
316
370
|
Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
|
317
371
|
|
318
372
|
# @type [Zlib::GzipWriter] writer
|
319
373
|
|writer|
|
320
|
-
writer.write(self.
|
374
|
+
writer.write(self.tape_archive(path, verbose: verbose))
|
321
375
|
end
|
322
376
|
end
|
323
377
|
|
324
378
|
# @param [Integer] uid
|
325
379
|
# @param [Integer] gid
|
326
380
|
def self.update_user(uid: 500, gid: 500)
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
381
|
+
uid = ENV.fetch('DOCKER_CORE_UID', uid)
|
382
|
+
gid = ENV.fetch('DOCKER_CORE_GID', gid)
|
383
|
+
Process.run('deluser', USER, exception: false)
|
384
|
+
Process.run('delgroup', GROUP, exception: false)
|
385
|
+
Process.run('addgroup', { system: true, gid: gid }, GROUP)
|
386
|
+
Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
|
331
387
|
end
|
332
388
|
|
333
389
|
# @param [String] stdout
|
@@ -340,24 +396,22 @@ module DockerCore
|
|
340
396
|
if '' != stderr
|
341
397
|
File.symlink('/dev/stderr', File.path(stderr))
|
342
398
|
end
|
399
|
+
|
400
|
+
return
|
343
401
|
end
|
344
402
|
|
345
403
|
# @param [Array<String>] arguments
|
404
|
+
# @param [Integer ,nil] mode
|
346
405
|
def self.clear_folders(*arguments, mode: nil)
|
347
406
|
self.remove_paths(*arguments)
|
348
407
|
self.make_folders(*arguments, mode: mode)
|
349
408
|
end
|
350
409
|
|
351
|
-
def self.architecture
|
352
|
-
hash = { x86: '386', x86_64: 'amd64', armhf: 'armv6', armv7l: 'armv7', aarch64: 'arm64' }
|
353
|
-
machine = "#{Etc.uname[:machine]}"
|
354
|
-
return hash.fetch(machine.to_sym, machine)
|
355
|
-
end
|
356
|
-
|
357
410
|
# @param [String] repository
|
358
411
|
def self.github_latest_version(repository)
|
359
412
|
uri = URI("https://api.github.com/repos/#{repository}/releases/latest")
|
360
|
-
|
413
|
+
data = JSON.parse(Net::HTTP.get(uri))['tag_name']
|
414
|
+
return "#{data}"
|
361
415
|
end
|
362
416
|
end
|
363
417
|
|
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.23
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|