docker_core 0.0.27 → 0.0.31

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docker_core.rb +99 -43
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da0b663870f8facf55cf16967c2e2fae3049bbedb497c89759251903f7fa4875
4
- data.tar.gz: 9c6539f512f9430de020c30ffc53677a7ecb03aa4cb6d90578ce622d0d1f2ecd
3
+ metadata.gz: 3844eb4ee913899cab8113bb7ce6ef006eca4a3c20520ccbd1e9c9b74f5245e4
4
+ data.tar.gz: 1ee372fce84dcc125d3ded1f14d65c583ef919949d4d722e2be1672f40fea992
5
5
  SHA512:
6
- metadata.gz: f71c262f8071fa6f2e45c897909f67b15776320c7fe9925c8d4abc3a4242190b3ba6bce25856b1f498aa35caca15c453689b73c8239891ac381f267593a21eac
7
- data.tar.gz: a0ff5f5cfa2c8152d71b17053c9f1a44904b62889252d2f917cab3170aac36886a09d211dc165c2657df80f39f0427bb8c6ab941d3ec1db24e816e0344b47c0c
6
+ metadata.gz: c6b3c402892459520958a46ed72d79fa2f7b9ec16daa447b34cae359a3a0b0f461a077f2a77ea39cf69c4148e399d0e4fb0cecbcd3ac5ce15291a3eb02681566
7
+ data.tar.gz: a2a5d399de5ee88cc83795a175ec3ec0f829aa3756adda5b575f68325893125b206526e588a4242303d7996616931c6f67a29d48caf6005b1713d3d7edcbdbcd
data/lib/docker_core.rb CHANGED
@@ -11,6 +11,8 @@ module DockerCore
11
11
  SUDO = false
12
12
  USER = 'core'
13
13
  GROUP = 'core'
14
+ REGISTRY = 'docker.io'
15
+ NAMESPACE = 'library'
14
16
 
15
17
  class Color < Thor::Shell::Color
16
18
  # @param [String] text
@@ -39,66 +41,112 @@ module DockerCore
39
41
  end
40
42
 
41
43
  module Command
42
- module Swarm
43
- def self.swarm_path
44
- return File.expand_path('~/.swarm')
45
- end
44
+ end
46
45
 
47
- # @param [String] service
48
- def self.service_actived(service)
49
- return 'active' == Process.capture("systemctl is-active #{service}").downcase
50
- end
46
+ module Swarm
47
+ # @param [String] image
48
+ # @param [String] registry
49
+ # @param [String] namespace
50
+ # @param [String] tag
51
+ def self.use_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest')
52
+ return [registry, namespace, image].join('/') + ":#{tag}"
53
+ end
51
54
 
52
- # @param [String] swarm
53
- def self.write_swarm(swarm = '')
54
- return File.write(self.swarm_path, "#{swarm}\n")
55
- end
55
+ def self.deploy_path
56
+ return File.expand_path('~/deploy')
57
+ end
56
58
 
57
- def self.read_swarm
58
- file = self.swarm_path
59
- return File.exists?(file) ? File.read(file).strip : ''
60
- end
59
+ def self.swarm_path
60
+ return File.expand_path('~/.swarm')
61
+ end
61
62
 
62
- def self.detect_services
63
- return { docker: self.service_actived('docker') }
64
- end
63
+ # @param [String] swarm
64
+ def self.write_swarm(swarm = '')
65
+ return File.write(self.swarm_path, "#{swarm}\n")
66
+ end
65
67
 
66
- def self.detect_swarm
67
- swarm = self.read_swarm.to_sym
68
- detect = self.detect_services
68
+ def self.read_swarm
69
+ file = self.swarm_path
70
+ return File.exists?(file) ? File.read(file).strip : ''
71
+ end
69
72
 
70
- if detect.has_key?(swarm) && detect[swarm]
71
- return "#{swarm}"
72
- end
73
+ def self.detect_services
74
+ return { docker: Shell.is_active_unit('docker') }
75
+ end
76
+
77
+ def self.detect_swarm
78
+ swarm = self.read_swarm.to_sym
79
+ detect = self.detect_services
73
80
 
74
- index = detect.key(true)
75
- return "#{index}"
81
+ if detect.has_key?(swarm) && detect[swarm]
82
+ return "#{swarm}"
76
83
  end
77
84
 
78
- def self.swarm_status
79
- color = Color::GREEN
80
- detect = self.detect_swarm
85
+ index = detect.key(true)
86
+ return "#{index}"
87
+ end
81
88
 
82
- Color.echo("Swarm: #{detect}", color)
83
- Color.echo(self.detect_services.to_yaml, color)
84
- end
89
+ def self.swarm_status
90
+ color = Color::GREEN
91
+ detect = self.detect_swarm
85
92
 
86
- # @param [String] swarm
87
- def self.update_swarm(swarm = '')
88
- if false == swarm.empty?
89
- self.write_swarm(swarm)
90
- end
93
+ Color.echo("Swarm: #{detect}", color)
94
+ Color.echo(self.detect_services.to_yaml, color)
95
+ end
91
96
 
92
- swarm = self.detect_swarm
97
+ # @param [String] swarm
98
+ def self.update_swarm(swarm = '')
99
+ if false == swarm.empty?
93
100
  self.write_swarm(swarm)
101
+ end
94
102
 
95
- if swarm.empty?
96
- swarm = 'none'
97
- end
103
+ swarm = self.detect_swarm
104
+ self.write_swarm(swarm)
105
+
106
+ if swarm.empty?
107
+ swarm = 'none'
108
+ end
109
+
110
+ Color.echo("Swarm: #{swarm}", Color::GREEN)
111
+ end
98
112
 
99
- Color.echo("Swarm: #{swarm}", Color::GREEN)
113
+ # @param [String] base
114
+ # @param [String] relative
115
+ def self.pair_paths(base, relative = '')
116
+ items = {}
117
+
118
+ { inside: base, outside: Dir.pwd }.each do |key, value|
119
+ items[key] = File.join(value, relative)
100
120
  end
121
+
122
+ return items
123
+ end
124
+
125
+ # @param [Array] arguments
126
+ # @param [Boolean] throw
127
+ # @param [Numeric] wait
128
+ # @param [Boolean] strip
129
+ # @param [Boolean] echo
130
+ # @return [String]
131
+ def self.capture_command(*arguments, environment: {}, throw: false, wait: 0, strip: true, echo: false)
132
+ raise "No implement #{__method__} method"
133
+ end
134
+
135
+ # @param [Array] arguments
136
+ # @param [Boolean] throw
137
+ # @param [Numeric] wait
138
+ # @param [Boolean] echo
139
+ # @return [Boolean]
140
+ def self.run_command(*arguments, environment: {}, throw: true, wait: 0, echo: true)
141
+ raise "No implement #{__method__} method"
142
+ end
143
+
144
+ #noinspection RubyClassVariableUsageInspection
145
+ def self.swarm
146
+ @@swarm ||= self.detect_swarm
147
+ return "#{@@swarm}"
101
148
  end
149
+
102
150
  end
103
151
 
104
152
  module Paser
@@ -261,6 +309,11 @@ module DockerCore
261
309
  return hash.fetch(machine.to_sym, machine)
262
310
  end
263
311
 
312
+ # @param [String] unit
313
+ def self.is_active_unit(unit)
314
+ return 'active' == Process.capture("systemctl is-active #{unit}").downcase
315
+ end
316
+
264
317
  # @param [Array<String>] arguments
265
318
  # @return [Array<String>]
266
319
  def self.find_paths(*arguments)
@@ -484,6 +537,9 @@ module DockerCore
484
537
  uri = URI("https://api.github.com/repos/#{repository}/releases/latest")
485
538
  data = JSON.parse(Net::HTTP.get(uri))['tag_name']
486
539
  return "#{data}"
540
+
541
+
542
+
487
543
  end
488
544
  end
489
545
 
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.27
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - agrozyme
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-31 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