sct 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/sct +3 -4
- data/{.DS_Store → cluster/lib/.DS_Store} +0 -0
- data/cluster/lib/cluster.rb +6 -0
- data/cluster/lib/cluster/commands_generator.rb +95 -0
- data/cluster/lib/cluster/module.rb +7 -0
- data/{lib/sct/commands/cluster.rb → cluster/lib/cluster/runner.rb} +96 -118
- data/{lib → sct/lib}/.DS_Store +0 -0
- data/sct/lib/sct.rb +17 -0
- data/sct/lib/sct/.DS_Store +0 -0
- data/sct/lib/sct/cli_tools_distributor.rb +46 -0
- data/{lib → sct/lib}/sct/command.rb +0 -0
- data/{lib → sct/lib}/sct/commands/hostfile.rb +7 -23
- data/sct/lib/sct/commands/init.rb +37 -0
- data/sct/lib/sct/commands/mysqlproxy.rb +20 -0
- data/sct/lib/sct/commands_generator.rb +56 -0
- data/sct/lib/sct/tools.rb +12 -0
- data/sct/lib/sct/version.rb +3 -0
- data/sct_core/lib/.DS_Store +0 -0
- data/sct_core/lib/sct_core.rb +13 -0
- data/{lib/sct → sct_core/lib/sct_core}/.DS_Store +0 -0
- data/sct_core/lib/sct_core/command_executor.rb +104 -0
- data/{lib/sct → sct_core/lib/sct_core}/config.rb +3 -3
- data/sct_core/lib/sct_core/core_ext/string.rb +9 -0
- data/{lib/sct/setup/helpers.rb → sct_core/lib/sct_core/helper.rb} +2 -2
- data/sct_core/lib/sct_core/module.rb +0 -0
- data/sct_core/lib/sct_core/sct_pty.rb +53 -0
- data/sct_core/lib/sct_core/ui/implementations/shell.rb +129 -0
- data/sct_core/lib/sct_core/ui/interface.rb +120 -0
- data/sct_core/lib/sct_core/ui/ui.rb +26 -0
- data/shell/README.md +0 -0
- data/shell/lib/shell.rb +3 -0
- data/{lib/sct → shell/lib/shell}/ClassLevelInheritableAttributes.rb +0 -0
- data/shell/lib/shell/commands_generator.rb +14 -0
- data/{lib/sct → shell/lib/shell}/docker/composer.rb +4 -3
- data/{lib/sct → shell/lib/shell}/docker/docker.rb +7 -10
- data/{lib/sct → shell/lib/shell}/docker/php.rb +3 -2
- data/{lib/sct → shell/lib/shell}/docker/yarn.rb +4 -3
- data/shell/lib/shell/module.rb +9 -0
- data/shell/lib/shell/runner.rb +34 -0
- data/shell/lib/shell/tools.rb +7 -0
- metadata +89 -53
- data/.gitignore +0 -12
- data/.gitlab/merge_request_templates/DefinitionOfDone.md +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -7
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -48
- data/LICENSE.txt +0 -21
- data/README.md +0 -134
- data/Rakefile +0 -6
- data/lib/sct.rb +0 -61
- data/lib/sct/command_interface.rb +0 -18
- data/lib/sct/command_option.rb +0 -14
- data/lib/sct/commands/composer.rb +0 -29
- data/lib/sct/commands/init.rb +0 -51
- data/lib/sct/commands/mysqlproxy.rb +0 -38
- data/lib/sct/commands/php.rb +0 -37
- data/lib/sct/commands/yarn.rb +0 -26
- data/lib/sct/version.rb +0 -3
- data/resources/corefile.yml +0 -45
- data/sct.gemspec +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e738ce105b1b145395e1126e272a2100112b7bc2282963b5ea08f76e0057f26e
|
4
|
+
data.tar.gz: 46076d0d575a48bca094be8a6eaf298ca3cb9943788ed8e52cbe131b1708764f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56a04592b7e8e81065dbad8c2f0913df26e90381bf2d0581741ad4e34db4b044da88688b8a1a5fdf8e08a7ac89676867934efc9f8ff6641eda2437c62df3ef0
|
7
|
+
data.tar.gz: a598f85d2e88af7230783a9918a1d0d90c5e6dd622fd3b98fbed1ea52081d3acde39e95bbf03cc8811e6a0eb6c66c7d7c37e5ff98dad51eb3003bc2f0bb7ea3d
|
data/bin/sct
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'commander/import'
|
4
|
-
require 'sct'
|
5
|
-
|
6
3
|
if RUBY_VERSION < '2.0.0'
|
7
4
|
abort("sct requires Ruby 2.0.0 or higher")
|
8
5
|
end
|
@@ -11,6 +8,8 @@ def self.windows?
|
|
11
8
|
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
12
9
|
end
|
13
10
|
|
11
|
+
require 'sct/cli_tools_distributor'
|
12
|
+
|
14
13
|
if ARGV.include?('-v') || ARGV.include?('--version')
|
15
14
|
# This will print out the sct binary path right above the
|
16
15
|
# version number. Very often, users are not aware they have
|
@@ -20,4 +19,4 @@ if ARGV.include?('-v') || ARGV.include?('--version')
|
|
20
19
|
puts("-----------------------------")
|
21
20
|
end
|
22
21
|
|
23
|
-
Sct::
|
22
|
+
Sct::CLIToolsDistributor.take_off
|
Binary file
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'commander'
|
2
|
+
require_relative 'runner'
|
3
|
+
|
4
|
+
module Cluster
|
5
|
+
class CommandsGenerator
|
6
|
+
include Commander::Methods
|
7
|
+
|
8
|
+
def self.start
|
9
|
+
self.new.run
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
program :name, 'cluster'
|
14
|
+
program :version, Sct::VERSION
|
15
|
+
program :description, 'CLI for \'cluster\' - Manage your local kubernetes cluster'
|
16
|
+
|
17
|
+
global_option('--verbose') { $verbose = true }
|
18
|
+
|
19
|
+
command :up do |c|
|
20
|
+
|
21
|
+
c.syntax = "sct cluster up"
|
22
|
+
c.description = "Start the cluster"
|
23
|
+
c.option '--clean', 'start a clean cluster. Old cluster will be purged if available.'
|
24
|
+
|
25
|
+
c.action do |args, options|
|
26
|
+
if options.clean
|
27
|
+
Cluster::Runner.new.reset
|
28
|
+
else
|
29
|
+
Cluster::Runner.new.launch
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
command :down do |c|
|
36
|
+
|
37
|
+
c.syntax = 'sct cluster down'
|
38
|
+
c.description = 'stop the cluster'
|
39
|
+
|
40
|
+
c.action do |args, options|
|
41
|
+
Cluster::Runner.new.down
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
command :reset do |c|
|
46
|
+
|
47
|
+
c.syntax = 'sct cluster reset'
|
48
|
+
c.description = 'reset your cluster and start with a clean cluster'
|
49
|
+
|
50
|
+
c.action do |args, options|
|
51
|
+
Cluster::Runner.new.reset
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
alias_command :'setup', :'reset'
|
56
|
+
|
57
|
+
command :status do |c|
|
58
|
+
|
59
|
+
c.syntax = 'sct cluster status'
|
60
|
+
c.description = 'see the status of your cluster'
|
61
|
+
|
62
|
+
c.action do |args, options|
|
63
|
+
Cluster::Runner.new.status
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
command :'update config' do |c|
|
68
|
+
|
69
|
+
c.syntax = 'sct cluster update config'
|
70
|
+
c.description = 'update the cluster configuration'
|
71
|
+
|
72
|
+
c.action do |args, options|
|
73
|
+
Cluster::Runner.new.update_config
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
command :'delete pods' do |c|
|
78
|
+
c.syntax = 'sct cluster delete stalled pods'
|
79
|
+
c.description = 'delete stalled pods from the cluster'
|
80
|
+
c.option '--stalled', 'delete stalled pods'
|
81
|
+
c.option '--all', 'delete all pods'
|
82
|
+
|
83
|
+
c.action do |args, options|
|
84
|
+
|
85
|
+
Cluster::Runner.new.delete_stalled_pods if options.stalled
|
86
|
+
UI.important("Currently its not possible to delete all pods") if options.all
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
default_command :status
|
91
|
+
|
92
|
+
run!
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,54 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
IS_PUBLIC_COMMAND = true
|
9
|
-
SYNTAX = 'sct cluster up | sct cluster down | sct cluster setup | sct cluster reset | sct cluster update-config | sct cluster delete-stalled-pods | sct cluster status'
|
10
|
-
SUMMARY = 'Perform actions on the minikube cluster.'
|
11
|
-
EXAMPLE = 'sct cluster up | sct cluster down | sct cluster setup | sct cluster reset | sct cluster update-config | sct cluster delete-stalled-pods | sct cluster status'
|
12
|
-
EXAMPLE_DESCRIPTION = 'Perform actions on the minikube cluster.'
|
13
|
-
DESCRIPTION = "sct cluster allows you to start, stop, setup/reset, update the config, delete the stalled pods, or status of the Spend Cloud minikube cluster."
|
14
|
-
|
15
|
-
OPTIONS = []
|
16
|
-
|
17
|
-
def execute(args, options)
|
18
|
-
return puts "SCT has not been initialized. Run 'sct init' first.".red unless Sct::Config.exists
|
19
|
-
|
20
|
-
case args[0]
|
21
|
-
when "up"
|
22
|
-
up
|
23
|
-
when "down"
|
24
|
-
down
|
25
|
-
when "update-config"
|
26
|
-
update_config
|
27
|
-
when "setup", "reset"
|
28
|
-
reset
|
29
|
-
when "delete-stalled-pods"
|
30
|
-
delete_stalled_pods(feedback: true)
|
31
|
-
when "status"
|
32
|
-
status
|
33
|
-
else
|
34
|
-
puts "Unknown or missing argument. Please run 'sct cluster --help'.".red
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def up
|
39
|
-
start
|
1
|
+
module Cluster
|
2
|
+
class Runner
|
3
|
+
|
4
|
+
def launch
|
5
|
+
return UI.error("SCT has not been initialized. Run 'sct init' first.") unless SctCore::Config.exists
|
6
|
+
start_cluster
|
40
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(" ")}"
|
41
8
|
run_command "kubectl rollout status -n kube-system deployment/registry-creds"
|
42
9
|
post_start
|
43
10
|
end
|
44
11
|
|
12
|
+
def start_cluster
|
13
|
+
if SctCore::Helper.operatingSystem == SctCore::Helper::MAC_OS
|
14
|
+
run_command "#{minikube} start --cpus=$(sysctl -n hw.ncpu) --memory=8G"
|
15
|
+
else
|
16
|
+
run_command "#{minikube} start --cpus=$(cat /proc/cpuinfo | grep processor | wc -l) --memory=10G"
|
17
|
+
end
|
18
|
+
run_command "#{minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'"
|
19
|
+
update_config
|
20
|
+
end
|
21
|
+
|
22
|
+
def post_start
|
23
|
+
wait_for_pods
|
24
|
+
run_command "sudo sct hostfile"
|
25
|
+
UI.success("\n✔️ You can visit your environment at 👉 https://spend-cloud.spend.cloud.local 👌")
|
26
|
+
end
|
27
|
+
|
45
28
|
def down
|
46
29
|
run_command "#{minikube} stop"
|
47
30
|
end
|
48
31
|
|
49
32
|
def reset
|
50
33
|
run_command "#{minikube} delete"
|
51
|
-
|
34
|
+
start_cluster
|
52
35
|
create_secrets
|
53
36
|
run_command "#{minikube} addons enable registry-creds"
|
54
37
|
run_command "#{minikube} addons enable ingress"
|
@@ -63,51 +46,84 @@ module Sct
|
|
63
46
|
post_start
|
64
47
|
end
|
65
48
|
|
49
|
+
def wait_for_pods
|
50
|
+
UI.important("Waiting for pods to become ready...")
|
51
|
+
|
52
|
+
while ! pods.all? { |pod| pod[:status] == "Running" }
|
53
|
+
delete_stalled_pods
|
54
|
+
|
55
|
+
sleep 5
|
56
|
+
end
|
57
|
+
|
58
|
+
UI.success("Pods are now ready.")
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete_stalled_pods(feedback: false)
|
62
|
+
|
63
|
+
return UI.success("No stalled pods found") unless !pods.to_a.empty?
|
64
|
+
|
65
|
+
stalled_pods = pods.select { |pod| pod[:stalled] }
|
66
|
+
|
67
|
+
if stalled_pods.empty?
|
68
|
+
UI.success("There are no stalled pods.") if feedback
|
69
|
+
else
|
70
|
+
run_command "kubectl delete pods #{stalled_pods.map { |pod| pod[:name] } .join(" ")}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
66
74
|
def update_config
|
67
|
-
if
|
68
|
-
windows_home_path =
|
75
|
+
if SctCore::Helper.operatingSystem == SctCore::Helper::WINDOWS
|
76
|
+
windows_home_path = SctCore::Helper.windowsHomePath
|
69
77
|
kube_file_path = windows_home_path+"/.kube/config"
|
70
78
|
|
71
79
|
if !File.exists?(kube_file_path)
|
72
|
-
return
|
80
|
+
return UI.error("#{kube_file_path} doesn't exist")
|
73
81
|
end
|
74
82
|
|
75
83
|
run_command "sed -e 's~\\\\~/~g' -e 's~C:~/mnt/c~g' < #{kube_file_path} > ~/.kube/minikube-config"
|
76
84
|
|
77
|
-
|
85
|
+
UI.success("#{kube_file_path} copied to ~/.kube/minikube-config")
|
78
86
|
end
|
79
87
|
|
80
88
|
run_command "kubectl config use-context minikube"
|
81
89
|
|
82
|
-
run_command "kubectl replace -n kube-system -f #{File.expand_path('
|
83
|
-
|
90
|
+
run_command "kubectl replace -n kube-system -f #{File.expand_path('../../resources/corefile.yml', __dir__)}"
|
91
|
+
old_list = pods("kube-system").map { |pod| pod[:name] if pod[:name].start_with? "coredns" }.compact
|
92
|
+
run_command "kubectl delete pod -n kube-system #{old_list.join(" ")}" unless old_list.to_a.empty?
|
84
93
|
run_command "kubectl rollout status -n kube-system deployment/coredns"
|
85
94
|
end
|
86
95
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
if stalled_pods.empty?
|
91
|
-
puts "There are no stalled pods.".green if feedback
|
96
|
+
def pods(namespace = nil)
|
97
|
+
if namespace
|
98
|
+
output = `kubectl get pods -n #{namespace}`
|
92
99
|
else
|
93
|
-
|
100
|
+
output = `kubectl get pods`
|
94
101
|
end
|
95
|
-
end
|
96
102
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
103
|
+
# split output lines
|
104
|
+
lines = output.split "\n"
|
105
|
+
|
106
|
+
# exclude first line (table header)
|
107
|
+
lines = lines[1..-1]
|
108
|
+
|
109
|
+
if lines.to_a.empty?
|
110
|
+
return
|
102
111
|
end
|
103
|
-
run_command "#{minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'"
|
104
|
-
update_config
|
105
|
-
end
|
106
112
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
113
|
+
# get name and status of each pod
|
114
|
+
lines.map do |line|
|
115
|
+
columns = line.split(" ")
|
116
|
+
|
117
|
+
name = columns[0]
|
118
|
+
status = columns[2]
|
119
|
+
stalled = status == "ErrImagePull" || status == "ImagePullBackOff"
|
120
|
+
|
121
|
+
{
|
122
|
+
name: name,
|
123
|
+
status: status,
|
124
|
+
stalled: stalled
|
125
|
+
}
|
126
|
+
end
|
111
127
|
end
|
112
128
|
|
113
129
|
def create_secrets
|
@@ -123,35 +139,23 @@ module Sct
|
|
123
139
|
end
|
124
140
|
|
125
141
|
def wait_for_gcr_secret
|
126
|
-
|
142
|
+
UI.important("Waiting for Google Cloud Registry secret to become available...")
|
127
143
|
|
128
144
|
while ! `kubectl get secrets`.include? "gcr-secret"
|
129
145
|
sleep 5
|
130
146
|
end
|
131
147
|
|
132
|
-
|
148
|
+
UI.success("Google Cloud Registry secret is now available.")
|
133
149
|
end
|
134
150
|
|
135
151
|
def wait_for_ingress_ip
|
136
|
-
|
152
|
+
UI.important("Waiting for ingress IP to become available...")
|
137
153
|
|
138
154
|
while `kubectl describe ingress | grep "Address" | awk '{print $2}'`.empty?
|
139
155
|
sleep 5
|
140
156
|
end
|
141
157
|
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
def wait_for_pods
|
146
|
-
puts "Waiting for pods to become ready...".yellow
|
147
|
-
|
148
|
-
while ! pods.all? { |pod| pod[:status] == "Running" }
|
149
|
-
delete_stalled_pods
|
150
|
-
|
151
|
-
sleep 5
|
152
|
-
end
|
153
|
-
|
154
|
-
puts "Pods are now ready.".green
|
158
|
+
UI.success("Ingress IP is now available.")
|
155
159
|
end
|
156
160
|
|
157
161
|
def status
|
@@ -162,7 +166,7 @@ module Sct
|
|
162
166
|
print_pods_status("kube-system")
|
163
167
|
print_pods_status
|
164
168
|
else
|
165
|
-
|
169
|
+
UI.important("Please check your minikube status. If all services are stopped you should start the minikube first.")
|
166
170
|
end
|
167
171
|
end
|
168
172
|
|
@@ -201,7 +205,14 @@ module Sct
|
|
201
205
|
end
|
202
206
|
|
203
207
|
def print_pods_status(namespace = nil)
|
204
|
-
|
208
|
+
|
209
|
+
pods_list = pods(namespace)
|
210
|
+
|
211
|
+
if pods_list.to_a.empty?
|
212
|
+
return
|
213
|
+
end
|
214
|
+
|
215
|
+
rows = pods_list.map do |pod|
|
205
216
|
[
|
206
217
|
pod[:name],
|
207
218
|
pod[:status] == "Running" ? pod[:status].green : pod[:status].red
|
@@ -211,35 +222,6 @@ module Sct
|
|
211
222
|
puts Terminal::Table.new title: "Pods (namespace: #{namespace || "default"})".green, headings: ['Name', 'Status'], rows: rows
|
212
223
|
end
|
213
224
|
|
214
|
-
def pods(namespace = nil)
|
215
|
-
if namespace
|
216
|
-
output = `kubectl get pods -n #{namespace}`
|
217
|
-
else
|
218
|
-
output = `kubectl get pods`
|
219
|
-
end
|
220
|
-
|
221
|
-
# split output lines
|
222
|
-
lines = output.split "\n"
|
223
|
-
|
224
|
-
# exclude first line (table header)
|
225
|
-
lines = lines[1..-1]
|
226
|
-
|
227
|
-
# get name and status of each pod
|
228
|
-
lines.map do |line|
|
229
|
-
columns = line.split(" ")
|
230
|
-
|
231
|
-
name = columns[0]
|
232
|
-
status = columns[2]
|
233
|
-
stalled = status == "ErrImagePull" || status == "ImagePullBackOff"
|
234
|
-
|
235
|
-
{
|
236
|
-
name: name,
|
237
|
-
status: status,
|
238
|
-
stalled: stalled
|
239
|
-
}
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
225
|
def run_command command
|
244
226
|
if ! system command
|
245
227
|
raise command.red
|
@@ -247,15 +229,11 @@ module Sct
|
|
247
229
|
end
|
248
230
|
|
249
231
|
def minikube
|
250
|
-
if
|
232
|
+
if SctCore::Helper.operatingSystem == SctCore::Helper::WINDOWS
|
251
233
|
return "minikube.exe"
|
252
234
|
else
|
253
235
|
return "minikube"
|
254
236
|
end
|
255
237
|
end
|
256
|
-
|
257
|
-
implements CommandInterface
|
258
|
-
|
259
238
|
end
|
260
|
-
|
261
|
-
end
|
239
|
+
end
|