docker_core 0.0.22 → 0.0.26
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 +135 -40
- 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: 59611c639cd8210b57b49f5c538f05b31c840c693c174ad97a0910ae0910713a
|
4
|
+
data.tar.gz: 267162407a1497ef11607b92328b17d8896465fa309bcec0ade8d29e41fabde2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28ab87b38c6cd69fa0bf13ad9187058b48b3d461cef229c4c2c4d24a2f3abb33fabe5a8c7b7383f6b0ba72a2f138b4a52ceaab15ba9d4932debfa4e065e8272a
|
7
|
+
data.tar.gz: 2ad3d345775b85deae503d88f860194aead2db16a3fea44f9e70d7c7e2571f6bc0ce4234bf6ce5bf8beff5dd0c14a04909527ffa8907d34fe3cb4fcdba946a52
|
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
|
|
@@ -37,6 +38,63 @@ module DockerCore
|
|
37
38
|
end
|
38
39
|
|
39
40
|
module Command
|
41
|
+
module Swarm
|
42
|
+
def self.swarm_path
|
43
|
+
return File.expand_path('~/.swarm')
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param [String] service
|
47
|
+
def self.service_actived(service)
|
48
|
+
return 'active' == Process.capture("systemctl is-active #{service}").downcase
|
49
|
+
end
|
50
|
+
|
51
|
+
# @param [String] name
|
52
|
+
def self.write_swarm(name = '')
|
53
|
+
return File.write(self.swarm_path, "#{name}\n")
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.read_swarm
|
57
|
+
file = self.swarm_path
|
58
|
+
return File.exists?(file) ? File.read(file).strip : ''
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param [String] name
|
62
|
+
def self.update_swarm(name = '')
|
63
|
+
if false == name.empty?
|
64
|
+
self.write_swarm(name)
|
65
|
+
end
|
66
|
+
|
67
|
+
name = self.detect_swarm
|
68
|
+
self.write_swarm(name)
|
69
|
+
|
70
|
+
if name.empty?
|
71
|
+
name = 'none'
|
72
|
+
end
|
73
|
+
|
74
|
+
Color.echo("Swarm: #{name}", Color::GREEN)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.detect_swarm
|
78
|
+
swarm = self.read_swarm
|
79
|
+
detect = self.detect_services
|
80
|
+
|
81
|
+
if detect.has_key?(swarm) && detect[swarm.to_sym]
|
82
|
+
return swarm
|
83
|
+
end
|
84
|
+
|
85
|
+
index = detect.key(true)
|
86
|
+
|
87
|
+
if index.nil?
|
88
|
+
return ''
|
89
|
+
end
|
90
|
+
|
91
|
+
return index.to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.detect_services
|
95
|
+
return { docker: self.service_actived('docker') }
|
96
|
+
end
|
97
|
+
end
|
40
98
|
end
|
41
99
|
|
42
100
|
module Paser
|
@@ -56,15 +114,20 @@ module DockerCore
|
|
56
114
|
|
57
115
|
if hash.is_a?(Hash)
|
58
116
|
hash.each do |key, value|
|
59
|
-
|
117
|
+
short = 1 == key.length
|
118
|
+
prefix = short ? '-' : '--'
|
119
|
+
separator = short ? ' ' : '='
|
120
|
+
name = prefix + self.kebab(key)
|
60
121
|
|
61
122
|
if true == value
|
62
123
|
items << name
|
63
124
|
next
|
64
125
|
end
|
65
126
|
|
66
|
-
value
|
67
|
-
|
127
|
+
[value].flatten.each do |item|
|
128
|
+
item = "#{item}".gsub(/\\/, '\&\&').gsub('"', '\"')
|
129
|
+
items << %(#{name}#{separator}"#{item}")
|
130
|
+
end
|
68
131
|
next
|
69
132
|
end
|
70
133
|
end
|
@@ -96,51 +159,82 @@ module DockerCore
|
|
96
159
|
end
|
97
160
|
|
98
161
|
module Process
|
162
|
+
# @param [Numeric] second
|
163
|
+
def self.wait(second = 0)
|
164
|
+
if second.is_a?(Numeric)
|
165
|
+
if 0 > second
|
166
|
+
return sleep
|
167
|
+
end
|
168
|
+
if 0 < second
|
169
|
+
return sleep(second)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
99
174
|
# @param [Array] arguments
|
100
|
-
# @param [Boolean]
|
101
|
-
def self.command(*arguments,
|
102
|
-
if
|
103
|
-
arguments.unshift('
|
175
|
+
# @param [Boolean, String] sudo
|
176
|
+
def self.command(*arguments, sudo: SUDO)
|
177
|
+
if true == sudo
|
178
|
+
arguments.unshift('sudo')
|
179
|
+
end
|
180
|
+
|
181
|
+
if sudo.is_a?(String) && false == "#{sudo}".empty?
|
182
|
+
arguments.unshift('su-exec', sudo)
|
104
183
|
end
|
105
184
|
|
106
185
|
return Paser.arguments(*arguments).join(' ')
|
107
186
|
end
|
108
187
|
|
109
188
|
# @param [Array] arguments
|
110
|
-
# @param [Boolean]
|
111
|
-
# @param [Boolean]
|
189
|
+
# @param [Boolean, String] sudo
|
190
|
+
# @param [Boolean] throw
|
191
|
+
# @param [Numeric] wait
|
112
192
|
# @param [Boolean] strip
|
113
|
-
# @param [Boolean]
|
114
|
-
def self.capture(*arguments,
|
193
|
+
# @param [Boolean] echo
|
194
|
+
def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false)
|
115
195
|
begin
|
116
|
-
command = self.command(*arguments,
|
196
|
+
command = self.command(*arguments, sudo: sudo)
|
117
197
|
|
118
|
-
if
|
119
|
-
Color.echo("
|
198
|
+
if echo
|
199
|
+
Color.echo(": #{command}", Color::YELLOW)
|
120
200
|
end
|
121
201
|
|
122
202
|
data = `#{command}`
|
123
|
-
|
203
|
+
result = strip ? "#{data}".strip : data
|
204
|
+
self.wait(wait)
|
205
|
+
return result
|
124
206
|
rescue
|
125
|
-
raise unless
|
207
|
+
raise unless throw
|
126
208
|
return ''
|
127
209
|
end
|
128
210
|
end
|
129
211
|
|
130
212
|
# @param [Array] arguments
|
131
|
-
# @param [Boolean]
|
132
|
-
# @param [Boolean]
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
213
|
+
# @param [Boolean, String] sudo
|
214
|
+
# @param [Boolean] throw
|
215
|
+
# @param [Numeric] wait
|
216
|
+
# @param [Boolean] echo
|
217
|
+
def self.run(*arguments, sudo: SUDO, throw: true, wait: 0, echo: true)
|
218
|
+
command = self.command(*arguments, sudo: sudo)
|
219
|
+
|
220
|
+
if echo
|
221
|
+
Color.echo("+ #{command}", Color::GREEN)
|
222
|
+
end
|
223
|
+
|
224
|
+
result = system(command, exception: throw)
|
225
|
+
self.wait(wait)
|
226
|
+
return result
|
137
227
|
end
|
138
228
|
|
139
229
|
# @param [Array] arguments
|
140
|
-
# @param [Boolean]
|
141
|
-
def self.execute(*arguments,
|
142
|
-
command = self.command(*arguments,
|
143
|
-
|
230
|
+
# @param [Boolean, String] sudo
|
231
|
+
def self.execute(*arguments, sudo: SUDO, echo: true)
|
232
|
+
command = self.command(*arguments, sudo: sudo)
|
233
|
+
|
234
|
+
if echo
|
235
|
+
Color.echo("= #{command}", Color::CYAN)
|
236
|
+
end
|
237
|
+
|
144
238
|
exec(command)
|
145
239
|
end
|
146
240
|
|
@@ -256,8 +350,8 @@ module DockerCore
|
|
256
350
|
|
257
351
|
# @param [Object] io
|
258
352
|
# @param [String] path
|
259
|
-
# @param [Boolean]
|
260
|
-
def self.unpack_archive(io, path,
|
353
|
+
# @param [Boolean] echo
|
354
|
+
def self.unpack_archive(io, path, echo: false)
|
261
355
|
Gem::Package::TarReader.new(io) do
|
262
356
|
|
263
357
|
# @type [Gem::Package::TarReader] reader
|
@@ -269,7 +363,7 @@ module DockerCore
|
|
269
363
|
mode = header.mode
|
270
364
|
file = File.join(path, entry.full_name)
|
271
365
|
|
272
|
-
if
|
366
|
+
if echo
|
273
367
|
Color.echo(": #{file}", Color::GREEN)
|
274
368
|
end
|
275
369
|
|
@@ -290,19 +384,19 @@ module DockerCore
|
|
290
384
|
|
291
385
|
# @param [String] file
|
292
386
|
# @param [String] path
|
293
|
-
# @param [Boolean]
|
294
|
-
def self.inflate_file(file, path,
|
387
|
+
# @param [Boolean] echo
|
388
|
+
def self.inflate_file(file, path, echo: false)
|
295
389
|
Zlib::GzipReader.open(file) do
|
296
390
|
|
297
391
|
# @type [Zlib::GzipReader] reader
|
298
392
|
|reader|
|
299
|
-
self.unpack_archive(reader, path,
|
393
|
+
self.unpack_archive(reader, path, echo: echo)
|
300
394
|
end
|
301
395
|
end
|
302
396
|
|
303
397
|
# @param [String] path
|
304
|
-
# @param [Boolean]
|
305
|
-
def self.tape_archive(path,
|
398
|
+
# @param [Boolean] echo
|
399
|
+
def self.tape_archive(path, echo: false)
|
306
400
|
io = StringIO.new('')
|
307
401
|
offset = path.size + 1
|
308
402
|
|
@@ -314,7 +408,7 @@ module DockerCore
|
|
314
408
|
mode = File.stat(name).mode
|
315
409
|
file = name.slice(offset ..)
|
316
410
|
|
317
|
-
if
|
411
|
+
if echo
|
318
412
|
Color.echo(": #{file}", Color::GREEN)
|
319
413
|
end
|
320
414
|
|
@@ -338,13 +432,13 @@ module DockerCore
|
|
338
432
|
|
339
433
|
# @param [String] file
|
340
434
|
# @param [String] path
|
341
|
-
# @param [Boolean]
|
342
|
-
def self.deflate_file(file, path,
|
435
|
+
# @param [Boolean] echo
|
436
|
+
def self.deflate_file(file, path, echo: false)
|
343
437
|
Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
|
344
438
|
|
345
439
|
# @type [Zlib::GzipWriter] writer
|
346
440
|
|writer|
|
347
|
-
writer.write(self.tape_archive(path,
|
441
|
+
writer.write(self.tape_archive(path, echo: echo))
|
348
442
|
end
|
349
443
|
end
|
350
444
|
|
@@ -353,8 +447,9 @@ module DockerCore
|
|
353
447
|
def self.update_user(uid: 500, gid: 500)
|
354
448
|
uid = ENV.fetch('DOCKER_CORE_UID', uid)
|
355
449
|
gid = ENV.fetch('DOCKER_CORE_GID', gid)
|
356
|
-
|
357
|
-
Process.run('
|
450
|
+
|
451
|
+
Process.run('deluser', USER, throw: false)
|
452
|
+
Process.run('delgroup', GROUP, throw: false)
|
358
453
|
Process.run('addgroup', { system: true, gid: gid }, GROUP)
|
359
454
|
Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
|
360
455
|
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.26
|
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
|