docker_core 0.0.23 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docker_core.rb +58 -47
- 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: 1ffc945fc5a13ce10567d97bdfda12a6f040ca26fb922f2e48b2537ae358aba6
|
4
|
+
data.tar.gz: 8814b75c42cf5e9793bbf4dcda92bde88d11e9bcf7cabd07cb14110d64bf6b7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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]
|
105
|
-
def self.wait(
|
106
|
-
if
|
107
|
-
if 0 >
|
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 <
|
111
|
-
return sleep(
|
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]
|
118
|
-
def self.command(*arguments,
|
119
|
-
if true ==
|
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
|
124
|
-
arguments.unshift('su-exec',
|
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]
|
132
|
-
# @param [Boolean]
|
133
|
-
# @param [Numeric]
|
132
|
+
# @param [Boolean, String] sudo
|
133
|
+
# @param [Boolean] throw
|
134
|
+
# @param [Numeric] wait
|
134
135
|
# @param [Boolean] strip
|
135
|
-
# @param [Boolean]
|
136
|
-
def self.capture(*arguments,
|
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:
|
139
|
+
command = self.command(*arguments, substitute: sudo)
|
139
140
|
|
140
|
-
if
|
141
|
-
Color.echo("
|
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(
|
147
|
+
self.wait(wait)
|
147
148
|
return result
|
148
149
|
rescue
|
149
|
-
raise unless
|
150
|
+
raise unless throw
|
150
151
|
return ''
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
154
155
|
# @param [Array] arguments
|
155
|
-
# @param [Boolean, String]
|
156
|
-
# @param [Boolean]
|
157
|
-
# @param [Numeric]
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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]
|
168
|
-
def self.execute(*arguments,
|
169
|
-
command = self.command(*arguments, substitute:
|
170
|
-
|
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]
|
287
|
-
def self.unpack_archive(io, path,
|
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
|
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]
|
321
|
-
def self.inflate_file(file, path,
|
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,
|
336
|
+
self.unpack_archive(reader, path, echo: echo)
|
327
337
|
end
|
328
338
|
end
|
329
339
|
|
330
340
|
# @param [String] path
|
331
|
-
# @param [Boolean]
|
332
|
-
def self.tape_archive(path,
|
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
|
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]
|
369
|
-
def self.deflate_file(file, path,
|
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,
|
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
|
-
|
384
|
-
Process.run('
|
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.
|
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-
|
11
|
+
date: 2021-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|