docker_core 0.0.24 → 0.0.28
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 +74 -3
- 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: 22b3b50217c9f811a9d9ae487c688c304addd5d222e7858b1bbb8e37124e7452
|
4
|
+
data.tar.gz: d0c97be16c1570f4baaa58471e3ea0d829b041a35dffed98343b21bf8ad6c98b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af385ed4efc0cfa3506f6869f815cbbb2fd34a5b94fec38fc5997b4c905b363aab1d63eddc56f9463dc8d7ed4479d5b0520608daa463c52235277b657f710e56
|
7
|
+
data.tar.gz: 80aa115113462cbb17f2acf53e534c72ac141ec87838f3c9ce80b0ae05788f5386280d25bbf1f87a0a76b7310934597be09db1a2b91f59be3b79025d0065615c
|
data/lib/docker_core.rb
CHANGED
@@ -4,12 +4,15 @@ 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
|
10
11
|
SUDO = false
|
11
12
|
USER = 'core'
|
12
13
|
GROUP = 'core'
|
14
|
+
REGISTRY = 'docker.io'
|
15
|
+
NAMESPACE = 'library'
|
13
16
|
|
14
17
|
class Color < Thor::Shell::Color
|
15
18
|
# @param [String] text
|
@@ -38,6 +41,74 @@ module DockerCore
|
|
38
41
|
end
|
39
42
|
|
40
43
|
module Command
|
44
|
+
module Swarm
|
45
|
+
# @param [String] image
|
46
|
+
# @param [String] registry
|
47
|
+
# @param [String] namespace
|
48
|
+
# @param [String] tag
|
49
|
+
def self.use_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest')
|
50
|
+
return [registry, namespace, image].join('/') + ":#{tag}"
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param [String] service
|
54
|
+
def self.service_actived(service)
|
55
|
+
return 'active' == Process.capture("systemctl is-active #{service}").downcase
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.swarm_path
|
59
|
+
return File.expand_path('~/.swarm')
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param [String] swarm
|
63
|
+
def self.write_swarm(swarm = '')
|
64
|
+
return File.write(self.swarm_path, "#{swarm}\n")
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.read_swarm
|
68
|
+
file = self.swarm_path
|
69
|
+
return File.exists?(file) ? File.read(file).strip : ''
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.detect_services
|
73
|
+
return { docker: self.service_actived('docker') }
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.detect_swarm
|
77
|
+
swarm = self.read_swarm.to_sym
|
78
|
+
detect = self.detect_services
|
79
|
+
|
80
|
+
if detect.has_key?(swarm) && detect[swarm]
|
81
|
+
return "#{swarm}"
|
82
|
+
end
|
83
|
+
|
84
|
+
index = detect.key(true)
|
85
|
+
return "#{index}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.swarm_status
|
89
|
+
color = Color::GREEN
|
90
|
+
detect = self.detect_swarm
|
91
|
+
|
92
|
+
Color.echo("Swarm: #{detect}", color)
|
93
|
+
Color.echo(self.detect_services.to_yaml, color)
|
94
|
+
end
|
95
|
+
|
96
|
+
# @param [String] swarm
|
97
|
+
def self.update_swarm(swarm = '')
|
98
|
+
if false == swarm.empty?
|
99
|
+
self.write_swarm(swarm)
|
100
|
+
end
|
101
|
+
|
102
|
+
swarm = self.detect_swarm
|
103
|
+
self.write_swarm(swarm)
|
104
|
+
|
105
|
+
if swarm.empty?
|
106
|
+
swarm = 'none'
|
107
|
+
end
|
108
|
+
|
109
|
+
Color.echo("Swarm: #{swarm}", Color::GREEN)
|
110
|
+
end
|
111
|
+
end
|
41
112
|
end
|
42
113
|
|
43
114
|
module Paser
|
@@ -136,7 +207,7 @@ module DockerCore
|
|
136
207
|
# @param [Boolean] echo
|
137
208
|
def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false)
|
138
209
|
begin
|
139
|
-
command = self.command(*arguments,
|
210
|
+
command = self.command(*arguments, sudo: sudo)
|
140
211
|
|
141
212
|
if echo
|
142
213
|
Color.echo(": #{command}", Color::YELLOW)
|
@@ -158,7 +229,7 @@ module DockerCore
|
|
158
229
|
# @param [Numeric] wait
|
159
230
|
# @param [Boolean] echo
|
160
231
|
def self.run(*arguments, sudo: SUDO, throw: true, wait: 0, echo: true)
|
161
|
-
command = self.command(*arguments,
|
232
|
+
command = self.command(*arguments, sudo: sudo)
|
162
233
|
|
163
234
|
if echo
|
164
235
|
Color.echo("+ #{command}", Color::GREEN)
|
@@ -172,7 +243,7 @@ module DockerCore
|
|
172
243
|
# @param [Array] arguments
|
173
244
|
# @param [Boolean, String] sudo
|
174
245
|
def self.execute(*arguments, sudo: SUDO, echo: true)
|
175
|
-
command = self.command(*arguments,
|
246
|
+
command = self.command(*arguments, sudo: sudo)
|
176
247
|
|
177
248
|
if echo
|
178
249
|
Color.echo("= #{command}", Color::CYAN)
|
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.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agrozyme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|