docker_core 0.0.20 → 0.0.24

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 +83 -42
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a39a514720435a65fbc3f039eee7c86503e501ab70b821656510b3ba8e8fe941
4
- data.tar.gz: 7c95deb803d9b5a095a8cc2a5758e926000065e22aaac2a2420a896ef2be2c81
3
+ metadata.gz: 1ffc945fc5a13ce10567d97bdfda12a6f040ca26fb922f2e48b2537ae358aba6
4
+ data.tar.gz: 8814b75c42cf5e9793bbf4dcda92bde88d11e9bcf7cabd07cb14110d64bf6b7c
5
5
  SHA512:
6
- metadata.gz: e0929e952d6d9c3bca9f1d0e5ca3a5f5fa9f193c545bbd0e286361ef7811f54c624db153354664f32e74eef2d20ce36632380a84c343273a05c5e71c435bf968
7
- data.tar.gz: 4e8ede2a599f2d820649d667f8b64e14d33227cd25abba7838b16202b1002633f4b363a91c7cf9dd709b99c036ff59210fb4deb76c8818946292a3a853c537fc
6
+ metadata.gz: bcce5fd8318a6d5e3795ac2da04f1f33a0dc84213ca919c47207834e9189ac489a28b291391ec2c9ed3817fa69cdd75107424fa90e7064f5243c92effc3db74a
7
+ data.tar.gz: 941379233235b53f26b4b630166b64fcb2cce08b1db259e7ea6e4ba0a1d08ef4111c21899f167123c9a29919c7c5adb9ccd495e66d3b9f3c4e51884de748819d
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
- name = '--' + self.kebab(key)
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 = "#{value}".gsub(/\\/, '\&\&').gsub('"', '\"')
67
- items << %(#{name}="#{value}")
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,48 +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] substitute
101
- def self.command(*arguments, substitute: false)
102
- if substitute
103
- arguments.unshift('su-exec', USER)
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
132
+ # @param [Boolean, String] sudo
133
+ # @param [Boolean] throw
134
+ # @param [Numeric] wait
110
135
  # @param [Boolean] strip
111
- # @param [Boolean] verbose
112
- # @param [Boolean] substitute
113
- def self.capture(*arguments, strip: true, verbose: false, substitute: false)
114
- command = self.command(*arguments, substitute: substitute)
136
+ # @param [Boolean] echo
137
+ def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false)
138
+ begin
139
+ command = self.command(*arguments, substitute: sudo)
115
140
 
116
- if verbose
117
- Color.echo("+ #{command}", Color::GREEN)
118
- end
141
+ if echo
142
+ Color.echo(": #{command}", Color::YELLOW)
143
+ end
119
144
 
120
- data = `#{command}`
121
- return strip ? "#{data}".strip : data
145
+ data = `#{command}`
146
+ result = strip ? "#{data}".strip : data
147
+ self.wait(wait)
148
+ return result
149
+ rescue
150
+ raise unless throw
151
+ return ''
152
+ end
122
153
  end
123
154
 
124
155
  # @param [Array] arguments
125
- # @param [Boolean] force
126
- # @param [Boolean] substitute
127
- def self.run(*arguments, force: false, substitute: false)
128
- begin
129
- data = self.capture(*arguments, strip: false, verbose: true, substitute: substitute)
130
- print(data)
131
- rescue
132
- raise unless force
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, substitute: sudo)
162
+
163
+ if echo
164
+ Color.echo("+ #{command}", Color::GREEN)
133
165
  end
166
+
167
+ result = system(command, exception: throw)
168
+ self.wait(wait)
169
+ return result
134
170
  end
135
171
 
136
172
  # @param [Array] arguments
137
- # @param [Boolean] substitute
138
- def self.execute(*arguments, substitute: false)
139
- command = self.command(*arguments, substitute: substitute)
140
- Color.echo("= #{command}", Color::CYAN)
173
+ # @param [Boolean, String] sudo
174
+ def self.execute(*arguments, sudo: SUDO, echo: true)
175
+ command = self.command(*arguments, substitute: sudo)
176
+
177
+ if echo
178
+ Color.echo("= #{command}", Color::CYAN)
179
+ end
180
+
141
181
  exec(command)
142
182
  end
143
183
 
@@ -253,8 +293,8 @@ module DockerCore
253
293
 
254
294
  # @param [Object] io
255
295
  # @param [String] path
256
- # @param [Boolean] verbose
257
- def self.unpack_archive(io, path, verbose: false)
296
+ # @param [Boolean] echo
297
+ def self.unpack_archive(io, path, echo: false)
258
298
  Gem::Package::TarReader.new(io) do
259
299
 
260
300
  # @type [Gem::Package::TarReader] reader
@@ -266,7 +306,7 @@ module DockerCore
266
306
  mode = header.mode
267
307
  file = File.join(path, entry.full_name)
268
308
 
269
- if verbose
309
+ if echo
270
310
  Color.echo(": #{file}", Color::GREEN)
271
311
  end
272
312
 
@@ -287,19 +327,19 @@ module DockerCore
287
327
 
288
328
  # @param [String] file
289
329
  # @param [String] path
290
- # @param [Boolean] verbose
291
- def self.inflate_file(file, path, verbose: false)
330
+ # @param [Boolean] echo
331
+ def self.inflate_file(file, path, echo: false)
292
332
  Zlib::GzipReader.open(file) do
293
333
 
294
334
  # @type [Zlib::GzipReader] reader
295
335
  |reader|
296
- self.unpack_archive(reader, path, verbose: verbose)
336
+ self.unpack_archive(reader, path, echo: echo)
297
337
  end
298
338
  end
299
339
 
300
340
  # @param [String] path
301
- # @param [Boolean] verbose
302
- def self.tape_archive(path, verbose: false)
341
+ # @param [Boolean] echo
342
+ def self.tape_archive(path, echo: false)
303
343
  io = StringIO.new('')
304
344
  offset = path.size + 1
305
345
 
@@ -311,7 +351,7 @@ module DockerCore
311
351
  mode = File.stat(name).mode
312
352
  file = name.slice(offset ..)
313
353
 
314
- if verbose
354
+ if echo
315
355
  Color.echo(": #{file}", Color::GREEN)
316
356
  end
317
357
 
@@ -335,13 +375,13 @@ module DockerCore
335
375
 
336
376
  # @param [String] file
337
377
  # @param [String] path
338
- # @param [Boolean] verbose
339
- def self.deflate_file(file, path, verbose: false)
378
+ # @param [Boolean] echo
379
+ def self.deflate_file(file, path, echo: false)
340
380
  Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
341
381
 
342
382
  # @type [Zlib::GzipWriter] writer
343
383
  |writer|
344
- writer.write(self.tape_archive(path, verbose: verbose))
384
+ writer.write(self.tape_archive(path, echo: echo))
345
385
  end
346
386
  end
347
387
 
@@ -350,8 +390,9 @@ module DockerCore
350
390
  def self.update_user(uid: 500, gid: 500)
351
391
  uid = ENV.fetch('DOCKER_CORE_UID', uid)
352
392
  gid = ENV.fetch('DOCKER_CORE_GID', gid)
353
- Process.run('deluser', USER, force: true)
354
- Process.run('delgroup', GROUP, force: true)
393
+
394
+ Process.run('deluser', USER, throw: false)
395
+ Process.run('delgroup', GROUP, throw: false)
355
396
  Process.run('addgroup', { system: true, gid: gid }, GROUP)
356
397
  Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
357
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.20
4
+ version: 0.0.24
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-26 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fileutils