docker_core 0.0.29 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docker_core.rb +180 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2140de9087b77a0e18d16fce1b19d5e2717df2be9be9031d0b6428ca9edd82b
4
- data.tar.gz: eadb652ba7df647a1393fa97e96d125d755593c844720ee7ee926d4cd99d70fb
3
+ metadata.gz: 78790883b936bcf19663c2f53215d29a5d7712a7faaebd89f13e492ac9e99098
4
+ data.tar.gz: 21c7d7253185dc285019a21892359f2d48c28109c003af75b56272e0afe166d8
5
5
  SHA512:
6
- metadata.gz: 3a8239bb8ca67edb1b482daf19aa2b4d2e0a72e8b4ad68cff3d386b47b224ac97d82bc12e19af32af1a5e07c9c1feb709394291671f8a4fca9b45e137d43c208
7
- data.tar.gz: f0b5438ab72e169fdfed38bd7ab6165d326b5739d0f2d77c6610e22c68eb406eb76275231ac4ace0174c9e29bd414aa81743f69f64e546c9d2448a26c79ba61c
6
+ metadata.gz: 8be30ce90786a532a67b224ecd1e15a9608eb36536f71790d1d4deb7a9c6a98c03402022d3a197b3a4d4d5dddd0be252cdee24b4059c31c796511b290646b804
7
+ data.tar.gz: d274f01d320675e32986af240fe0a65f96a2a3d8acfbe410b7a49b64a4d016743a7da6ab7128edd8aa85560df06ccb3c09cf056438b92824ae4122ba81c9039f
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
@@ -35,11 +81,71 @@ module DockerCore
35
81
  end
36
82
 
37
83
  class Runner < Thor
84
+ desc('swarm_command', 'show swarm command')
85
+ def swarm_command
86
+ Process.run('ruby', Swarm.runner_path, sudo: false)
87
+ end
88
+
89
+ desc('swarm_setup', 'setup swarm')
90
+ def swarm_setup
91
+ Error.no_method(__method__)
92
+ end
93
+
94
+ desc('swarm_leave', 'leave swarm')
95
+ def swarm_leave
96
+ Error.no_method(__method__)
97
+ end
98
+
99
+ desc('stack_deploy', 'deploy stack')
100
+ def stack_deploy
101
+ Error.no_method(__method__)
102
+ end
103
+
104
+ desc('stack_remove', 'remove stack')
105
+ def stack_remove
106
+ Error.no_method(__method__)
107
+ end
108
+
109
+ desc('swarm_status', 'show swarm service status')
110
+ def swarm_status
111
+ Swarm.swarm_status
112
+ end
113
+
114
+ desc('update_swarm [orchestrator]', 'update default orchestrator')
115
+ def update_swarm(orchestrator = '')
116
+ Swarm.update_swarm(orchestrator)
117
+ end
118
+
119
+ desc('update_core', 'update gem docker_core')
120
+ def update_core
121
+ Process.run('gem update docker_core')
122
+ Process.run('gem clean')
123
+ end
124
+
125
+ desc('update_alias', 'update alias')
126
+ def update_alias
127
+ script = Swarm.script_path
128
+ method = __method__.to_s
129
+ items = ['unalias -a']
130
+
131
+ self.class.all_commands.filter do |key, value|
132
+ next false == ['help', method].include?("#{key}")
133
+ end.each do |key, value|
134
+ items << "alias #{key}='#{__FILE__} #{key}' "
135
+ end
136
+
137
+ items << "alias #{method}='source #{script}' \n"
138
+ File.write(File.expand_path('~/.bash_aliases'), items.join("\n"))
139
+ Color.echo("Update #{items.size} aliases", Color::GREEN)
140
+ end
38
141
  end
39
142
 
40
143
  module Image
41
144
  end
42
145
 
146
+ module Orchestrator
147
+ end
148
+
43
149
  module Command
44
150
  end
45
151
 
@@ -48,13 +154,22 @@ module DockerCore
48
154
  # @param [String] registry
49
155
  # @param [String] namespace
50
156
  # @param [String] tag
51
- def self.use_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest')
52
- return [registry, namespace, image].join('/') + ":#{tag}"
157
+ def self.from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest')
158
+ return "#{registry}/#{namespace}/#{image}:#{tag}"
159
+ end
160
+
161
+ # @return [String]
162
+ def self.script_path
163
+ Error.no_method(__method__)
53
164
  end
54
165
 
55
- # @param [String] service
56
- def self.service_actived(service)
57
- return 'active' == Process.capture("systemctl is-active #{service}").downcase
166
+ # @return [String]
167
+ def self.runner_path
168
+ Error.no_method(__method__)
169
+ end
170
+
171
+ def self.deploy_path
172
+ return File.expand_path('~/deploy')
58
173
  end
59
174
 
60
175
  def self.swarm_path
@@ -72,10 +187,10 @@ module DockerCore
72
187
  end
73
188
 
74
189
  def self.detect_services
75
- return { docker: self.service_actived('docker') }
190
+ return { docker: Shell.is_active_unit('docker') }
76
191
  end
77
192
 
78
- def self.detect_swarm
193
+ def self.detect_orchestrator
79
194
  swarm = self.read_swarm.to_sym
80
195
  detect = self.detect_services
81
196
 
@@ -89,27 +204,67 @@ module DockerCore
89
204
 
90
205
  def self.swarm_status
91
206
  color = Color::GREEN
92
- detect = self.detect_swarm
93
-
94
- Color.echo("Swarm: #{detect}", color)
207
+ Color.echo("Swarm: #{self.detect_orchestrator}", color)
95
208
  Color.echo(self.detect_services.to_yaml, color)
96
209
  end
97
210
 
98
- # @param [String] swarm
99
- def self.update_swarm(swarm = '')
100
- if false == swarm.empty?
101
- self.write_swarm(swarm)
211
+ # @param [String] orchestrator
212
+ def self.update_swarm(orchestrator = '')
213
+ if false == orchestrator.empty?
214
+ self.write_swarm(orchestrator)
102
215
  end
103
216
 
104
- swarm = self.detect_swarm
105
- self.write_swarm(swarm)
217
+ orchestrator = self.detect_orchestrator
218
+ self.write_swarm(orchestrator)
106
219
 
107
- if swarm.empty?
108
- swarm = 'none'
220
+ if orchestrator.empty?
221
+ orchestrator = '<none>'
109
222
  end
110
223
 
111
- Color.echo("Swarm: #{swarm}", Color::GREEN)
224
+ Color.echo("Swarm: #{orchestrator}", Color::GREEN)
225
+ end
226
+
227
+ # @param [String] base
228
+ # @param [String] relative
229
+ def self.pair_paths(base, relative = '')
230
+ items = {}
231
+
232
+ { inside: base, outside: Dir.pwd }.each do |key, value|
233
+ items[key] = File.join(value, relative)
234
+ end
235
+
236
+ return items
237
+ end
238
+
239
+ # @param [Array] arguments
240
+ # @param [Hash] environment
241
+ # @param [Hash] bind
242
+ # @param [Boolean] throw
243
+ # @param [Numeric] wait
244
+ # @param [Boolean] strip
245
+ # @param [Boolean] echo
246
+ # @return [String]
247
+ def self.capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false)
248
+ Error.no_method(__method__)
112
249
  end
250
+
251
+ # @param [Array] arguments
252
+ # @param [Hash] environment
253
+ # @param [Hash] bind
254
+ # @param [Boolean] throw
255
+ # @param [Numeric] wait
256
+ # @param [Boolean] echo
257
+ # @return [Boolean]
258
+ def self.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true)
259
+ Error.no_method(__method__)
260
+ end
261
+
262
+ #noinspection RubyClassVariableUsageInspection
263
+ def self.orchestrator
264
+ @@orchestrator ||= self.detect_orchestrator
265
+ return "#{@@orchestrator}"
266
+ end
267
+
113
268
  end
114
269
 
115
270
  module Paser
@@ -272,6 +427,11 @@ module DockerCore
272
427
  return hash.fetch(machine.to_sym, machine)
273
428
  end
274
429
 
430
+ # @param [String] unit
431
+ def self.is_active_unit(unit)
432
+ return 'active' == Process.capture("systemctl is-active #{unit}").downcase
433
+ end
434
+
275
435
  # @param [Array<String>] arguments
276
436
  # @return [Array<String>]
277
437
  def self.find_paths(*arguments)
@@ -495,6 +655,7 @@ module DockerCore
495
655
  uri = URI("https://api.github.com/repos/#{repository}/releases/latest")
496
656
  data = JSON.parse(Net::HTTP.get(uri))['tag_name']
497
657
  return "#{data}"
658
+
498
659
  end
499
660
  end
500
661
 
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.29
4
+ version: 0.0.33
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-01 00:00:00.000000000 Z
11
+ date: 2021-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fileutils