sct 0.1.21 → 0.1.26

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd0c29ef1fa29ea92d1ecd0e5190b72a10a6b8253c93e3cdea79c6cf02093bc8
4
- data.tar.gz: 987dcdf7f07e610c7c1f5dadf0096dbd006bd4a8da601cdeb59919c5b8fb95ac
3
+ metadata.gz: bccdad524c4eddc87b2e6a51f77bdedbcf455753db1b12e6a111cca020c72ea4
4
+ data.tar.gz: 85f7cc6150fb7257b847be14c9778ccfd4e47a1e473671a859acad3a10323684
5
5
  SHA512:
6
- metadata.gz: 7cef3c668d1ff1bf1e92a0d1363582f6310af7f639c15983168cd5ee03e5885d05a4c409c518d90b53b74fedf3f1ac71945e201772dd131fc97ee3e652b062fe
7
- data.tar.gz: 98ed6109ff77991041a559db372a2a74e45b6693725025e258c020f506df77c355505af0510050fb2269566b994e42e6a247a03ac08f4538e70833904fd6014d
6
+ metadata.gz: 06e991dfc21f3bb3de82b55269c0c34bd2ba3997eae02a7e8d153f15a69116c6d2426439b1cd12105a60a36aad65236a3aa940cec75d00d37f6919a3f614440c
7
+ data.tar.gz: 5aea270e858e20f34ce1aaa97d21ea050e81d682c186affaf5a1985162ae095c1d15f19deac4d8566a0ec331b8bc005ff5c32bf8bf4b248f3a91c3c6f74038bd
@@ -1,7 +1,7 @@
1
1
  module Cluster
2
2
  class Runner
3
-
4
- def launch
3
+
4
+ def launch
5
5
  return UI.error("SCT has not been initialized. Run 'sct init' first.") unless SctCore::Config.exists
6
6
  start_cluster
7
7
  run_command "kubectl delete pod -n kube-system #{pods("kube-system").map { |pod| pod[:name] if pod[:name].start_with? "registry-creds" } .compact.join(" ")}"
@@ -11,11 +11,11 @@ module Cluster
11
11
 
12
12
  def start_cluster
13
13
  if SctCore::Helper.operatingSystem == SctCore::Helper::MAC_OS
14
- run_command "#{minikube} start --cpus=$(sysctl -n hw.ncpu) --memory=8G"
14
+ run_command "#{SctCore::Helper.minikube} start --cpus=$(sysctl -n hw.ncpu) --memory=8G"
15
15
  else
16
- run_command "#{minikube} start --cpus=$(cat /proc/cpuinfo | grep processor | wc -l) --memory=10G"
16
+ run_command "#{SctCore::Helper.minikube} start --cpus=$(cat /proc/cpuinfo | grep processor | wc -l) --memory=10G"
17
17
  end
18
- run_command "#{minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'"
18
+ run_command "#{SctCore::Helper.minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'"
19
19
  update_config
20
20
  end
21
21
 
@@ -26,17 +26,14 @@ module Cluster
26
26
  end
27
27
 
28
28
  def down
29
- run_command "#{minikube} stop"
29
+ run_command "#{SctCore::Helper.minikube} stop"
30
30
  end
31
31
 
32
32
  def reset
33
- run_command "#{minikube} delete"
33
+ run_command "#{SctCore::Helper.minikube} delete"
34
34
  start_cluster
35
35
  create_secrets
36
- run_command "#{minikube} addons enable registry-creds"
37
- run_command "#{minikube} addons enable ingress"
38
- run_command "kubectl rollout status -n kube-system deployment/registry-creds"
39
- run_command "kubectl rollout status -n kube-system deployment/nginx-ingress-controller"
36
+ enable_addons
40
37
  wait_for_gcr_secret
41
38
  run_command "kubectl apply -f ~/development/spend-cloud/k8s/ingress.yml"
42
39
  wait_for_ingress_ip
@@ -46,6 +43,19 @@ module Cluster
46
43
  post_start
47
44
  end
48
45
 
46
+ def enable_addons
47
+ enable_addon "registry-creds"
48
+ enable_addon "ingress"
49
+ end
50
+
51
+ def enable_addon(addon)
52
+ run_command "#{SctCore::Helper.minikube} addons enable #{addon}"
53
+
54
+ deployment = deployments("kube-system").find { |deployment| deployment[:name].include? addon }
55
+
56
+ run_command "kubectl rollout status -n kube-system deployment/#{deployment[:name]}"
57
+ end
58
+
49
59
  def wait_for_pods
50
60
  UI.important("Waiting for pods to become ready...")
51
61
 
@@ -71,7 +81,7 @@ module Cluster
71
81
  end
72
82
  end
73
83
 
74
- def delete_all_pods
84
+ def delete_all_pods
75
85
  run_command "kubectl delete pods --all"
76
86
  end
77
87
 
@@ -105,12 +115,8 @@ module Cluster
105
115
  run_command "kubectl rollout status -n kube-system deployment/coredns"
106
116
  end
107
117
 
108
- def pods(namespace = nil)
109
- if namespace
110
- output = `kubectl get pods -n #{namespace}`
111
- else
112
- output = `kubectl get pods`
113
- end
118
+ def deployments(namespace = "default")
119
+ output = `kubectl get deployments -n #{namespace}`
114
120
 
115
121
  # split output lines
116
122
  lines = output.split "\n"
@@ -118,9 +124,26 @@ module Cluster
118
124
  # exclude first line (table header)
119
125
  lines = lines[1..-1]
120
126
 
121
- if lines.to_a.empty?
122
- return
127
+ # get name and status of each pod
128
+ lines.map do |line|
129
+ columns = line.split(" ")
130
+
131
+ name = columns[0]
132
+
133
+ {
134
+ name: name
135
+ }
123
136
  end
137
+ end
138
+
139
+ def pods(namespace = "default")
140
+ output = `kubectl get pods -n #{namespace}`
141
+
142
+ # split output lines
143
+ lines = output.split "\n"
144
+
145
+ # exclude first line (table header)
146
+ lines = lines[1..-1]
124
147
 
125
148
  # get name and status of each pod
126
149
  lines.map do |line|
@@ -205,7 +228,7 @@ module Cluster
205
228
  end
206
229
 
207
230
  def get_minikube_status
208
- output = `#{minikube} status`
231
+ output = `#{SctCore::Helper.minikube} status`
209
232
 
210
233
  lines = output.split "\n"
211
234
 
@@ -216,12 +239,12 @@ module Cluster
216
239
  end
217
240
  end
218
241
 
219
- def print_pods_status(namespace = nil)
242
+ def print_pods_status(namespace = "default")
220
243
 
221
244
  pods_list = pods(namespace)
222
245
 
223
246
  if pods_list.to_a.empty?
224
- return
247
+ return
225
248
  end
226
249
 
227
250
  rows = pods_list.map do |pod|
@@ -231,7 +254,7 @@ module Cluster
231
254
  ]
232
255
  end
233
256
 
234
- puts Terminal::Table.new title: "Pods (namespace: #{namespace || "default"})".green, headings: ['Name', 'Status'], rows: rows
257
+ puts Terminal::Table.new title: "Pods (namespace: #{namespace})".green, headings: ['Name', 'Status'], rows: rows
235
258
  end
236
259
 
237
260
  def run_command command
@@ -239,13 +262,5 @@ module Cluster
239
262
  raise command.red
240
263
  end
241
264
  end
242
-
243
- def minikube
244
- if SctCore::Helper.operatingSystem == SctCore::Helper::WINDOWS
245
- return "minikube.exe"
246
- else
247
- return "minikube"
248
- end
249
- end
250
265
  end
251
- end
266
+ end
@@ -30,6 +30,10 @@ module Sct
30
30
  {
31
31
  host: "docs.spend.cloud.local",
32
32
  comment: "The spend cloud documentation url"
33
+ },
34
+ {
35
+ host: "henk.spend.cloud.local",
36
+ comment: "The spend cloud Henk web-interface"
33
37
  }
34
38
  ]
35
39
 
@@ -1,3 +1,3 @@
1
1
  module Sct
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.26"
3
3
  end
@@ -35,10 +35,10 @@ module SctCore
35
35
  def self.operatingSystem
36
36
  proc = `uname -a`
37
37
 
38
- case proc
39
- when /Microsoft/
38
+ case proc.downcase
39
+ when /microsoft/
40
40
  os = WINDOWS
41
- when /Darwin/
41
+ when /darwin/
42
42
  os = MAC_OS
43
43
  else
44
44
  os = UBUNTU
@@ -86,5 +86,13 @@ module SctCore
86
86
  def self.isSudo
87
87
  return !ENV["SUDO_USER"].nil? && !ENV["SUDO_USER"].empty?
88
88
  end
89
+
90
+ def self.minikube
91
+ if self.operatingSystem == WINDOWS
92
+ return "minikube.exe"
93
+ else
94
+ return "minikube"
95
+ end
96
+ end
89
97
  end
90
98
  end
@@ -6,11 +6,11 @@ module Shell
6
6
 
7
7
  # Configure the Yarn command
8
8
  def self.config
9
- self.setImage("eu.gcr.io/dev-pasc-vcdm/helpers-composer:latest", true)
10
- self.setPwdAsVolume("/app")
11
- self.addVolume(SctCore::Helper.convertWSLToWindowsPath("#{SctCore::Helper.windowsHomePath || SctCore::Helper.homePath}/.composer") , "/tmp")
12
- self.setCurrentUserAndGroup()
13
- self.setEntrypoint("composer")
9
+ self.set_image("eu.gcr.io/dev-pasc-vcdm/helpers-composer:latest", true)
10
+ self.set_pwd_as_volume("/app")
11
+ self.add_volume(SctCore::Helper.convertWSLToWindowsPath("#{SctCore::Helper.windowsHomePath || SctCore::Helper.homePath}/.composer") , "/tmp")
12
+ self.set_current_user_and_group()
13
+ self.set_entrypoint("composer")
14
14
  end
15
15
  end
16
16
  end
@@ -4,7 +4,7 @@ require "shell/ClassLevelInheritableAttributes"
4
4
  module Shell
5
5
  class Docker
6
6
  include ClassLevelInheritableAttributes
7
- inheritable_attributes :image, :is_private_registry, :entrypoint, :volumes, :ports, :extra_arguments
7
+ inheritable_attributes :image, :is_private_registry, :entrypoint, :volumes, :ports, :extra_arguments, :env_variables
8
8
 
9
9
  @image = nil
10
10
  @is_private_registry = false
@@ -14,6 +14,7 @@ module Shell
14
14
  @ports = {}
15
15
  @user_group = []
16
16
  @extra_arguments = {}
17
+ @env_variables = {}
17
18
 
18
19
  ###
19
20
  # The Docker command configuration. This has to be able to execute the command properly
@@ -27,28 +28,28 @@ module Shell
27
28
  ###
28
29
  def self.exec(cli_arguments)
29
30
 
30
- self.addExtraArgument(cli_arguments)
31
+ self.add_extra_argument(cli_arguments)
31
32
 
32
- self.config()
33
+ self.config
33
34
 
34
35
  # Check if the basic variables are set
35
36
  if !@image || @image.empty?
36
37
  raise LoadError, "The required image is not defined for this command"
37
38
  end
38
39
 
39
- if !self.checkForImage() && @is_private_registry
40
- if !self.loginToPrivateRegistry()
40
+ if !self.check_for_image && @is_private_registry
41
+ unless self.login_to_private_registry
41
42
  raise RuntimeError, "Could not authenticate to GCR (" + $?.exitstatus + ")"
42
43
  end
43
44
  end
44
45
 
45
- self.runCommand()
46
+ self.run_command
46
47
  end
47
48
 
48
49
  ###
49
50
  # The image for this Docker command
50
51
  ###
51
- def self.setImage(image, is_private_registry=false)
52
+ def self.set_image(image, is_private_registry=false)
52
53
  @image = image
53
54
  @is_private_registry = is_private_registry
54
55
  end
@@ -56,27 +57,27 @@ module Shell
56
57
  ###
57
58
  # Set the current PWD as a volume on the specified path in the container
58
59
  ###
59
- def self.setPwdAsVolume(volume_path)
60
+ def self.set_pwd_as_volume(volume_path)
60
61
  pwd = `pwd -P`
61
62
 
62
63
  if SctCore::Helper.operatingSystem == SctCore::Helper::WINDOWS
63
64
  pwd=SctCore::Helper.convertWSLToWindowsPath(pwd)
64
65
  end
65
66
 
66
- addVolume(pwd, volume_path)
67
+ add_volume(pwd, volume_path)
67
68
  end
68
69
 
69
70
  ###
70
71
  # Add an extra volume in the container
71
72
  ###
72
- def self.addVolume(localPath, volume_path)
73
- @volumes[localPath] = volume_path
73
+ def self.add_volume(local_path, volume_path)
74
+ @volumes[local_path] = volume_path
74
75
  end
75
76
 
76
77
  ###
77
78
  # Add a port mapping for the container
78
79
  ###
79
- def self.mapPort(external_port, container_port = nil)
80
+ def self.map_port(external_port, container_port = nil)
80
81
 
81
82
  external_port=String(external_port)
82
83
  container_port=String(container_port)
@@ -91,7 +92,7 @@ module Shell
91
92
  ###
92
93
  # Set the current user and group in the container
93
94
  ###
94
- def self.setCurrentUserAndGroup
95
+ def self.set_current_user_and_group
95
96
  @user_group = []
96
97
  @user_group << `id -u`
97
98
  @user_group << `id -g`
@@ -100,14 +101,14 @@ module Shell
100
101
  ###
101
102
  # Set the entrypoint for the command in the container
102
103
  ###
103
- def self.setEntrypoint(entrypoint)
104
+ def self.set_entrypoint(entrypoint)
104
105
  @entrypoint=entrypoint
105
106
  end
106
107
 
107
108
  ###
108
109
  # Add extra arguments to be configured for the container
109
110
  ###
110
- def self.addExtraArgument(argument, value=nil)
111
+ def self.add_extra_argument(argument, value=nil)
111
112
  argument = String(argument)
112
113
 
113
114
  if value
@@ -117,10 +118,17 @@ module Shell
117
118
  self.extra_arguments[argument] = value
118
119
  end
119
120
 
121
+ ###
122
+ # Set environment variables for the container
123
+ ###
124
+ def self.set_environment_variables(env_variables)
125
+ @env_variables = env_variables
126
+ end
127
+
120
128
  ###
121
129
  # Check if the image is already present in the system
122
130
  ###
123
- def self.checkForImage
131
+ def self.check_for_image
124
132
  image_list=`docker images -q #{@image} 2> /dev/null`
125
133
 
126
134
  return image_list && !image_list.empty?
@@ -129,7 +137,7 @@ module Shell
129
137
  ###
130
138
  # Login to the private container registry with the cloud credentials
131
139
  ###
132
- def self.loginToPrivateRegistry
140
+ def self.login_to_private_registry
133
141
  `docker login -u oauth2accesstoken -p "$(gcloud auth application-default print-access-token)" https://eu.gcr.io &> /dev/null`
134
142
  return $?.success?
135
143
  end
@@ -137,8 +145,8 @@ module Shell
137
145
  ###
138
146
  # Run the command
139
147
  ###
140
- def self.runCommand()
141
- command = self.compileCommand()
148
+ def self.run_command
149
+ command = self.compile_command
142
150
 
143
151
  SctCore::CommandExecutor.execute(command: command, print_all: true, suppress_output: false)
144
152
  end
@@ -146,42 +154,53 @@ module Shell
146
154
  ###
147
155
  # Compile the command with all options
148
156
  ###
149
- def self.compileCommand()
157
+ def self.compile_command
150
158
  # Basic docker run command
151
- command = self.addToCommandString("" , "docker run --rm -it")
159
+ command = self.add_to_command_string("" , "docker run --rm -it")
160
+
161
+ # Attach environment variables
162
+ if @env_variables
163
+ @env_variables.each do |key, value|
164
+ if value && !value.empty?
165
+ command = self.add_to_command_string(command, "-e " + key+"="+value)
166
+ else
167
+ command = self.add_to_command_string("-e " + key, value)
168
+ end
169
+ end
170
+ end
152
171
 
153
172
  # Attach configured volumes
154
173
  if @volumes
155
174
  @volumes.each do |local_path, container_path|
156
- command = self.addToCommandString(command, "--volume " + local_path +":"+ container_path)
175
+ command = self.add_to_command_string(command, "--volume " + local_path +":"+ container_path)
157
176
  end
158
177
  end
159
178
 
160
179
  # Map configured ports
161
180
  if @ports
162
181
  @ports.each do |external_port, container_port|
163
- command = self.addToCommandString(command, "-p " + external_port +":"+ container_port)
182
+ command = self.add_to_command_string(command, "-p " + external_port +":"+ container_port)
164
183
  end
165
184
  end
166
185
 
167
186
  if @user_group
168
- command = self.addToCommandString(command, "--user "+ String(@user_group.shift()) +":"+ String(@user_group.shift()))
187
+ command = self.add_to_command_string(command, "--user "+ String(@user_group.shift) +":"+ String(@user_group.shift))
169
188
  end
170
189
 
171
190
  # Add image to command
172
- command = self.addToCommandString(command, @image)
191
+ command = self.add_to_command_string(command, @image)
173
192
 
174
193
  if @entrypoint
175
- command = self.addToCommandString(command, String(@entrypoint))
194
+ command = self.add_to_command_string(command, String(@entrypoint))
176
195
  end
177
196
 
178
197
  # Append arguments and options to command
179
198
  if @extra_arguments
180
199
  @extra_arguments.each do |argument, value|
181
200
  if value && !value.empty?
182
- command = self.addToCommandString(command, argument+"="+value)
201
+ command = self.add_to_command_string(command, argument+"="+value)
183
202
  else
184
- command = self.addToCommandString(command, argument)
203
+ command = self.add_to_command_string(command, argument)
185
204
  end
186
205
  end
187
206
  end
@@ -192,7 +211,7 @@ module Shell
192
211
  ###
193
212
  # Append a part to the command string and remove any unwanted characters
194
213
  ###
195
- def self.addToCommandString(command_string, append)
214
+ def self.add_to_command_string(command_string, append)
196
215
  return command_string + append.gsub(/\r?\n/, "") + " "
197
216
  end
198
217
  end
@@ -1,15 +1,60 @@
1
1
  require "sct_core"
2
+
2
3
  require_relative "docker"
3
4
 
4
5
  module Shell
5
- class Php < Docker
6
-
7
- # Configure the Yarn command
8
- def self.config
9
- self.setImage("eu.gcr.io/dev-pasc-vcdm/proactive-base:latest", true)
10
- self.setPwdAsVolume("/var/www")
11
- self.setCurrentUserAndGroup()
12
- self.setEntrypoint("php")
6
+ class Php < Docker
7
+
8
+ attr_accessor :make
9
+
10
+ # Configure the Yarn command
11
+ def self.config
12
+ self.set_image("eu.gcr.io/dev-pasc-vcdm/proactive-base:latest", true)
13
+ self.set_pwd_as_volume("/var/www")
14
+ self.set_current_user_and_group
15
+ self.set_entrypoint("php")
16
+ self.set_environment_variables(self.get_environment_variables)
17
+ end
18
+
19
+ def self.get_environment_variables
20
+ environment_variables = {}
21
+ environment_variables.store("ENVIRONMENT", "local")
22
+
23
+ environment_variables = self.add_service_ip_and_port(environment_variables)
24
+
25
+ return environment_variables
26
+ end
27
+
28
+ def self.add_service_ip_and_port(environment_variables)
29
+ service_names = %w[mysql-service redis-service]
30
+
31
+ minikube_status
32
+
33
+ service_names.each { |service_name|
34
+ url = `#{SctCore::Helper.minikube} service #{service_name} --url`
35
+
36
+ ip_and_port = url.match /(?<ip>[0-9]+(?:\.[0-9]+){3}):(?<port>[0-9]+)/
37
+
38
+ case service_name
39
+ when "mysql-service"
40
+ environment_variables.store("DB_HOST", ip_and_port[:ip])
41
+ environment_variables.store("DB_PORT", ip_and_port[:port])
42
+ when "redis-service"
43
+ environment_variables.store("REDIS_HOST", ip_and_port[:ip])
44
+ environment_variables.store("REDIS_PORT", ip_and_port[:port])
13
45
  end
46
+ }
47
+
48
+ return environment_variables
49
+ end
50
+
51
+ def self.minikube_status
52
+ output = `#{SctCore::Helper.minikube} status`
53
+
54
+ if output.scan(/Running/).length != 3 && output.scan(/Configured/).length != 1
55
+ UI.important("Please check your minikube status. If all services are stopped you should start the minikube first.")
56
+ exit
57
+ end
14
58
  end
59
+ end
15
60
  end
@@ -6,12 +6,12 @@ module Shell
6
6
 
7
7
  # Configure the Yarn command
8
8
  def self.config
9
- self.setImage("eu.gcr.io/dev-pasc-vcdm/helpers-yarn:latest", true)
10
- self.setPwdAsVolume("/app")
11
- self.addVolume(SctCore::Helper.convertWSLToWindowsPath("#{SctCore::Helper.windowsHomePath || SctCore::Helper.homePath}/.cache") , "/.cache")
12
- self.mapPort(8081, 8080)
13
- self.mapPort(9001)
14
- self.setCurrentUserAndGroup()
9
+ self.set_image("eu.gcr.io/dev-pasc-vcdm/helpers-yarn:latest", true)
10
+ self.set_pwd_as_volume("/app")
11
+ self.add_volume(SctCore::Helper.convertWSLToWindowsPath("#{SctCore::Helper.windowsHomePath || SctCore::Helper.homePath}/.cache") , "/.cache")
12
+ self.map_port(8081, 8080)
13
+ self.map_port(9001)
14
+ self.set_current_user_and_group()
15
15
  end
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reshad Farid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-01 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -249,9 +249,9 @@ post_install_message:
249
249
  rdoc_options: []
250
250
  require_paths:
251
251
  - cluster/lib
252
- - shell/lib
253
252
  - sct/lib
254
253
  - sct_core/lib
254
+ - shell/lib
255
255
  required_ruby_version: !ruby/object:Gem::Requirement
256
256
  requirements:
257
257
  - - ">="
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  - !ruby/object:Gem::Version
264
264
  version: '0'
265
265
  requirements: []
266
- rubygems_version: 3.0.8
266
+ rubygems_version: 3.0.6
267
267
  signing_key:
268
268
  specification_version: 4
269
269
  summary: Spend Cloud Tool.