sct 0.1.22 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61cca19491733244389c6a46e8c8fd8fd226b3cdab4fb8537b17a4e6d51d196e
4
- data.tar.gz: 3057200714457d8b312f34f542454019155e634137d8a0de5ffe4fee93538d90
3
+ metadata.gz: 795f84864a77f3e67efdbba2318ba62ca9958f665512f8d0b0f52eaffef5d191
4
+ data.tar.gz: 91ca3561de5f9418aaad5d99faf4f2d38cedf5e0063723ddad774345c96bff1d
5
5
  SHA512:
6
- metadata.gz: 721bcf403b7292dad0bec08f9d0198ad64acc9ab5ffa0200299499d51b7fb3b15fb859f5812c03347484fe5175263d73af86072f65138bb3cdda39e3ba532621
7
- data.tar.gz: 19386f51a743615e480a579ce3fbb7eb17859a0f8bd2e57c21b9ce57562ac6c6436bcee1d6b845004317d160e2b2d288703a07c5829dfd02374b286cbe8a9a4c
6
+ metadata.gz: feffcc74dba1ebdcce727e9718f70d88d22bacc6643d17a69f2dc05716bd7c440e95988a2387421185f6e0d0ea0294ad83cad166759a570fa70cd649120943fc
7
+ data.tar.gz: e40cbed1e28216b1e68190eef67e383966015bae5c6ad24ddcac745826279a01175ce42021aa175fe93e755aa154f2e6f51effc0c5a2e3a2c88f7623de2aa118
@@ -9,7 +9,7 @@ module Cluster
9
9
  self.new.run
10
10
  end
11
11
 
12
- def run
12
+ def run
13
13
  program :name, 'cluster'
14
14
  program :version, Sct::VERSION
15
15
  program :description, 'CLI for \'cluster\' - Manage your local kubernetes cluster'
@@ -22,8 +22,8 @@ module Cluster
22
22
  c.description = "Start the cluster"
23
23
  c.option '--clean', 'start a clean cluster. Old cluster will be purged if available.'
24
24
 
25
- c.action do |args, options|
26
- if options.clean
25
+ c.action do |args, options|
26
+ if options.clean
27
27
  Cluster::Runner.new.reset
28
28
  else
29
29
  Cluster::Runner.new.launch
@@ -37,17 +37,17 @@ module Cluster
37
37
  c.syntax = 'sct cluster down'
38
38
  c.description = 'stop the cluster'
39
39
 
40
- c.action do |args, options|
40
+ c.action do |args, options|
41
41
  Cluster::Runner.new.down
42
42
  end
43
43
  end
44
44
 
45
- command :reset do |c|
45
+ command :reset do |c|
46
46
 
47
47
  c.syntax = 'sct cluster reset'
48
48
  c.description = 'reset your cluster and start with a clean cluster'
49
49
 
50
- c.action do |args, options|
50
+ c.action do |args, options|
51
51
  Cluster::Runner.new.reset
52
52
  end
53
53
  end
@@ -59,13 +59,13 @@ module Cluster
59
59
  c.syntax = 'sct cluster status'
60
60
  c.description = 'see the status of your cluster'
61
61
 
62
- c.action do |args, options|
62
+ c.action do |args, options|
63
63
  Cluster::Runner.new.status
64
64
  end
65
65
  end
66
66
 
67
67
  command :'update config' do |c|
68
-
68
+
69
69
  c.syntax = 'sct cluster update config'
70
70
  c.description = 'update the cluster configuration'
71
71
 
@@ -84,7 +84,7 @@ module Cluster
84
84
 
85
85
  Cluster::Runner.new.delete_stalled_pods if options.stalled
86
86
  Cluster::Runner.new.delete_all_pods if options.all
87
-
87
+
88
88
  Cluster::Runner.new.delete_pods(args) if !args.empty?
89
89
 
90
90
  end
@@ -106,4 +106,4 @@ module Cluster
106
106
  run!
107
107
  end
108
108
  end
109
- end
109
+ end
@@ -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,11 +26,11 @@ 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
36
  enable_addons
@@ -49,7 +49,7 @@ module Cluster
49
49
  end
50
50
 
51
51
  def enable_addon(addon)
52
- run_command "#{minikube} addons enable #{addon}"
52
+ run_command "#{SctCore::Helper.minikube} addons enable #{addon}"
53
53
 
54
54
  deployment = deployments("kube-system").find { |deployment| deployment[:name].include? addon }
55
55
 
@@ -228,7 +228,7 @@ module Cluster
228
228
  end
229
229
 
230
230
  def get_minikube_status
231
- output = `#{minikube} status`
231
+ output = `#{SctCore::Helper.minikube} status`
232
232
 
233
233
  lines = output.split "\n"
234
234
 
@@ -262,13 +262,5 @@ module Cluster
262
262
  raise command.red
263
263
  end
264
264
  end
265
-
266
- def minikube
267
- if SctCore::Helper.operatingSystem == SctCore::Helper::WINDOWS
268
- return "minikube.exe"
269
- else
270
- return "minikube"
271
- end
272
- end
273
265
  end
274
266
  end
@@ -1,3 +1,3 @@
1
1
  module Sct
2
- VERSION = "0.1.22"
2
+ VERSION = "0.1.23"
3
3
  end
@@ -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,52 @@
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(get_service_ip_and_port)
17
+ end
18
+
19
+ def self.get_service_ip_and_port
20
+ service_names = %w[mysql-service redis-service]
21
+ environment_variables = {}
22
+
23
+ minikube_status
24
+
25
+ service_names.each { |service_name|
26
+ url = `#{SctCore::Helper.minikube} service #{service_name} --url`
27
+
28
+ ip_and_port = url.match /(?<ip>[0-9]+(?:\.[0-9]+){3}):(?<port>[0-9]+)/
29
+
30
+ case service_name
31
+ when "mysql-service"
32
+ environment_variables.store("DB_HOST", ip_and_port[:ip])
33
+ environment_variables.store("DB_PORT", ip_and_port[:port])
34
+ when "redis-service"
35
+ environment_variables.store("REDIS_HOST", ip_and_port[:ip])
36
+ environment_variables.store("REDIS_PORT", ip_and_port[:port])
13
37
  end
38
+ }
39
+
40
+ return environment_variables
41
+ end
42
+
43
+ def self.minikube_status
44
+ output = `#{SctCore::Helper.minikube} status`
45
+
46
+ if output.scan(/Running/).length != 3 && output.scan(/Configured/).length != 1
47
+ UI.important("Please check your minikube status. If all services are stopped you should start the minikube first.")
48
+ exit
49
+ end
14
50
  end
51
+ end
15
52
  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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reshad Farid
@@ -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.