docker_core 0.0.18 → 0.0.22
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 +128 -90
- 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: 9e24b7a9fd2ff938ceda59f6846768c1e414dd54b9b99ee22d8384a3044d1978
|
4
|
+
data.tar.gz: 4b15e835e7b275c3b8dbbb5e82db512870a07d551f3064f7f0ce2a8e9606e625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b35e8577e6893fd84518b7eeaa8bb364684b3d632806b1c33ad0a884a3ac3457e2dbbc3c5697355a1785722f11f0b8d6076d62185b5d56a0c0f8438bbf6201d
|
7
|
+
data.tar.gz: 2b73c1c304b64e38ffb065c948a5856753c7b33100b436816f9da02219ca1f6c73931b1db2b021ac40044572085e1f5b38a537c781555ff868ddbe7b3e0302c0
|
data/lib/docker_core.rb
CHANGED
@@ -7,114 +7,140 @@ require('thor')
|
|
7
7
|
require('zlib')
|
8
8
|
|
9
9
|
module DockerCore
|
10
|
-
|
11
|
-
|
10
|
+
USER = 'core'
|
11
|
+
GROUP = 'core'
|
12
12
|
|
13
|
-
|
14
|
-
|
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
|
15
25
|
|
16
|
-
|
26
|
+
next "#{color}"
|
27
|
+
end.join
|
28
|
+
|
29
|
+
return puts("#{color}#{text}#{self::CLEAR}")
|
17
30
|
end
|
31
|
+
end
|
18
32
|
|
19
|
-
|
20
|
-
|
21
|
-
def self.boolean(value)
|
22
|
-
return %w[true yes on].include?("#{value}".strip.downcase)
|
23
|
-
end
|
33
|
+
class Runner < Thor
|
34
|
+
end
|
24
35
|
|
25
|
-
|
26
|
-
|
27
|
-
return "#{text}".gsub(/_/, '-')
|
28
|
-
end
|
36
|
+
module Image
|
37
|
+
end
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
items = []
|
39
|
+
module Command
|
40
|
+
end
|
33
41
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
42
|
+
module Paser
|
43
|
+
# @param [String] text
|
44
|
+
def self.boolean(text)
|
45
|
+
return %w[true yes on].include?("#{text}".strip.downcase)
|
46
|
+
end
|
39
47
|
|
40
|
-
|
41
|
-
|
48
|
+
# @param [String] text
|
49
|
+
def self.kebab(text)
|
50
|
+
return "#{text}".gsub(/_/, '-')
|
51
|
+
end
|
42
52
|
|
43
|
-
|
44
|
-
|
53
|
+
# @param [Hash] hash
|
54
|
+
def self.options(hash)
|
55
|
+
items = []
|
45
56
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
next
|
50
|
-
end
|
57
|
+
if hash.is_a?(Hash)
|
58
|
+
hash.each do |key, value|
|
59
|
+
name = '--' + self.kebab(key)
|
51
60
|
|
52
|
-
if
|
53
|
-
items
|
61
|
+
if true == value
|
62
|
+
items << name
|
54
63
|
next
|
55
64
|
end
|
56
65
|
|
57
|
-
|
66
|
+
value = "#{value}".gsub(/\\/, '\&\&').gsub('"', '\"')
|
67
|
+
items << %(#{name}="#{value}")
|
58
68
|
next
|
59
69
|
end
|
60
|
-
|
61
|
-
return items
|
62
70
|
end
|
71
|
+
|
72
|
+
return items
|
63
73
|
end
|
64
74
|
|
65
|
-
# @param [
|
66
|
-
|
67
|
-
|
68
|
-
if 0 == colors.size
|
69
|
-
return puts(text)
|
70
|
-
end
|
75
|
+
# @param [Array] items
|
76
|
+
def self.arguments(*items)
|
77
|
+
list = []
|
71
78
|
|
72
|
-
|
73
|
-
if
|
74
|
-
|
79
|
+
items.each do |item|
|
80
|
+
if item.is_a?(Array)
|
81
|
+
list.concat(item.map { |value| "#{value}" })
|
82
|
+
next
|
75
83
|
end
|
76
84
|
|
77
|
-
|
78
|
-
|
85
|
+
if item.is_a?(Hash)
|
86
|
+
list.concat(self.options(item))
|
87
|
+
next
|
88
|
+
end
|
79
89
|
|
80
|
-
|
90
|
+
list << "#{item}"
|
91
|
+
next
|
92
|
+
end
|
93
|
+
|
94
|
+
return list
|
81
95
|
end
|
96
|
+
end
|
82
97
|
|
98
|
+
module Process
|
99
|
+
# @param [Array] arguments
|
100
|
+
# @param [Boolean] substitute
|
83
101
|
def self.command(*arguments, substitute: false)
|
84
102
|
if substitute
|
85
103
|
arguments.unshift('su-exec', USER)
|
86
104
|
end
|
87
105
|
|
88
|
-
return Paser.
|
106
|
+
return Paser.arguments(*arguments).join(' ')
|
89
107
|
end
|
90
108
|
|
109
|
+
# @param [Array] arguments
|
110
|
+
# @param [Boolean] substitute
|
111
|
+
# @param [Boolean] exception
|
91
112
|
# @param [Boolean] strip
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
self.echo("+ #{command}", Color::GREEN)
|
97
|
-
end
|
113
|
+
# @param [Boolean] verbose
|
114
|
+
def self.capture(*arguments, substitute: false, exception: false, strip: true, verbose: false)
|
115
|
+
begin
|
116
|
+
command = self.command(*arguments, substitute: substitute)
|
98
117
|
|
99
|
-
|
100
|
-
|
101
|
-
|
118
|
+
if verbose
|
119
|
+
Color.echo("+ #{command}", Color::GREEN)
|
120
|
+
end
|
102
121
|
|
103
|
-
|
104
|
-
|
105
|
-
begin
|
106
|
-
data = self.capture(*arguments, strip: false, verbose: true, substitute: substitute)
|
107
|
-
print(data)
|
122
|
+
data = `#{command}`
|
123
|
+
return strip ? "#{data}".strip : data
|
108
124
|
rescue
|
109
|
-
raise unless
|
125
|
+
raise unless exception
|
126
|
+
return ''
|
110
127
|
end
|
111
128
|
end
|
112
129
|
|
113
|
-
# @param [
|
114
|
-
# @param [
|
130
|
+
# @param [Array] arguments
|
131
|
+
# @param [Boolean] substitute
|
132
|
+
# @param [Boolean] exception
|
133
|
+
def self.run(*arguments, substitute: false, exception: true)
|
134
|
+
command = self.command(*arguments, substitute: substitute)
|
135
|
+
Color.echo("+ #{command}", Color::GREEN)
|
136
|
+
return system(command, exception: exception)
|
137
|
+
end
|
138
|
+
|
139
|
+
# @param [Array] arguments
|
140
|
+
# @param [Boolean] substitute
|
115
141
|
def self.execute(*arguments, substitute: false)
|
116
142
|
command = self.command(*arguments, substitute: substitute)
|
117
|
-
|
143
|
+
Color.echo("= #{command}", Color::CYAN)
|
118
144
|
exec(command)
|
119
145
|
end
|
120
146
|
|
@@ -123,9 +149,18 @@ module DockerCore
|
|
123
149
|
# @param [Array] arguments
|
124
150
|
def self.invoke(title, delegate, *arguments)
|
125
151
|
color = Color::YELLOW
|
126
|
-
|
152
|
+
Color.echo("> #{title}", color)
|
127
153
|
delegate.call(*arguments)
|
128
|
-
|
154
|
+
Color.echo("< #{title}", color)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
module Shell
|
160
|
+
def self.architecture
|
161
|
+
hash = { x86: '386', x86_64: 'amd64', armhf: 'armv6', armv7l: 'armv7', aarch64: 'arm64' }
|
162
|
+
machine = "#{Etc.uname[:machine]}"
|
163
|
+
return hash.fetch(machine.to_sym, machine)
|
129
164
|
end
|
130
165
|
|
131
166
|
# @param [Array<String>] arguments
|
@@ -148,6 +183,7 @@ module DockerCore
|
|
148
183
|
end
|
149
184
|
|
150
185
|
# @param [Array<String>] arguments
|
186
|
+
# @param [String, Integer] mode
|
151
187
|
def self.change_mode(mode, *arguments)
|
152
188
|
self.find_paths(*arguments).each do |path|
|
153
189
|
FileUtils.chmod_R(mode, path, force: true)
|
@@ -155,6 +191,7 @@ module DockerCore
|
|
155
191
|
end
|
156
192
|
|
157
193
|
# @param [Array<String>] arguments
|
194
|
+
# @param [Integer, nil] mode
|
158
195
|
def self.make_folders(*arguments, mode: nil)
|
159
196
|
stack = []
|
160
197
|
paths = arguments.map do |path|
|
@@ -187,8 +224,8 @@ module DockerCore
|
|
187
224
|
# @param [String, Array<String>] source
|
188
225
|
# @param [String] target
|
189
226
|
def self.move_paths(source, target)
|
190
|
-
|
191
|
-
FileUtils.mv(self.find_paths(*
|
227
|
+
paths = [source].flatten
|
228
|
+
FileUtils.mv(self.find_paths(*paths), target)
|
192
229
|
end
|
193
230
|
|
194
231
|
# @param [String] uri
|
@@ -217,9 +254,10 @@ module DockerCore
|
|
217
254
|
return File.binwrite(file, content)
|
218
255
|
end
|
219
256
|
|
257
|
+
# @param [Object] io
|
220
258
|
# @param [String] path
|
221
259
|
# @param [Boolean] verbose
|
222
|
-
def self.
|
260
|
+
def self.unpack_archive(io, path, verbose: false)
|
223
261
|
Gem::Package::TarReader.new(io) do
|
224
262
|
|
225
263
|
# @type [Gem::Package::TarReader] reader
|
@@ -232,7 +270,7 @@ module DockerCore
|
|
232
270
|
file = File.join(path, entry.full_name)
|
233
271
|
|
234
272
|
if verbose
|
235
|
-
|
273
|
+
Color.echo(": #{file}", Color::GREEN)
|
236
274
|
end
|
237
275
|
|
238
276
|
if entry.directory?
|
@@ -253,18 +291,18 @@ module DockerCore
|
|
253
291
|
# @param [String] file
|
254
292
|
# @param [String] path
|
255
293
|
# @param [Boolean] verbose
|
256
|
-
def self.
|
294
|
+
def self.inflate_file(file, path, verbose: false)
|
257
295
|
Zlib::GzipReader.open(file) do
|
258
296
|
|
259
297
|
# @type [Zlib::GzipReader] reader
|
260
298
|
|reader|
|
261
|
-
self.
|
299
|
+
self.unpack_archive(reader, path, verbose: verbose)
|
262
300
|
end
|
263
301
|
end
|
264
302
|
|
265
303
|
# @param [String] path
|
266
304
|
# @param [Boolean] verbose
|
267
|
-
def self.
|
305
|
+
def self.tape_archive(path, verbose: false)
|
268
306
|
io = StringIO.new('')
|
269
307
|
offset = path.size + 1
|
270
308
|
|
@@ -277,7 +315,7 @@ module DockerCore
|
|
277
315
|
file = name.slice(offset ..)
|
278
316
|
|
279
317
|
if verbose
|
280
|
-
|
318
|
+
Color.echo(": #{file}", Color::GREEN)
|
281
319
|
end
|
282
320
|
|
283
321
|
if File.directory?(name)
|
@@ -301,22 +339,24 @@ module DockerCore
|
|
301
339
|
# @param [String] file
|
302
340
|
# @param [String] path
|
303
341
|
# @param [Boolean] verbose
|
304
|
-
def self.
|
342
|
+
def self.deflate_file(file, path, verbose: false)
|
305
343
|
Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
|
306
344
|
|
307
345
|
# @type [Zlib::GzipWriter] writer
|
308
346
|
|writer|
|
309
|
-
writer.write(self.
|
347
|
+
writer.write(self.tape_archive(path, verbose: verbose))
|
310
348
|
end
|
311
349
|
end
|
312
350
|
|
313
351
|
# @param [Integer] uid
|
314
352
|
# @param [Integer] gid
|
315
353
|
def self.update_user(uid: 500, gid: 500)
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
354
|
+
uid = ENV.fetch('DOCKER_CORE_UID', uid)
|
355
|
+
gid = ENV.fetch('DOCKER_CORE_GID', gid)
|
356
|
+
Process.run('deluser', USER, exception: false)
|
357
|
+
Process.run('delgroup', GROUP, exception: false)
|
358
|
+
Process.run('addgroup', { system: true, gid: gid }, GROUP)
|
359
|
+
Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
|
320
360
|
end
|
321
361
|
|
322
362
|
# @param [String] stdout
|
@@ -329,24 +369,22 @@ module DockerCore
|
|
329
369
|
if '' != stderr
|
330
370
|
File.symlink('/dev/stderr', File.path(stderr))
|
331
371
|
end
|
372
|
+
|
373
|
+
return
|
332
374
|
end
|
333
375
|
|
334
376
|
# @param [Array<String>] arguments
|
377
|
+
# @param [Integer ,nil] mode
|
335
378
|
def self.clear_folders(*arguments, mode: nil)
|
336
379
|
self.remove_paths(*arguments)
|
337
380
|
self.make_folders(*arguments, mode: mode)
|
338
381
|
end
|
339
382
|
|
340
|
-
def self.architecture
|
341
|
-
hash = { x86: '386', x86_64: 'amd64', armhf: 'armv6', armv7l: 'armv7', aarch64: 'arm64' }
|
342
|
-
machine = "#{Etc.uname[:machine]}"
|
343
|
-
return hash.fetch(machine.to_sym, machine)
|
344
|
-
end
|
345
|
-
|
346
383
|
# @param [String] repository
|
347
384
|
def self.github_latest_version(repository)
|
348
385
|
uri = URI("https://api.github.com/repos/#{repository}/releases/latest")
|
349
|
-
|
386
|
+
data = JSON.parse(Net::HTTP.get(uri))['tag_name']
|
387
|
+
return "#{data}"
|
350
388
|
end
|
351
389
|
end
|
352
390
|
|
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.22
|
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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|