docker_core 0.0.30 → 0.0.34
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 +89 -28
- 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: 5e196caa3ad51a15efa9e55d0def50e88d1798ae8df091b035b7c8b6cd2b2417
|
4
|
+
data.tar.gz: 2f1239749845ee727bdf21102d68fdf68ea686ab10bc1fb24509a3d265be9cfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ecbab6bd1ff332c4ef71749968f47ca85c483bf79bf0d8ec40046635a269c20366daac6867fe2203c3cac1024f756296c30cbefc53315c41cc6ddd94d0a6131
|
7
|
+
data.tar.gz: 292e36438fbaa30436978d94859e895ce06facf013b8d5af26ac8db727ec6df886e65cc3515573fe78c75a5c6138c72bc5965c163009fa80c666e09b155f9a62
|
data/lib/docker_core.rb
CHANGED
@@ -14,6 +14,52 @@ module DockerCore
|
|
14
14
|
REGISTRY = 'docker.io'
|
15
15
|
NAMESPACE = 'library'
|
16
16
|
|
17
|
+
module Base
|
18
|
+
module Command
|
19
|
+
module ClassMethod
|
20
|
+
# @return [String]
|
21
|
+
def from_image
|
22
|
+
Error.no_method(__method__)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
def work_folder
|
27
|
+
Error.no_method(__method__)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [Array] arguments
|
31
|
+
# @param [Boolean] throw
|
32
|
+
# @param [Numeric] wait
|
33
|
+
# @param [Boolean] strip
|
34
|
+
# @param [Boolean] echo
|
35
|
+
def capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false)
|
36
|
+
bind[Dir.pwd] = self.work_folder
|
37
|
+
Swarm.capture_command(self.from_image, *arguments, environment: environment, bind: bind, throw: throw, wait: wait, strip: strip, echo: echo)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @param [Array] arguments
|
41
|
+
# @param [Boolean] throw
|
42
|
+
# @param [Numeric] wait
|
43
|
+
# @param [Boolean] echo
|
44
|
+
def run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true)
|
45
|
+
bind[Dir.pwd] = self.work_folder
|
46
|
+
Swarm.run_command(self.from_image, *arguments, environment: environment, bind: bind, throw: throw, wait: wait, echo: echo)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.included(base)
|
51
|
+
base.extend(ClassMethod)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module Error
|
57
|
+
# @param [Symbol] method
|
58
|
+
def self.no_method(method)
|
59
|
+
raise("#{method} method should be implemented in concrete class")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
17
63
|
class Color < Thor::Shell::Color
|
18
64
|
# @param [String] text
|
19
65
|
# @param [Array<String>] colors
|
@@ -40,6 +86,9 @@ module DockerCore
|
|
40
86
|
module Image
|
41
87
|
end
|
42
88
|
|
89
|
+
module Orchestrator
|
90
|
+
end
|
91
|
+
|
43
92
|
module Command
|
44
93
|
end
|
45
94
|
|
@@ -48,19 +97,26 @@ module DockerCore
|
|
48
97
|
# @param [String] registry
|
49
98
|
# @param [String] namespace
|
50
99
|
# @param [String] tag
|
51
|
-
def self.
|
52
|
-
return
|
100
|
+
def self.from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest')
|
101
|
+
return "#{registry}/#{namespace}/#{image}:#{tag}"
|
53
102
|
end
|
54
103
|
|
55
|
-
|
56
|
-
|
57
|
-
return 'active' == Process.capture("systemctl is-active #{service}").downcase
|
104
|
+
def self.deploy_path
|
105
|
+
return File.expand_path('~/deploy')
|
58
106
|
end
|
59
107
|
|
60
108
|
def self.swarm_path
|
61
109
|
return File.expand_path('~/.swarm')
|
62
110
|
end
|
63
111
|
|
112
|
+
def self.profile_path
|
113
|
+
return File.realpath('profile.sh', self.deploy_path)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.runner_path
|
117
|
+
return File.realpath('runner.rb', self.deploy_path)
|
118
|
+
end
|
119
|
+
|
64
120
|
# @param [String] swarm
|
65
121
|
def self.write_swarm(swarm = '')
|
66
122
|
return File.write(self.swarm_path, "#{swarm}\n")
|
@@ -72,10 +128,10 @@ module DockerCore
|
|
72
128
|
end
|
73
129
|
|
74
130
|
def self.detect_services
|
75
|
-
return { docker:
|
131
|
+
return { docker: Shell.is_active_unit('docker') }
|
76
132
|
end
|
77
133
|
|
78
|
-
def self.
|
134
|
+
def self.detect_orchestrator
|
79
135
|
swarm = self.read_swarm.to_sym
|
80
136
|
detect = self.detect_services
|
81
137
|
|
@@ -89,26 +145,24 @@ module DockerCore
|
|
89
145
|
|
90
146
|
def self.swarm_status
|
91
147
|
color = Color::GREEN
|
92
|
-
|
93
|
-
|
94
|
-
Color.echo("Swarm: #{detect}", color)
|
148
|
+
Color.echo("Swarm: #{self.detect_orchestrator}", color)
|
95
149
|
Color.echo(self.detect_services.to_yaml, color)
|
96
150
|
end
|
97
151
|
|
98
|
-
# @param [String]
|
99
|
-
def self.update_swarm(
|
100
|
-
if false ==
|
101
|
-
self.write_swarm(
|
152
|
+
# @param [String] orchestrator
|
153
|
+
def self.update_swarm(orchestrator = '')
|
154
|
+
if false == orchestrator.empty?
|
155
|
+
self.write_swarm(orchestrator)
|
102
156
|
end
|
103
157
|
|
104
|
-
|
105
|
-
self.write_swarm(
|
158
|
+
orchestrator = self.detect_orchestrator
|
159
|
+
self.write_swarm(orchestrator)
|
106
160
|
|
107
|
-
if
|
108
|
-
|
161
|
+
if orchestrator.empty?
|
162
|
+
orchestrator = '<none>'
|
109
163
|
end
|
110
164
|
|
111
|
-
Color.echo("Swarm: #{
|
165
|
+
Color.echo("Swarm: #{orchestrator}", Color::GREEN)
|
112
166
|
end
|
113
167
|
|
114
168
|
# @param [String] base
|
@@ -124,28 +178,32 @@ module DockerCore
|
|
124
178
|
end
|
125
179
|
|
126
180
|
# @param [Array] arguments
|
181
|
+
# @param [Hash] environment
|
182
|
+
# @param [Hash] bind
|
127
183
|
# @param [Boolean] throw
|
128
184
|
# @param [Numeric] wait
|
129
185
|
# @param [Boolean] strip
|
130
186
|
# @param [Boolean] echo
|
131
187
|
# @return [String]
|
132
|
-
def self.capture_command(*arguments, environment: {}, throw: false, wait: 0, strip: true, echo: false)
|
133
|
-
|
188
|
+
def self.capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false)
|
189
|
+
Error.no_method(__method__)
|
134
190
|
end
|
135
191
|
|
136
192
|
# @param [Array] arguments
|
193
|
+
# @param [Hash] environment
|
194
|
+
# @param [Hash] bind
|
137
195
|
# @param [Boolean] throw
|
138
196
|
# @param [Numeric] wait
|
139
197
|
# @param [Boolean] echo
|
140
198
|
# @return [Boolean]
|
141
|
-
def self.run_command(*arguments, environment: {}, throw: true, wait: 0, echo: true)
|
142
|
-
|
199
|
+
def self.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true)
|
200
|
+
Error.no_method(__method__)
|
143
201
|
end
|
144
202
|
|
145
203
|
#noinspection RubyClassVariableUsageInspection
|
146
|
-
def self.
|
147
|
-
@@
|
148
|
-
return "#{@@
|
204
|
+
def self.orchestrator
|
205
|
+
@@orchestrator ||= self.detect_orchestrator
|
206
|
+
return "#{@@orchestrator}"
|
149
207
|
end
|
150
208
|
|
151
209
|
end
|
@@ -310,6 +368,11 @@ module DockerCore
|
|
310
368
|
return hash.fetch(machine.to_sym, machine)
|
311
369
|
end
|
312
370
|
|
371
|
+
# @param [String] unit
|
372
|
+
def self.is_active_unit(unit)
|
373
|
+
return 'active' == Process.capture("systemctl is-active #{unit}").downcase
|
374
|
+
end
|
375
|
+
|
313
376
|
# @param [Array<String>] arguments
|
314
377
|
# @return [Array<String>]
|
315
378
|
def self.find_paths(*arguments)
|
@@ -534,8 +597,6 @@ module DockerCore
|
|
534
597
|
data = JSON.parse(Net::HTTP.get(uri))['tag_name']
|
535
598
|
return "#{data}"
|
536
599
|
|
537
|
-
|
538
|
-
|
539
600
|
end
|
540
601
|
end
|
541
602
|
|
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.34
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agrozyme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|