docker_core 0.0.18 → 0.0.22

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 +128 -90
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f80afb4258260ec1da58951eca584f9321f0f21b13f0137865ca42c5852944f
4
- data.tar.gz: 8d1c6a6d11b3365c23fb67f618e63d20087afe72bc11b09c9c005cf666daac4b
3
+ metadata.gz: 9e24b7a9fd2ff938ceda59f6846768c1e414dd54b9b99ee22d8384a3044d1978
4
+ data.tar.gz: 4b15e835e7b275c3b8dbbb5e82db512870a07d551f3064f7f0ce2a8e9606e625
5
5
  SHA512:
6
- metadata.gz: d79c07a8abea54822b90858b3a27e6894dc2d51dd509f37769e879a60c33ee66806fb663480aef403524e93243c4ca02fbfdb3cef23672f1acd132cc41cdf128
7
- data.tar.gz: 2e497a18fc9afcefcadc97fc0b89fc364e7dc6c70d78100d426ce05e18db49fe99122f4075c68376eb4737862bfd6577ceafd2f51114cef4659e01449ab7734c
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
- module Shell
11
- # include(Thor::Shell)
10
+ USER = 'core'
11
+ GROUP = 'core'
12
12
 
13
- USER = 'core'
14
- GROUP = 'core'
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
- class Color < Thor::Shell::Color
26
+ next "#{color}"
27
+ end.join
28
+
29
+ return puts("#{color}#{text}#{self::CLEAR}")
17
30
  end
31
+ end
18
32
 
19
- module Paser
20
- # @param [String] value
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
- # @param [String] text
26
- def self.kebab(text)
27
- return "#{text}".gsub(/_/, '-')
28
- end
36
+ module Image
37
+ end
29
38
 
30
- # @param [Hash] hash
31
- def self.options(hash = {})
32
- items = []
39
+ module Command
40
+ end
33
41
 
34
- hash.each do |key, value|
35
- name = '--' + self.kebab(key)
36
- item = (true == value) ? name : %Q(#{name}="#{value}")
37
- items << item
38
- end
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
- return items
41
- end
48
+ # @param [String] text
49
+ def self.kebab(text)
50
+ return "#{text}".gsub(/_/, '-')
51
+ end
42
52
 
43
- def self.make(*arguments)
44
- items = []
53
+ # @param [Hash] hash
54
+ def self.options(hash)
55
+ items = []
45
56
 
46
- arguments.each do |item|
47
- if item.is_a?(Array)
48
- items.concat(item.map { |value| "#{value}" })
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 item.is_a?(Hash)
53
- items.concat(self.options(item))
61
+ if true == value
62
+ items << name
54
63
  next
55
64
  end
56
65
 
57
- items << "#{item}"
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 [String] text
66
- # @param [Array<String>] colors
67
- def self.echo(text, *colors)
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
- color = colors.map do |color|
73
- if color.is_a?(Symbol)
74
- next Color.const_get(color.to_s.upcase)
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
- next "#{color}"
78
- end.join
85
+ if item.is_a?(Hash)
86
+ list.concat(self.options(item))
87
+ next
88
+ end
79
89
 
80
- return puts("#{color}#{text}#{Color::CLEAR}")
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.make(*arguments).join(' ')
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
- def self.capture(*arguments, strip: true, verbose: false, substitute: false)
93
- command = self.command(*arguments, substitute: substitute)
94
-
95
- if verbose
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
- data = `#{command}`
100
- return strip ? "#{data}".strip : data
101
- end
118
+ if verbose
119
+ Color.echo("+ #{command}", Color::GREEN)
120
+ end
102
121
 
103
- # @param [Boolean] force
104
- def self.run(*arguments, force: false, substitute: false)
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 force
125
+ raise unless exception
126
+ return ''
110
127
  end
111
128
  end
112
129
 
113
- # @param [Boolean] force
114
- # @param [String] user
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
- self.echo("= #{command}", Color::CYAN)
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
- self.echo("> #{title}", color)
152
+ Color.echo("> #{title}", color)
127
153
  delegate.call(*arguments)
128
- self.echo("< #{title}", color)
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
- files = [source].flatten
191
- FileUtils.mv(self.find_paths(*files), target)
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.untar(io, path, verbose: false)
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
- self.echo(": #{file}", Color::GREEN)
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.ungzip(file, path, verbose: false)
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.untar(reader, path, verbose: verbose)
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.tar(path, verbose: false)
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
- self.echo(": #{file}", Color::GREEN)
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.gzip(file, path, verbose: false)
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.tar(path, verbose: verbose))
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
- self.run('deluser', USER, force: true)
317
- self.run('delgroup', GROUP, force: true)
318
- self.run('addgroup', { system: true, gid: ENV.fetch('DOCKER_CORE_GID', gid) }, GROUP)
319
- 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)
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
- return JSON.parse(Net::HTTP.get(uri))['tag_name']
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.18
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-25 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fileutils