docker_core 0.0.31 → 0.0.35
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 +97 -25
- 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: 7d26f53611ff2fae746c097de480885cb51ab1e142a4dea4e94d0963b5271022
|
4
|
+
data.tar.gz: f60a3b3dc891178eda615cce425080f556dd2c0e7536e7f8bd6678b7a3a94b2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57b4897a6dab83a917487b0d9e3592f0c4543e6838411d4ccd0720306f912827d0bfa1563e47e0db1e46b16a3b7ea13a4769bffecdb89defd2cb804240276297
|
7
|
+
data.tar.gz: '09f727751538859678f5808942293db69a022d9b2c38615f88e6f07c070ec40e9e38e3b408dd3633c065319589f05bd1d5b4c14bd322f54e2a96b072f8ee3e50'
|
data/lib/docker_core.rb
CHANGED
@@ -14,6 +14,56 @@ 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
|
+
|
62
|
+
def self.maximum_redirect
|
63
|
+
raise('maximum redirect reached')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
17
67
|
class Color < Thor::Shell::Color
|
18
68
|
# @param [String] text
|
19
69
|
# @param [Array<String>] colors
|
@@ -40,6 +90,9 @@ module DockerCore
|
|
40
90
|
module Image
|
41
91
|
end
|
42
92
|
|
93
|
+
module Orchestrator
|
94
|
+
end
|
95
|
+
|
43
96
|
module Command
|
44
97
|
end
|
45
98
|
|
@@ -48,8 +101,8 @@ module DockerCore
|
|
48
101
|
# @param [String] registry
|
49
102
|
# @param [String] namespace
|
50
103
|
# @param [String] tag
|
51
|
-
def self.
|
52
|
-
return
|
104
|
+
def self.from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest')
|
105
|
+
return "#{registry}/#{namespace}/#{image}:#{tag}"
|
53
106
|
end
|
54
107
|
|
55
108
|
def self.deploy_path
|
@@ -60,6 +113,14 @@ module DockerCore
|
|
60
113
|
return File.expand_path('~/.swarm')
|
61
114
|
end
|
62
115
|
|
116
|
+
# def self.profile_path
|
117
|
+
# return File.realpath('profile.sh', self.deploy_path)
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# def self.runner_path
|
121
|
+
# return File.realpath('runner.rb', self.deploy_path)
|
122
|
+
# end
|
123
|
+
|
63
124
|
# @param [String] swarm
|
64
125
|
def self.write_swarm(swarm = '')
|
65
126
|
return File.write(self.swarm_path, "#{swarm}\n")
|
@@ -74,7 +135,7 @@ module DockerCore
|
|
74
135
|
return { docker: Shell.is_active_unit('docker') }
|
75
136
|
end
|
76
137
|
|
77
|
-
def self.
|
138
|
+
def self.detect_orchestrator
|
78
139
|
swarm = self.read_swarm.to_sym
|
79
140
|
detect = self.detect_services
|
80
141
|
|
@@ -88,26 +149,24 @@ module DockerCore
|
|
88
149
|
|
89
150
|
def self.swarm_status
|
90
151
|
color = Color::GREEN
|
91
|
-
|
92
|
-
|
93
|
-
Color.echo("Swarm: #{detect}", color)
|
152
|
+
Color.echo("Swarm: #{self.detect_orchestrator}", color)
|
94
153
|
Color.echo(self.detect_services.to_yaml, color)
|
95
154
|
end
|
96
155
|
|
97
|
-
# @param [String]
|
98
|
-
def self.update_swarm(
|
99
|
-
if false ==
|
100
|
-
self.write_swarm(
|
156
|
+
# @param [String] orchestrator
|
157
|
+
def self.update_swarm(orchestrator = '')
|
158
|
+
if false == orchestrator.empty?
|
159
|
+
self.write_swarm(orchestrator)
|
101
160
|
end
|
102
161
|
|
103
|
-
|
104
|
-
self.write_swarm(
|
162
|
+
orchestrator = self.detect_orchestrator
|
163
|
+
self.write_swarm(orchestrator)
|
105
164
|
|
106
|
-
if
|
107
|
-
|
165
|
+
if orchestrator.empty?
|
166
|
+
orchestrator = '<none>'
|
108
167
|
end
|
109
168
|
|
110
|
-
Color.echo("Swarm: #{
|
169
|
+
Color.echo("Swarm: #{orchestrator}", Color::GREEN)
|
111
170
|
end
|
112
171
|
|
113
172
|
# @param [String] base
|
@@ -122,29 +181,44 @@ module DockerCore
|
|
122
181
|
return items
|
123
182
|
end
|
124
183
|
|
184
|
+
# @param [Array<String>] arguments
|
185
|
+
# @param [Array<String>] folders
|
186
|
+
def self.prepare_folders(*services, folders: %w[stack volume])
|
187
|
+
deploy = self.deploy_path
|
188
|
+
folders.each do |folder|
|
189
|
+
services.each do |service|
|
190
|
+
FileUtils.mkdir_p(File.join(deploy, folder, service))
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
125
195
|
# @param [Array] arguments
|
196
|
+
# @param [Hash] environment
|
197
|
+
# @param [Hash] bind
|
126
198
|
# @param [Boolean] throw
|
127
199
|
# @param [Numeric] wait
|
128
200
|
# @param [Boolean] strip
|
129
201
|
# @param [Boolean] echo
|
130
202
|
# @return [String]
|
131
|
-
def self.capture_command(*arguments, environment: {}, throw: false, wait: 0, strip: true, echo: false)
|
132
|
-
|
203
|
+
def self.capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false)
|
204
|
+
Error.no_method(__method__)
|
133
205
|
end
|
134
206
|
|
135
207
|
# @param [Array] arguments
|
208
|
+
# @param [Hash] environment
|
209
|
+
# @param [Hash] bind
|
136
210
|
# @param [Boolean] throw
|
137
211
|
# @param [Numeric] wait
|
138
212
|
# @param [Boolean] echo
|
139
213
|
# @return [Boolean]
|
140
|
-
def self.run_command(*arguments, environment: {}, throw: true, wait: 0, echo: true)
|
141
|
-
|
214
|
+
def self.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true)
|
215
|
+
Error.no_method(__method__)
|
142
216
|
end
|
143
217
|
|
144
218
|
#noinspection RubyClassVariableUsageInspection
|
145
|
-
def self.
|
146
|
-
@@
|
147
|
-
return "#{@@
|
219
|
+
def self.orchestrator
|
220
|
+
@@orchestrator ||= self.detect_orchestrator
|
221
|
+
return "#{@@orchestrator}"
|
148
222
|
end
|
149
223
|
|
150
224
|
end
|
@@ -391,7 +465,7 @@ module DockerCore
|
|
391
465
|
max_redirect = max_redirect - 1
|
392
466
|
|
393
467
|
if 0 == max_redirect
|
394
|
-
|
468
|
+
Error.maximum_redirect
|
395
469
|
end
|
396
470
|
|
397
471
|
return self.resolve_link(response['location'], max_redirect)
|
@@ -538,8 +612,6 @@ module DockerCore
|
|
538
612
|
data = JSON.parse(Net::HTTP.get(uri))['tag_name']
|
539
613
|
return "#{data}"
|
540
614
|
|
541
|
-
|
542
|
-
|
543
615
|
end
|
544
616
|
end
|
545
617
|
|
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.35
|
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
|