docker_core 0.0.23 → 0.0.27
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.
- checksums.yaml +4 -4
- data/lib/docker_core.rb +119 -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: da0b663870f8facf55cf16967c2e2fae3049bbedb497c89759251903f7fa4875
|
4
|
+
data.tar.gz: 9c6539f512f9430de020c30ffc53677a7ecb03aa4cb6d90578ce622d0d1f2ecd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f71c262f8071fa6f2e45c897909f67b15776320c7fe9925c8d4abc3a4242190b3ba6bce25856b1f498aa35caca15c453689b73c8239891ac381f267593a21eac
|
7
|
+
data.tar.gz: a0ff5f5cfa2c8152d71b17053c9f1a44904b62889252d2f917cab3170aac36886a09d211dc165c2657df80f39f0427bb8c6ab941d3ec1db24e816e0344b47c0c
|
data/lib/docker_core.rb
CHANGED
@@ -4,9 +4,11 @@ require('json')
|
|
4
4
|
require('net/http')
|
5
5
|
require('rubygems/package')
|
6
6
|
require('thor')
|
7
|
+
require('yaml')
|
7
8
|
require('zlib')
|
8
9
|
|
9
10
|
module DockerCore
|
11
|
+
SUDO = false
|
10
12
|
USER = 'core'
|
11
13
|
GROUP = 'core'
|
12
14
|
|
@@ -37,6 +39,66 @@ module DockerCore
|
|
37
39
|
end
|
38
40
|
|
39
41
|
module Command
|
42
|
+
module Swarm
|
43
|
+
def self.swarm_path
|
44
|
+
return File.expand_path('~/.swarm')
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param [String] service
|
48
|
+
def self.service_actived(service)
|
49
|
+
return 'active' == Process.capture("systemctl is-active #{service}").downcase
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param [String] swarm
|
53
|
+
def self.write_swarm(swarm = '')
|
54
|
+
return File.write(self.swarm_path, "#{swarm}\n")
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.read_swarm
|
58
|
+
file = self.swarm_path
|
59
|
+
return File.exists?(file) ? File.read(file).strip : ''
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.detect_services
|
63
|
+
return { docker: self.service_actived('docker') }
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.detect_swarm
|
67
|
+
swarm = self.read_swarm.to_sym
|
68
|
+
detect = self.detect_services
|
69
|
+
|
70
|
+
if detect.has_key?(swarm) && detect[swarm]
|
71
|
+
return "#{swarm}"
|
72
|
+
end
|
73
|
+
|
74
|
+
index = detect.key(true)
|
75
|
+
return "#{index}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.swarm_status
|
79
|
+
color = Color::GREEN
|
80
|
+
detect = self.detect_swarm
|
81
|
+
|
82
|
+
Color.echo("Swarm: #{detect}", color)
|
83
|
+
Color.echo(self.detect_services.to_yaml, color)
|
84
|
+
end
|
85
|
+
|
86
|
+
# @param [String] swarm
|
87
|
+
def self.update_swarm(swarm = '')
|
88
|
+
if false == swarm.empty?
|
89
|
+
self.write_swarm(swarm)
|
90
|
+
end
|
91
|
+
|
92
|
+
swarm = self.detect_swarm
|
93
|
+
self.write_swarm(swarm)
|
94
|
+
|
95
|
+
if swarm.empty?
|
96
|
+
swarm = 'none'
|
97
|
+
end
|
98
|
+
|
99
|
+
Color.echo("Swarm: #{swarm}", Color::GREEN)
|
100
|
+
end
|
101
|
+
end
|
40
102
|
end
|
41
103
|
|
42
104
|
module Paser
|
@@ -101,73 +163,82 @@ module DockerCore
|
|
101
163
|
end
|
102
164
|
|
103
165
|
module Process
|
104
|
-
# @param [Numeric]
|
105
|
-
def self.wait(
|
106
|
-
if
|
107
|
-
if 0 >
|
166
|
+
# @param [Numeric] second
|
167
|
+
def self.wait(second = 0)
|
168
|
+
if second.is_a?(Numeric)
|
169
|
+
if 0 > second
|
108
170
|
return sleep
|
109
171
|
end
|
110
|
-
if 0 <
|
111
|
-
return sleep(
|
172
|
+
if 0 < second
|
173
|
+
return sleep(second)
|
112
174
|
end
|
113
175
|
end
|
114
176
|
end
|
115
177
|
|
116
178
|
# @param [Array] arguments
|
117
|
-
# @param [Boolean, String]
|
118
|
-
def self.command(*arguments,
|
119
|
-
if true ==
|
179
|
+
# @param [Boolean, String] sudo
|
180
|
+
def self.command(*arguments, sudo: SUDO)
|
181
|
+
if true == sudo
|
120
182
|
arguments.unshift('sudo')
|
121
183
|
end
|
122
184
|
|
123
|
-
if
|
124
|
-
arguments.unshift('su-exec',
|
185
|
+
if sudo.is_a?(String) && false == "#{sudo}".empty?
|
186
|
+
arguments.unshift('su-exec', sudo)
|
125
187
|
end
|
126
188
|
|
127
189
|
return Paser.arguments(*arguments).join(' ')
|
128
190
|
end
|
129
191
|
|
130
192
|
# @param [Array] arguments
|
131
|
-
# @param [Boolean, String]
|
132
|
-
# @param [Boolean]
|
133
|
-
# @param [Numeric]
|
193
|
+
# @param [Boolean, String] sudo
|
194
|
+
# @param [Boolean] throw
|
195
|
+
# @param [Numeric] wait
|
134
196
|
# @param [Boolean] strip
|
135
|
-
# @param [Boolean]
|
136
|
-
def self.capture(*arguments,
|
197
|
+
# @param [Boolean] echo
|
198
|
+
def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false)
|
137
199
|
begin
|
138
|
-
command = self.command(*arguments,
|
200
|
+
command = self.command(*arguments, sudo: sudo)
|
139
201
|
|
140
|
-
if
|
141
|
-
Color.echo("
|
202
|
+
if echo
|
203
|
+
Color.echo(": #{command}", Color::YELLOW)
|
142
204
|
end
|
143
205
|
|
144
206
|
data = `#{command}`
|
145
207
|
result = strip ? "#{data}".strip : data
|
146
|
-
self.wait(
|
208
|
+
self.wait(wait)
|
147
209
|
return result
|
148
210
|
rescue
|
149
|
-
raise unless
|
211
|
+
raise unless throw
|
150
212
|
return ''
|
151
213
|
end
|
152
214
|
end
|
153
215
|
|
154
216
|
# @param [Array] arguments
|
155
|
-
# @param [Boolean, String]
|
156
|
-
# @param [Boolean]
|
157
|
-
# @param [Numeric]
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
217
|
+
# @param [Boolean, String] sudo
|
218
|
+
# @param [Boolean] throw
|
219
|
+
# @param [Numeric] wait
|
220
|
+
# @param [Boolean] echo
|
221
|
+
def self.run(*arguments, sudo: SUDO, throw: true, wait: 0, echo: true)
|
222
|
+
command = self.command(*arguments, sudo: sudo)
|
223
|
+
|
224
|
+
if echo
|
225
|
+
Color.echo("+ #{command}", Color::GREEN)
|
226
|
+
end
|
227
|
+
|
228
|
+
result = system(command, exception: throw)
|
229
|
+
self.wait(wait)
|
163
230
|
return result
|
164
231
|
end
|
165
232
|
|
166
233
|
# @param [Array] arguments
|
167
|
-
# @param [Boolean, String]
|
168
|
-
def self.execute(*arguments,
|
169
|
-
command = self.command(*arguments,
|
170
|
-
|
234
|
+
# @param [Boolean, String] sudo
|
235
|
+
def self.execute(*arguments, sudo: SUDO, echo: true)
|
236
|
+
command = self.command(*arguments, sudo: sudo)
|
237
|
+
|
238
|
+
if echo
|
239
|
+
Color.echo("= #{command}", Color::CYAN)
|
240
|
+
end
|
241
|
+
|
171
242
|
exec(command)
|
172
243
|
end
|
173
244
|
|
@@ -283,8 +354,8 @@ module DockerCore
|
|
283
354
|
|
284
355
|
# @param [Object] io
|
285
356
|
# @param [String] path
|
286
|
-
# @param [Boolean]
|
287
|
-
def self.unpack_archive(io, path,
|
357
|
+
# @param [Boolean] echo
|
358
|
+
def self.unpack_archive(io, path, echo: false)
|
288
359
|
Gem::Package::TarReader.new(io) do
|
289
360
|
|
290
361
|
# @type [Gem::Package::TarReader] reader
|
@@ -296,7 +367,7 @@ module DockerCore
|
|
296
367
|
mode = header.mode
|
297
368
|
file = File.join(path, entry.full_name)
|
298
369
|
|
299
|
-
if
|
370
|
+
if echo
|
300
371
|
Color.echo(": #{file}", Color::GREEN)
|
301
372
|
end
|
302
373
|
|
@@ -317,19 +388,19 @@ module DockerCore
|
|
317
388
|
|
318
389
|
# @param [String] file
|
319
390
|
# @param [String] path
|
320
|
-
# @param [Boolean]
|
321
|
-
def self.inflate_file(file, path,
|
391
|
+
# @param [Boolean] echo
|
392
|
+
def self.inflate_file(file, path, echo: false)
|
322
393
|
Zlib::GzipReader.open(file) do
|
323
394
|
|
324
395
|
# @type [Zlib::GzipReader] reader
|
325
396
|
|reader|
|
326
|
-
self.unpack_archive(reader, path,
|
397
|
+
self.unpack_archive(reader, path, echo: echo)
|
327
398
|
end
|
328
399
|
end
|
329
400
|
|
330
401
|
# @param [String] path
|
331
|
-
# @param [Boolean]
|
332
|
-
def self.tape_archive(path,
|
402
|
+
# @param [Boolean] echo
|
403
|
+
def self.tape_archive(path, echo: false)
|
333
404
|
io = StringIO.new('')
|
334
405
|
offset = path.size + 1
|
335
406
|
|
@@ -341,7 +412,7 @@ module DockerCore
|
|
341
412
|
mode = File.stat(name).mode
|
342
413
|
file = name.slice(offset ..)
|
343
414
|
|
344
|
-
if
|
415
|
+
if echo
|
345
416
|
Color.echo(": #{file}", Color::GREEN)
|
346
417
|
end
|
347
418
|
|
@@ -365,13 +436,13 @@ module DockerCore
|
|
365
436
|
|
366
437
|
# @param [String] file
|
367
438
|
# @param [String] path
|
368
|
-
# @param [Boolean]
|
369
|
-
def self.deflate_file(file, path,
|
439
|
+
# @param [Boolean] echo
|
440
|
+
def self.deflate_file(file, path, echo: false)
|
370
441
|
Zlib::GzipWriter.open(file, Zlib::BEST_COMPRESSION) do
|
371
442
|
|
372
443
|
# @type [Zlib::GzipWriter] writer
|
373
444
|
|writer|
|
374
|
-
writer.write(self.tape_archive(path,
|
445
|
+
writer.write(self.tape_archive(path, echo: echo))
|
375
446
|
end
|
376
447
|
end
|
377
448
|
|
@@ -380,8 +451,9 @@ module DockerCore
|
|
380
451
|
def self.update_user(uid: 500, gid: 500)
|
381
452
|
uid = ENV.fetch('DOCKER_CORE_UID', uid)
|
382
453
|
gid = ENV.fetch('DOCKER_CORE_GID', gid)
|
383
|
-
|
384
|
-
Process.run('
|
454
|
+
|
455
|
+
Process.run('deluser', USER, throw: false)
|
456
|
+
Process.run('delgroup', GROUP, throw: false)
|
385
457
|
Process.run('addgroup', { system: true, gid: gid }, GROUP)
|
386
458
|
Process.run('adduser', { system: true, 'disabled-password': true, 'no-create-home': true, ingroup: GROUP, gecos: USER, shell: '/bin/bash', uid: uid }, USER)
|
387
459
|
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.27
|
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-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|