docker_core 0.0.23 → 0.0.24

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docker_core.rb +58 -47
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80affaf62801f9396342f5e34a9b4d7d9c60cbb7734eb072c53fd639a0128795
4
- data.tar.gz: fb93776e06070bcf7633f4307d0c2fb16e0c1c447c1548dd57618319c61dd7aa
3
+ metadata.gz: 1ffc945fc5a13ce10567d97bdfda12a6f040ca26fb922f2e48b2537ae358aba6
4
+ data.tar.gz: 8814b75c42cf5e9793bbf4dcda92bde88d11e9bcf7cabd07cb14110d64bf6b7c
5
5
  SHA512:
6
- metadata.gz: 357c0774652360108f2a5cc9773b482999a3f454b0af977ab609b80618fbe8a2157af83d8bc1041afa1e0056f2aa7e7b61ec2f5fa60b56a7caff996296b07d8e
7
- data.tar.gz: 861b83b14df2c399f64a5a580dc61281414c0c581528118d38cbcdd044e09c79387fb334930c170b0197b3bd7f6c84a2739efb064112f60011131d26d034e926
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
 
@@ -101,73 +102,82 @@ module DockerCore
101
102
  end
102
103
 
103
104
  module Process
104
- # @param [Numeric] duration
105
- def self.wait(duration = 0)
106
- if duration.is_a?(Numeric)
107
- if 0 > duration
105
+ # @param [Numeric] second
106
+ def self.wait(second = 0)
107
+ if second.is_a?(Numeric)
108
+ if 0 > second
108
109
  return sleep
109
110
  end
110
- if 0 < duration
111
- return sleep(duration)
111
+ if 0 < second
112
+ return sleep(second)
112
113
  end
113
114
  end
114
115
  end
115
116
 
116
117
  # @param [Array] arguments
117
- # @param [Boolean, String] substitute
118
- def self.command(*arguments, substitute: false)
119
- if true == substitute
118
+ # @param [Boolean, String] sudo
119
+ def self.command(*arguments, sudo: SUDO)
120
+ if true == sudo
120
121
  arguments.unshift('sudo')
121
122
  end
122
123
 
123
- if substitute.is_a?(String) && false == "#{substitute}".empty?
124
- arguments.unshift('su-exec', substitute)
124
+ if sudo.is_a?(String) && false == "#{sudo}".empty?
125
+ arguments.unshift('su-exec', sudo)
125
126
  end
126
127
 
127
128
  return Paser.arguments(*arguments).join(' ')
128
129
  end
129
130
 
130
131
  # @param [Array] arguments
131
- # @param [Boolean, String] substitute
132
- # @param [Boolean] exception
133
- # @param [Numeric] duration
132
+ # @param [Boolean, String] sudo
133
+ # @param [Boolean] throw
134
+ # @param [Numeric] wait
134
135
  # @param [Boolean] strip
135
- # @param [Boolean] verbose
136
- def self.capture(*arguments, substitute: false, exception: false, duration: 0, strip: true, verbose: false)
136
+ # @param [Boolean] echo
137
+ def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false)
137
138
  begin
138
- command = self.command(*arguments, substitute: substitute)
139
+ command = self.command(*arguments, substitute: sudo)
139
140
 
140
- if verbose
141
- Color.echo("+ #{command}", Color::GREEN)
141
+ if echo
142
+ Color.echo(": #{command}", Color::YELLOW)
142
143
  end
143
144
 
144
145
  data = `#{command}`
145
146
  result = strip ? "#{data}".strip : data
146
- self.wait(duration)
147
+ self.wait(wait)
147
148
  return result
148
149
  rescue
149
- raise unless exception
150
+ raise unless throw
150
151
  return ''
151
152
  end
152
153
  end
153
154
 
154
155
  # @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)
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)
165
+ end
166
+
167
+ result = system(command, exception: throw)
168
+ self.wait(wait)
163
169
  return result
164
170
  end
165
171
 
166
172
  # @param [Array] arguments
167
- # @param [Boolean, String] substitute
168
- def self.execute(*arguments, substitute: false)
169
- command = self.command(*arguments, substitute: substitute)
170
- 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
+
171
181
  exec(command)
172
182
  end
173
183
 
@@ -283,8 +293,8 @@ module DockerCore
283
293
 
284
294
  # @param [Object] io
285
295
  # @param [String] path
286
- # @param [Boolean] verbose
287
- def self.unpack_archive(io, path, verbose: false)
296
+ # @param [Boolean] echo
297
+ def self.unpack_archive(io, path, echo: false)
288
298
  Gem::Package::TarReader.new(io) do
289
299
 
290
300
  # @type [Gem::Package::TarReader] reader
@@ -296,7 +306,7 @@ module DockerCore
296
306
  mode = header.mode
297
307
  file = File.join(path, entry.full_name)
298
308
 
299
- if verbose
309
+ if echo
300
310
  Color.echo(": #{file}", Color::GREEN)
301
311
  end
302
312
 
@@ -317,19 +327,19 @@ module DockerCore
317
327
 
318
328
  # @param [String] file
319
329
  # @param [String] path
320
- # @param [Boolean] verbose
321
- def self.inflate_file(file, path, verbose: false)
330
+ # @param [Boolean] echo
331
+ def self.inflate_file(file, path, echo: false)
322
332
  Zlib::GzipReader.open(file) do
323
333
 
324
334
  # @type [Zlib::GzipReader] reader
325
335
  |reader|
326
- self.unpack_archive(reader, path, verbose: verbose)
336
+ self.unpack_archive(reader, path, echo: echo)
327
337
  end
328
338
  end
329
339
 
330
340
  # @param [String] path
331
- # @param [Boolean] verbose
332
- def self.tape_archive(path, verbose: false)
341
+ # @param [Boolean] echo
342
+ def self.tape_archive(path, echo: false)
333
343
  io = StringIO.new('')
334
344
  offset = path.size + 1
335
345
 
@@ -341,7 +351,7 @@ module DockerCore
341
351
  mode = File.stat(name).mode
342
352
  file = name.slice(offset ..)
343
353
 
344
- if verbose
354
+ if echo
345
355
  Color.echo(": #{file}", Color::GREEN)
346
356
  end
347
357
 
@@ -365,13 +375,13 @@ module DockerCore
365
375
 
366
376
  # @param [String] file
367
377
  # @param [String] path
368
- # @param [Boolean] verbose
369
- def self.deflate_file(file, path, verbose: false)
378
+ # @param [Boolean] echo
379
+ def self.deflate_file(file, path, echo: false)
370
380
  Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
371
381
 
372
382
  # @type [Zlib::GzipWriter] writer
373
383
  |writer|
374
- writer.write(self.tape_archive(path, verbose: verbose))
384
+ writer.write(self.tape_archive(path, echo: echo))
375
385
  end
376
386
  end
377
387
 
@@ -380,8 +390,9 @@ module DockerCore
380
390
  def self.update_user(uid: 500, gid: 500)
381
391
  uid = ENV.fetch('DOCKER_CORE_UID', uid)
382
392
  gid = ENV.fetch('DOCKER_CORE_GID', gid)
383
- Process.run('deluser', USER, exception: false)
384
- Process.run('delgroup', GROUP, exception: false)
393
+
394
+ Process.run('deluser', USER, throw: false)
395
+ Process.run('delgroup', GROUP, throw: false)
385
396
  Process.run('addgroup', { system: true, gid: gid }, GROUP)
386
397
  Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
387
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.23
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-28 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