sct 0.1.11 → 0.1.12

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: 8f69f48e36f97431cf118494409bb2f326d94c4373144cb55a49c1414b367e18
4
- data.tar.gz: 9ccba2ad04721031f78ae8ce5d13c4a40ad0d0d7e3decf7780c5e52a678ce096
3
+ metadata.gz: fa4a9c05109327130b6c1b08f44e0658be4db63e1c8402118ee9b7c7a14463cf
4
+ data.tar.gz: 88e20c8c3e6ff0fac970955b03ae2d95010544cd158c733507cba312b5507499
5
5
  SHA512:
6
- metadata.gz: 64d70d3ec8a1cb25d2996f086503433f059bd3825a67ce370c3b072cb5b59e4e109cfc726e1258a6b68d34569e59f713775f654bb4cf3ee48798fe014d981519
7
- data.tar.gz: c4816aa4ac66903b48d843a277a1a9b17e4fd92698e1d0321f60d077fdaa36e16c164398169c53533a10e0e1448e8dc191a1b6d894d0c08327d8bdd628c2d53a
6
+ metadata.gz: b153495574021b51ee936580da13b4a177a22e0e8c5ad8e74be877e21cbb65be0570bfa24945941599807f1658786ffbe7d8d68002cb7759e8ce07f6cb3628b7
7
+ data.tar.gz: 3b2dba1bd88a72519a8043fae447568b9d8927e6c5e26ce40ba45c35275927ea18949371e88011f195af2dae2986df83d0110c2aa39a43dcadc45e6395bbbbef
data/.DS_Store CHANGED
File without changes
data/.rspec CHANGED
File without changes
File without changes
File without changes
data/Gemfile CHANGED
File without changes
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -16,7 +16,7 @@ module Sct
16
16
  def execute(args, options)
17
17
  return puts "SCT has not been initialized. Run 'sct init' first.".red unless Sct::Config.exists
18
18
 
19
- if Sct::Config::WINDOWS
19
+ if Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
20
20
  minikube = "minikube.exe"
21
21
  else
22
22
  minikube = "minikube"
@@ -26,7 +26,7 @@ module Sct
26
26
  when "up"
27
27
  system("#{minikube} start")
28
28
  system("#{minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'")
29
- system("sct cluster update-config")
29
+ update_config
30
30
  system("kubectl config use-context minikube")
31
31
  system("kubectl delete pod -n kube-system $(kubectl get pods -n kube-system | grep registry-creds | awk '{print $1}')")
32
32
  system("sudo sct hostfile")
@@ -34,21 +34,25 @@ module Sct
34
34
  when "down"
35
35
  system("#{minikube} stop")
36
36
  when "update-config"
37
- return puts "Skipping minikube config ( only needed for windows )".yellow unless Sct::Config.operatingSystem == Sct::Config::WINDOWS
38
-
39
- windows_home_path = Sct::Config.getTrueHomePath
40
- kube_file_path = windows_home_path+"/.kube/config"
37
+ update_config
38
+ else
39
+ puts "Unknown or missing argument. Please run 'sct cluster up','sct cluster down' or 'sct cluster update-config'".red
40
+ end
41
+ end
41
42
 
42
- if !File.exists?(kube_file_path)
43
- return puts "#{kube_file_path} doesn't exist".red
44
- end
43
+ def update_config
44
+ return puts "Skipping minikube config (only needed for Windows)".yellow unless Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
45
45
 
46
- system("sed -e 's~\\\\~/~g' -e 's~C:~/mnt/c~g' < #{kube_file_path} > ~/.kube/minikube-config")
46
+ windows_home_path = Sct::Helpers.windowsHomePath
47
+ kube_file_path = windows_home_path+"/.kube/config"
47
48
 
48
- return puts "Windows minikube config copied to ~/.kube/minikube-config".green
49
- else
50
- puts "Unknown or missing argument. Please run 'sct cluster up','sct cluster down' or 'sct cluster update-config'".red
49
+ if !File.exists?(kube_file_path)
50
+ return puts "#{kube_file_path} doesn't exist".red
51
51
  end
52
+
53
+ system("sed -e 's~\\\\~/~g' -e 's~C:~/mnt/c~g' < #{kube_file_path} > ~/.kube/minikube-config")
54
+
55
+ return puts "Windows minikube config copied to ~/.kube/minikube-config".green
52
56
  end
53
57
 
54
58
  implements CommandInterface
@@ -1,3 +1,4 @@
1
+ require 'hosts'
1
2
  require 'sct/command_interface'
2
3
 
3
4
  module Sct
@@ -16,34 +17,36 @@ module Sct
16
17
  end
17
18
 
18
19
  def execute(args, options)
19
-
20
20
  return puts "SCT has not been initialized. Run 'sct init' first.".red unless Sct::Config.exists
21
21
 
22
- require 'hosts'
22
+ return puts "This command needs to be run with sudo.".red unless Sct::Helpers.isSudo
23
23
 
24
- return unless ingressUrl
24
+ return unless Sct::Helpers.ingressAddress
25
25
 
26
- url = ingressUrl
27
- host_path = Sct::Config.get("host-path")
26
+ ingressAddress = Sct::Helpers.ingressAddress
28
27
 
29
- if !options.path.nil?
30
- hosts = Hosts::File.read(options.path)
31
- elsif host_path
32
- hosts = Hosts::File.read(host_path)
28
+ if options.path
29
+ hosts_paths = [options.path]
33
30
  else
34
- puts "No hostpath found in config file. Using default /etc/hosts".yellow
35
- hosts = Hosts::File.read('/etc/hosts')
36
- end
31
+ hosts_paths = ["/etc/hosts"]
37
32
 
38
- if ([url].any? { |ip| hosts.to_s =~ /#{ip}/ })
39
- puts "Already exist and skipped.".green
40
- else
41
- validate_if_exist(hosts)
42
- add_entry(url, hosts)
43
- hosts.write
44
- puts "patched: #{url}".green
33
+ if Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
34
+ hosts_paths << "/mnt/c/Windows/System32/drivers/etc/hosts"
35
+ end
45
36
  end
46
37
 
38
+ hosts_paths.each do |hosts_path|
39
+ hosts = Hosts::File.read(hosts_path)
40
+
41
+ if ([ingressAddress].any? { |ip| hosts.to_s =~ /#{ip}/ })
42
+ puts "Skipped patching #{hosts_path} (already up to date)".green
43
+ else
44
+ validate_if_exist(hosts)
45
+ add_entry(ingressAddress, hosts)
46
+ hosts.write
47
+ puts "Patched #{hosts_path} with #{ingressAddress}".green
48
+ end
49
+ end
47
50
  end
48
51
 
49
52
  def add_entry(url, hosts)
@@ -100,10 +103,6 @@ module Sct
100
103
 
101
104
  end
102
105
 
103
- def ingressUrl
104
- return Sct::Helpers.ingressUrl
105
- end
106
-
107
106
  implements CommandInterface
108
107
 
109
108
  end
@@ -31,15 +31,9 @@ module Sct
31
31
  q.default = "~/.config/gcloud/application_default_credentials.json"
32
32
  }
33
33
 
34
- host_path = "/etc/hosts"
35
- if Sct::Config.operatingSystem == Sct::Config::WINDOWS
36
- host_path = "/mnt/c/Windows/System32/drivers/etc/hosts"
37
- end
38
-
39
34
  contents = ""
40
35
  contents << "email=#{email}\n"
41
36
  contents << "cloud-proxy-path=#{File.expand_path(cloud_proxy_path)}\n"
42
- contents << "host-path=#{File.expand_path(host_path)}\n"
43
37
 
44
38
  if !File.directory?(Sct::Config.dir)
45
39
  FileUtils.mkdir_p(Sct::Config.dir)
@@ -1,20 +1,8 @@
1
1
  module Sct
2
2
  class Config
3
3
 
4
- WINDOWS = "Windows"
5
- MAC_OS = "MacOS"
6
- UBUNTU = "Ubuntu"
7
-
8
4
  def self.dir
9
- user = ENV["SUDO_USER"] || ENV["USER"]
10
-
11
- if self.operatingSystem == MAC_OS
12
- home = "/Users"
13
- else
14
- home = "/home"
15
- end
16
-
17
- return "#{home}/#{user}/.config/sct"
5
+ return "#{Sct::Helpers.homePath}/.config/sct"
18
6
  end
19
7
 
20
8
  def self.path
@@ -44,48 +32,5 @@ module Sct
44
32
 
45
33
  return Sct::Helpers.to_hash(contents)
46
34
  end
47
-
48
- def self.operatingSystem
49
- proc = `uname -a`
50
-
51
- case proc
52
- when /Microsoft/
53
- os = WINDOWS
54
- when /Darwin/
55
- os = MAC_OS
56
- else
57
- os = UBUNTU
58
- end
59
-
60
- return os
61
- end
62
-
63
- ###
64
- # Get the actual home path of the user. This may be different depending on the operating system
65
- ###
66
- def self.getTrueHomePath
67
- home_path = `echo ~`
68
- if self.operatingSystem == WINDOWS
69
- home_path = self.convertWindowsToWSLPath(`cmd.exe /c echo %userprofile%`)
70
- end
71
-
72
- return home_path
73
- end
74
-
75
- def self.convertWindowsToWSLPath(path)
76
- if self.operatingSystem == WINDOWS
77
- return path.gsub(/C:\\/, '/mnt/c/').gsub(/\\\\/, "/").gsub(/\\/, '/').gsub(/\r\n?/, '')
78
- end
79
-
80
- return path
81
- end
82
-
83
- def self.convertWSLToWindowsPath(path)
84
- if self.operatingSystem == WINDOWS
85
- return path.gsub(/\/mnt\/c/, 'C:/').gsub(/\/\//, '/').gsub(/\\\\/, "/").gsub(/\r\n?/, '')
86
- end
87
-
88
- return path
89
- end
90
35
  end
91
36
  end
@@ -7,7 +7,7 @@ module Sct
7
7
  def self.config
8
8
  self.setImage("eu.gcr.io/dev-pasc-vcdm/helpers-composer:latest", true)
9
9
  self.setPwdAsVolume("/app")
10
- self.addVolume(Sct::Config.convertWSLToWindowsPath(Sct::Config.getTrueHomePath()+"/.composer") , "/tmp")
10
+ self.addVolume(Sct::Helpers.convertWSLToWindowsPath("#{Sct::Helpers.windowsHomePath || Sct::Helpers.homePath}/.composer") , "/tmp")
11
11
  self.setCurrentUserAndGroup()
12
12
  self.setEntrypoint("composer")
13
13
  end
@@ -60,8 +60,8 @@ module Sct
60
60
  def self.setPwdAsVolume(volume_path)
61
61
  pwd = `pwd -P`
62
62
 
63
- if Sct::Config.operatingSystem == Sct::Config::WINDOWS
64
- pwd=Sct::Config.convertWSLToWindowsPath(pwd)
63
+ if Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
64
+ pwd=Sct::Helpers.convertWSLToWindowsPath(pwd)
65
65
  end
66
66
 
67
67
  addVolume(pwd, volume_path)
@@ -131,7 +131,7 @@ module Sct
131
131
  # Login to the private container registry with the cloud credentials
132
132
  ###
133
133
  def self.loginToPrivateRegistry
134
- `docker login -u oauth2accesstoken -p "$(gcloud auth application-default print-access-token)" https://eu.gcr.io &>2`
134
+ `docker login -u oauth2accesstoken -p "$(gcloud auth application-default print-access-token)" https://eu.gcr.io &> /dev/null`
135
135
  return $?.success?
136
136
  end
137
137
 
File without changes
@@ -7,7 +7,7 @@ module Sct
7
7
  def self.config
8
8
  self.setImage("eu.gcr.io/dev-pasc-vcdm/helpers-yarn:latest", true)
9
9
  self.setPwdAsVolume("/app")
10
- self.addVolume(Sct::Config.convertWSLToWindowsPath(Sct::Config.getTrueHomePath()+"/.cache") , "/.cache")
10
+ self.addVolume(Sct::Helpers.convertWSLToWindowsPath("#{Sct::Helpers.windowsHomePath || Sct::Helpers.homePath}/.cache") , "/.cache")
11
11
  self.mapPort(8081, 8080)
12
12
  self.mapPort(9001)
13
13
  self.setCurrentUserAndGroup()
@@ -1,16 +1,29 @@
1
1
  module Sct
2
2
  class Helpers
3
3
 
4
- def self.ingressUrl
5
- ip = `kubectl get ingress`
6
-
7
- if ip.nil? || ip.empty?
8
- puts "Can't fetch ip from kubectl".yellow
4
+ WINDOWS = "Windows"
5
+ MAC_OS = "MacOS"
6
+ UBUNTU = "Ubuntu"
7
+
8
+ def self.ingressAddress
9
+ if self.operatingSystem == WINDOWS
10
+ kubeconfig_file = "minikube-config"
11
+ else
12
+ kubeconfig_file = "config"
13
+ end
14
+
15
+ kubeconfig_path= "#{self.homePath}/.kube/#{kubeconfig_file}"
16
+
17
+ ip = `KUBECONFIG="#{kubeconfig_path}" kubectl get ingress`
18
+
19
+ if ip.nil? || ip.empty?
20
+ puts "Can't fetch IP from kubectl".yellow
9
21
  return nil
10
22
  end
11
-
12
- match = ip.scan(/((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})/);
13
- return match[0].first
23
+
24
+ match = ip.scan(/((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})/)
25
+
26
+ return match.first.first
14
27
  end
15
28
 
16
29
  def self.to_hash(str)
@@ -18,5 +31,60 @@ module Sct
18
31
  str.split("\n").map{|i|i.split('=')}
19
32
  ]
20
33
  end
34
+
35
+ def self.operatingSystem
36
+ proc = `uname -a`
37
+
38
+ case proc
39
+ when /Microsoft/
40
+ os = WINDOWS
41
+ when /Darwin/
42
+ os = MAC_OS
43
+ else
44
+ os = UBUNTU
45
+ end
46
+
47
+ return os
48
+ end
49
+
50
+ def self.homePath
51
+ user = ENV["SUDO_USER"] || ENV["USER"]
52
+
53
+ if self.operatingSystem == MAC_OS
54
+ home = "/Users"
55
+ else
56
+ home = "/home"
57
+ end
58
+
59
+ return "#{home}/#{user}"
60
+ end
61
+
62
+ def self.windowsHomePath
63
+ if self.operatingSystem == WINDOWS
64
+ return self.convertWindowsToWSLPath(`cmd.exe /c echo %userprofile%`)
65
+ end
66
+
67
+ return nil
68
+ end
69
+
70
+ def self.convertWindowsToWSLPath(path)
71
+ if self.operatingSystem == WINDOWS
72
+ return path.gsub(/C:\\/, '/mnt/c/').gsub(/\\\\/, "/").gsub(/\\/, '/').gsub(/\r\n?/, '')
73
+ end
74
+
75
+ return path
76
+ end
77
+
78
+ def self.convertWSLToWindowsPath(path)
79
+ if self.operatingSystem == WINDOWS
80
+ return path.gsub(/\/mnt\/c/, 'C:/').gsub(/\/\//, '/').gsub(/\\\\/, "/").gsub(/\r\n?/, '')
81
+ end
82
+
83
+ return path
84
+ end
85
+
86
+ def self.isSudo
87
+ return !ENV["SUDO_USER"].nil? && !ENV["SUDO_USER"].empty?
88
+ end
21
89
  end
22
- end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module Sct
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
File without changes
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.11
4
+ version: 0.1.12
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-02-04 00:00:00.000000000 Z
11
+ date: 2020-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_interface