docker_core 0.0.28 → 0.0.32

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 +99 -50
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22b3b50217c9f811a9d9ae487c688c304addd5d222e7858b1bbb8e37124e7452
4
- data.tar.gz: d0c97be16c1570f4baaa58471e3ea0d829b041a35dffed98343b21bf8ad6c98b
3
+ metadata.gz: 3462495808e195a26c503fcb47e809cd1cf3b14234785f54906da57c1312fadd
4
+ data.tar.gz: ca4e5679e8ea61bd243355a9b4ad68258d7da68086d51356e6105df10f51d206
5
5
  SHA512:
6
- metadata.gz: af385ed4efc0cfa3506f6869f815cbbb2fd34a5b94fec38fc5997b4c905b363aab1d63eddc56f9463dc8d7ed4479d5b0520608daa463c52235277b657f710e56
7
- data.tar.gz: 80aa115113462cbb17f2acf53e534c72ac141ec87838f3c9ce80b0ae05788f5386280d25bbf1f87a0a76b7310934597be09db1a2b91f59be3b79025d0065615c
6
+ metadata.gz: 5bc578621035135247e128d111ff55393725de6b3f237bc2c6d3eb7af2e8e8f36b8382461a3005a02ab4aa4f25a8a59cc98c6185e7453215c12a3573bfae2bf9
7
+ data.tar.gz: e28f011b67bcee8e3fac989191b8d727c5abadb6d58793f0a166fa75f4ffd2e29fc0552103bdb6f67e87fc4267aaa0431959db7ad8a075bbe09a91c0db7bc007
data/lib/docker_core.rb CHANGED
@@ -40,75 +40,118 @@ module DockerCore
40
40
  module Image
41
41
  end
42
42
 
43
+ module Orchestrator
44
+ end
45
+
43
46
  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
47
+ end
52
48
 
53
- # @param [String] service
54
- def self.service_actived(service)
55
- return 'active' == Process.capture("systemctl is-active #{service}").downcase
56
- end
49
+ module Swarm
50
+ # @param [String] image
51
+ # @param [String] registry
52
+ # @param [String] namespace
53
+ # @param [String] tag
54
+ def self.from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest')
55
+ return "#{registry}/#{namespace}/#{image}:#{tag}"
56
+ end
57
57
 
58
- def self.swarm_path
59
- return File.expand_path('~/.swarm')
60
- end
58
+ def self.deploy_path
59
+ return File.expand_path('~/deploy')
60
+ end
61
61
 
62
- # @param [String] swarm
63
- def self.write_swarm(swarm = '')
64
- return File.write(self.swarm_path, "#{swarm}\n")
65
- end
62
+ def self.swarm_path
63
+ return File.expand_path('~/.swarm')
64
+ end
66
65
 
67
- def self.read_swarm
68
- file = self.swarm_path
69
- return File.exists?(file) ? File.read(file).strip : ''
70
- end
66
+ # @param [String] swarm
67
+ def self.write_swarm(swarm = '')
68
+ return File.write(self.swarm_path, "#{swarm}\n")
69
+ end
71
70
 
72
- def self.detect_services
73
- return { docker: self.service_actived('docker') }
74
- end
71
+ def self.read_swarm
72
+ file = self.swarm_path
73
+ return File.exists?(file) ? File.read(file).strip : ''
74
+ end
75
75
 
76
- def self.detect_swarm
77
- swarm = self.read_swarm.to_sym
78
- detect = self.detect_services
76
+ def self.detect_services
77
+ return { docker: Shell.is_active_unit('docker') }
78
+ end
79
79
 
80
- if detect.has_key?(swarm) && detect[swarm]
81
- return "#{swarm}"
82
- end
80
+ def self.detect_orchestrator
81
+ swarm = self.read_swarm.to_sym
82
+ detect = self.detect_services
83
83
 
84
- index = detect.key(true)
85
- return "#{index}"
84
+ if detect.has_key?(swarm) && detect[swarm]
85
+ return "#{swarm}"
86
86
  end
87
87
 
88
- def self.swarm_status
89
- color = Color::GREEN
90
- detect = self.detect_swarm
88
+ index = detect.key(true)
89
+ return "#{index}"
90
+ end
91
+
92
+ def self.swarm_status
93
+ color = Color::GREEN
94
+ Color.echo("Swarm: #{self.detect_orchestrator}", color)
95
+ Color.echo(self.detect_services.to_yaml, color)
96
+ end
91
97
 
92
- Color.echo("Swarm: #{detect}", color)
93
- Color.echo(self.detect_services.to_yaml, color)
98
+ # @param [String] swarm
99
+ def self.update_swarm(swarm = '')
100
+ if false == swarm.empty?
101
+ self.write_swarm(swarm)
94
102
  end
95
103
 
96
- # @param [String] swarm
97
- def self.update_swarm(swarm = '')
98
- if false == swarm.empty?
99
- self.write_swarm(swarm)
100
- end
104
+ orchestrator = self.detect_orchestrator
105
+ self.write_swarm(orchestrator)
101
106
 
102
- swarm = self.detect_swarm
103
- self.write_swarm(swarm)
107
+ if orchestrator.empty?
108
+ orchestrator = '<none>'
109
+ end
104
110
 
105
- if swarm.empty?
106
- swarm = 'none'
107
- end
111
+ Color.echo("Swarm: #{orchestrator}", Color::GREEN)
112
+ end
113
+
114
+ # @param [String] base
115
+ # @param [String] relative
116
+ def self.pair_paths(base, relative = '')
117
+ items = {}
108
118
 
109
- Color.echo("Swarm: #{swarm}", Color::GREEN)
119
+ { inside: base, outside: Dir.pwd }.each do |key, value|
120
+ items[key] = File.join(value, relative)
110
121
  end
122
+
123
+ return items
124
+ end
125
+
126
+ # @param [Array] arguments
127
+ # @param [Hash] environment
128
+ # @param [Hash] bind
129
+ # @param [Boolean] throw
130
+ # @param [Numeric] wait
131
+ # @param [Boolean] strip
132
+ # @param [Boolean] echo
133
+ # @return [String]
134
+ def self.capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false)
135
+ raise "No implement #{__method__} method"
111
136
  end
137
+
138
+ # @param [Array] arguments
139
+ # @param [Hash] environment
140
+ # @param [Hash] bind
141
+ # @param [Boolean] throw
142
+ # @param [Numeric] wait
143
+ # @param [Boolean] echo
144
+ # @return [Boolean]
145
+ def self.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true)
146
+ raise "No implement #{__method__} method"
147
+ end
148
+
149
+ #noinspection RubyClassVariableUsageInspection
150
+ def self.orchestrator
151
+ @@orchestrator ||= self.detect_orchestrator
152
+ return "#{@@orchestrator}"
153
+ end
154
+
112
155
  end
113
156
 
114
157
  module Paser
@@ -271,6 +314,11 @@ module DockerCore
271
314
  return hash.fetch(machine.to_sym, machine)
272
315
  end
273
316
 
317
+ # @param [String] unit
318
+ def self.is_active_unit(unit)
319
+ return 'active' == Process.capture("systemctl is-active #{unit}").downcase
320
+ end
321
+
274
322
  # @param [Array<String>] arguments
275
323
  # @return [Array<String>]
276
324
  def self.find_paths(*arguments)
@@ -494,6 +542,7 @@ module DockerCore
494
542
  uri = URI("https://api.github.com/repos/#{repository}/releases/latest")
495
543
  data = JSON.parse(Net::HTTP.get(uri))['tag_name']
496
544
  return "#{data}"
545
+
497
546
  end
498
547
  end
499
548
 
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.28
4
+ version: 0.0.32
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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fileutils