docker_core 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docker_core.rb +93 -69
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99124c5250cb55f257fbe4c99701f860b4cc8f29c5889672b482c6a0d9ecfb4a
4
- data.tar.gz: 539db15180fb5f835c03f199e4944b20479e71d47bc92c3d1ba7fecdbe723fb9
3
+ metadata.gz: a39a514720435a65fbc3f039eee7c86503e501ab70b821656510b3ba8e8fe941
4
+ data.tar.gz: 7c95deb803d9b5a095a8cc2a5758e926000065e22aaac2a2420a896ef2be2c81
5
5
  SHA512:
6
- metadata.gz: cf8f61dc593866c8b000b9e1f6926c11594ec9b8c9bc2da52947d4410422bd25f5489ac38be02e57d765ffa1363391444e71ee250b4eb3c1e793d2bb326d1757
7
- data.tar.gz: 29fbd93e2e05ca7cef4be7529c1d2c082081908cf8ca061c4f7c26ff759324ad56a57673443d7f86db80d5009882879aa48762c5380abeee883c7553c47104f7
6
+ metadata.gz: e0929e952d6d9c3bca9f1d0e5ca3a5f5fa9f193c545bbd0e286361ef7811f54c624db153354664f32e74eef2d20ce36632380a84c343273a05c5e71c435bf968
7
+ data.tar.gz: 4e8ede2a599f2d820649d667f8b64e14d33227cd25abba7838b16202b1002633f4b363a91c7cf9dd709b99c036ff59210fb4deb76c8818946292a3a853c537fc
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] value
21
- def self.boolean(value)
22
- return %w[true yes on].include?("#{value}".strip.downcase)
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,90 +51,79 @@ 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.each do |key, value|
35
- name = '--' + self.kebab(key)
57
+ if hash.is_a?(Hash)
58
+ hash.each do |key, value|
59
+ name = '--' + self.kebab(key)
60
+
61
+ if true == value
62
+ items << name
63
+ next
64
+ end
36
65
 
37
- if true == value
38
- items << name
66
+ value = "#{value}".gsub(/\\/, '\&\&').gsub('"', '\"')
67
+ items << %(#{name}="#{value}")
39
68
  next
40
69
  end
41
-
42
- value = "#{value}".gsub(/\\/, '\&\&').gsub('"', '\"')
43
- items << %(#{name}="#{value}")
44
- next
45
70
  end
46
71
 
47
72
  return items
48
73
  end
49
74
 
50
- def self.make(*arguments)
51
- items = []
75
+ # @param [Array] items
76
+ def self.arguments(*items)
77
+ list = []
52
78
 
53
- arguments.each do |item|
79
+ items.each do |item|
54
80
  if item.is_a?(Array)
55
- items.concat(item.map { |value| "#{value}" })
81
+ list.concat(item.map { |value| "#{value}" })
56
82
  next
57
83
  end
58
84
 
59
85
  if item.is_a?(Hash)
60
- items.concat(self.options(item))
86
+ list.concat(self.options(item))
61
87
  next
62
88
  end
63
89
 
64
- items << "#{item}"
90
+ list << "#{item}"
65
91
  next
66
92
  end
67
93
 
68
- return items
94
+ return list
69
95
  end
70
96
  end
71
97
 
72
- module Shell
73
- USER = 'core'
74
- GROUP = 'core'
75
-
76
- # @param [String] text
77
- # @param [Array<String>] colors
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)
86
- end
87
-
88
- next "#{color}"
89
- end.join
90
-
91
- return puts("#{color}#{text}#{Color::CLEAR}")
92
- end
93
-
98
+ module Process
99
+ # @param [Array] arguments
100
+ # @param [Boolean] substitute
94
101
  def self.command(*arguments, substitute: false)
95
102
  if substitute
96
103
  arguments.unshift('su-exec', USER)
97
104
  end
98
105
 
99
- return Paser.make(*arguments).join(' ')
106
+ return Paser.arguments(*arguments).join(' ')
100
107
  end
101
108
 
109
+ # @param [Array] arguments
102
110
  # @param [Boolean] strip
111
+ # @param [Boolean] verbose
112
+ # @param [Boolean] substitute
103
113
  def self.capture(*arguments, strip: true, verbose: false, substitute: false)
104
114
  command = self.command(*arguments, substitute: substitute)
105
115
 
106
116
  if verbose
107
- self.echo("+ #{command}", Color::GREEN)
117
+ Color.echo("+ #{command}", Color::GREEN)
108
118
  end
109
119
 
110
120
  data = `#{command}`
111
121
  return strip ? "#{data}".strip : data
112
122
  end
113
123
 
124
+ # @param [Array] arguments
114
125
  # @param [Boolean] force
126
+ # @param [Boolean] substitute
115
127
  def self.run(*arguments, force: false, substitute: false)
116
128
  begin
117
129
  data = self.capture(*arguments, strip: false, verbose: true, substitute: substitute)
@@ -121,11 +133,11 @@ module DockerCore
121
133
  end
122
134
  end
123
135
 
124
- # @param [Boolean] force
125
- # @param [String] user
136
+ # @param [Array] arguments
137
+ # @param [Boolean] substitute
126
138
  def self.execute(*arguments, substitute: false)
127
139
  command = self.command(*arguments, substitute: substitute)
128
- self.echo("= #{command}", Color::CYAN)
140
+ Color.echo("= #{command}", Color::CYAN)
129
141
  exec(command)
130
142
  end
131
143
 
@@ -134,9 +146,18 @@ module DockerCore
134
146
  # @param [Array] arguments
135
147
  def self.invoke(title, delegate, *arguments)
136
148
  color = Color::YELLOW
137
- self.echo("> #{title}", color)
149
+ Color.echo("> #{title}", color)
138
150
  delegate.call(*arguments)
139
- self.echo("< #{title}", color)
151
+ Color.echo("< #{title}", color)
152
+ end
153
+
154
+ end
155
+
156
+ module Shell
157
+ def self.architecture
158
+ hash = { x86: '386', x86_64: 'amd64', armhf: 'armv6', armv7l: 'armv7', aarch64: 'arm64' }
159
+ machine = "#{Etc.uname[:machine]}"
160
+ return hash.fetch(machine.to_sym, machine)
140
161
  end
141
162
 
142
163
  # @param [Array<String>] arguments
@@ -159,6 +180,7 @@ module DockerCore
159
180
  end
160
181
 
161
182
  # @param [Array<String>] arguments
183
+ # @param [String, Integer] mode
162
184
  def self.change_mode(mode, *arguments)
163
185
  self.find_paths(*arguments).each do |path|
164
186
  FileUtils.chmod_R(mode, path, force: true)
@@ -166,6 +188,7 @@ module DockerCore
166
188
  end
167
189
 
168
190
  # @param [Array<String>] arguments
191
+ # @param [Integer, nil] mode
169
192
  def self.make_folders(*arguments, mode: nil)
170
193
  stack = []
171
194
  paths = arguments.map do |path|
@@ -198,8 +221,8 @@ module DockerCore
198
221
  # @param [String, Array<String>] source
199
222
  # @param [String] target
200
223
  def self.move_paths(source, target)
201
- files = [source].flatten
202
- FileUtils.mv(self.find_paths(*files), target)
224
+ paths = [source].flatten
225
+ FileUtils.mv(self.find_paths(*paths), target)
203
226
  end
204
227
 
205
228
  # @param [String] uri
@@ -228,9 +251,10 @@ module DockerCore
228
251
  return File.binwrite(file, content)
229
252
  end
230
253
 
254
+ # @param [Object] io
231
255
  # @param [String] path
232
256
  # @param [Boolean] verbose
233
- def self.untar(io, path, verbose: false)
257
+ def self.unpack_archive(io, path, verbose: false)
234
258
  Gem::Package::TarReader.new(io) do
235
259
 
236
260
  # @type [Gem::Package::TarReader] reader
@@ -243,7 +267,7 @@ module DockerCore
243
267
  file = File.join(path, entry.full_name)
244
268
 
245
269
  if verbose
246
- self.echo(": #{file}", Color::GREEN)
270
+ Color.echo(": #{file}", Color::GREEN)
247
271
  end
248
272
 
249
273
  if entry.directory?
@@ -264,18 +288,18 @@ module DockerCore
264
288
  # @param [String] file
265
289
  # @param [String] path
266
290
  # @param [Boolean] verbose
267
- def self.ungzip(file, path, verbose: false)
291
+ def self.inflate_file(file, path, verbose: false)
268
292
  Zlib::GzipReader.open(file) do
269
293
 
270
294
  # @type [Zlib::GzipReader] reader
271
295
  |reader|
272
- self.untar(reader, path, verbose: verbose)
296
+ self.unpack_archive(reader, path, verbose: verbose)
273
297
  end
274
298
  end
275
299
 
276
300
  # @param [String] path
277
301
  # @param [Boolean] verbose
278
- def self.tar(path, verbose: false)
302
+ def self.tape_archive(path, verbose: false)
279
303
  io = StringIO.new('')
280
304
  offset = path.size + 1
281
305
 
@@ -288,7 +312,7 @@ module DockerCore
288
312
  file = name.slice(offset ..)
289
313
 
290
314
  if verbose
291
- self.echo(": #{file}", Color::GREEN)
315
+ Color.echo(": #{file}", Color::GREEN)
292
316
  end
293
317
 
294
318
  if File.directory?(name)
@@ -312,22 +336,24 @@ module DockerCore
312
336
  # @param [String] file
313
337
  # @param [String] path
314
338
  # @param [Boolean] verbose
315
- def self.gzip(file, path, verbose: false)
339
+ def self.deflate_file(file, path, verbose: false)
316
340
  Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
317
341
 
318
342
  # @type [Zlib::GzipWriter] writer
319
343
  |writer|
320
- writer.write(self.tar(path, verbose: verbose))
344
+ writer.write(self.tape_archive(path, verbose: verbose))
321
345
  end
322
346
  end
323
347
 
324
348
  # @param [Integer] uid
325
349
  # @param [Integer] gid
326
350
  def self.update_user(uid: 500, gid: 500)
327
- self.run('deluser', USER, force: true)
328
- self.run('delgroup', GROUP, force: true)
329
- self.run('addgroup', { system: true, gid: ENV.fetch('DOCKER_CORE_GID', gid) }, GROUP)
330
- self.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: ENV.fetch('DOCKER_CORE_UID', uid) }, USER)
351
+ uid = ENV.fetch('DOCKER_CORE_UID', uid)
352
+ gid = ENV.fetch('DOCKER_CORE_GID', gid)
353
+ Process.run('deluser', USER, force: true)
354
+ Process.run('delgroup', GROUP, force: true)
355
+ Process.run('addgroup', { system: true, gid: gid }, GROUP)
356
+ Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
331
357
  end
332
358
 
333
359
  # @param [String] stdout
@@ -340,24 +366,22 @@ module DockerCore
340
366
  if '' != stderr
341
367
  File.symlink('/dev/stderr', File.path(stderr))
342
368
  end
369
+
370
+ return
343
371
  end
344
372
 
345
373
  # @param [Array<String>] arguments
374
+ # @param [Integer ,nil] mode
346
375
  def self.clear_folders(*arguments, mode: nil)
347
376
  self.remove_paths(*arguments)
348
377
  self.make_folders(*arguments, mode: mode)
349
378
  end
350
379
 
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
380
  # @param [String] repository
358
381
  def self.github_latest_version(repository)
359
382
  uri = URI("https://api.github.com/repos/#{repository}/releases/latest")
360
- return JSON.parse(Net::HTTP.get(uri))['tag_name']
383
+ data = JSON.parse(Net::HTTP.get(uri))['tag_name']
384
+ return "#{data}"
361
385
  end
362
386
  end
363
387
 
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.19
4
+ version: 0.0.20
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-25 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fileutils