sct 0.1.35 → 1.0.5

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.
@@ -1,6 +1,6 @@
1
1
  module Sct
2
2
  class CLIToolsDistributor
3
- class << self
3
+ class << self
4
4
  def take_off
5
5
  require 'sct'
6
6
 
@@ -8,18 +8,18 @@ module Sct
8
8
 
9
9
  if tool_name && Sct::TOOLS.include?(tool_name.to_sym)
10
10
  # Triggering a specific tool
11
-
11
+
12
12
  require tool_name
13
13
  begin
14
14
  # First, remove the tool's name from the arguments
15
15
  # Since it will be parsed by the `commander` at a later point
16
16
  # and it must not contain the binary name
17
17
  ARGV.shift
18
-
18
+
19
19
  # Import the CommandsGenerator class, which is used to parse
20
20
  # the user input
21
21
  require File.join(tool_name, "commands_generator")
22
-
22
+
23
23
  # Call the tool's CommandsGenerator class and let it do its thing
24
24
  commands_generator = Object.const_get(tool_name.sct_module)::CommandsGenerator
25
25
  rescue LoadError
@@ -28,15 +28,15 @@ module Sct
28
28
  # When we launch this feature, this should never be the case
29
29
  abort("#{tool_name} can't be called via `sct #{tool_name}`, run '#{tool_name}' directly instead".red)
30
30
  end
31
-
31
+
32
32
  # Some of the tools might use other actions so need to load all
33
33
  # actions before we start the tool generator here in the future
34
34
  Sct.load_actions
35
-
35
+
36
36
  # trigger start on tool
37
37
  commands_generator.start
38
38
 
39
- else
39
+ else
40
40
  require "sct/commands_generator"
41
41
  Sct::CommandsGenerator.start
42
42
  end
@@ -47,4 +47,4 @@ module Sct
47
47
 
48
48
  end
49
49
  end
50
- end
50
+ end
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+
3
+ module Sct
4
+ class DevCommand
5
+
6
+ @@file = "docker-compose.dev.yml"
7
+
8
+ def error message
9
+ UI.error message
10
+ exit 1
11
+ end
12
+
13
+ def dc command, env = {}
14
+ system env, "docker-compose -f ~/development/spend-cloud/docker-compose.yml #{command}"
15
+ end
16
+
17
+ def dc_dev command, env = {}
18
+ system env, "docker-compose -f #{@@file} #{command}"
19
+ end
20
+
21
+ def manifest
22
+ if !File.exist? @@file
23
+ error "Could not find file '#{@@file}'."
24
+ end
25
+
26
+ YAML.load File.read @@file
27
+ end
28
+
29
+ def execute args, options
30
+ services = manifest["services"].to_a
31
+
32
+ if services.length != 1
33
+ error "Currently sct only supports a single service declaration in '#{@@file}'. Contact the infra guild if you consider this a limitation."
34
+ end
35
+
36
+ service, service_spec = services.first
37
+
38
+ container = service_spec["container_name"]
39
+ command = service_spec["command"] || ""
40
+
41
+ env = { "PUID" => `id -u`.chomp, "PGID" => `id -g`.chomp }
42
+
43
+ if options.pull
44
+ return unless dc_dev "pull"
45
+ end
46
+
47
+ if options.build
48
+ return unless dc_dev "build #{options.pull ? "--pull" : ""}", env
49
+ end
50
+
51
+ if options.pull or options.build
52
+ system "docker image prune -f"
53
+ end
54
+
55
+ return unless dc "rm --stop --force #{service}"
56
+
57
+ dc_dev "run --rm --service-ports --name #{container} #{service} #{command}", env
58
+
59
+ dc "up --detach #{service}"
60
+ end
61
+
62
+ end
63
+ end
@@ -1,20 +1,14 @@
1
1
  module Sct
2
2
  class MysqlproxyCommand
3
-
3
+
4
4
  DEFAULT_SECRET_NAME = "gcloud-credentials"
5
5
 
6
6
  def execute(args, options)
7
-
8
- return UI.error("SCT has not been initialized. Run 'sct init' first.") unless SctCore::Config.exists
9
-
10
- path = SctCore::Config.get('cloud-proxy-path')
11
-
12
7
  system("kubectl delete secret gcloud-credentials")
13
- system("kubectl create secret generic gcloud-credentials --from-file=#{path}")
14
-
8
+ system("kubectl create secret generic gcloud-credentials --from-file=~/.config/gcloud/application_default_credentials.json")
9
+
15
10
  UI.success("Authenticated with secret-name: '#{DEFAULT_SECRET_NAME}'")
16
11
  end
17
-
18
- end
19
12
 
20
- end
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ require 'yaml'
2
+
3
+ module Sct
4
+ class ShellCommand
5
+
6
+ def error message
7
+ UI.error message
8
+ exit 1
9
+ end
10
+
11
+ def execute args, options
12
+ command = args.empty? ? "sh" : args.join(" ")
13
+
14
+ file = "docker-compose.dev.yml"
15
+
16
+ if !File.exist? file
17
+ error "Could not find file '#{file}'."
18
+ end
19
+
20
+ manifest = YAML.load File.read file
21
+
22
+ services = manifest["services"].to_a
23
+
24
+ if services.length != 1
25
+ error "Currently sct only supports a single service declaration in '#{file}'. Contact the infra guild if you consider this a limitation."
26
+ end
27
+
28
+ service, service_spec = services.first
29
+
30
+ container = service_spec["container_name"]
31
+
32
+ project = `docker container inspect --format '{{index .Config.Labels "com.docker.compose.project"}}' #{container}`.chomp
33
+
34
+ if project == "spend-cloud"
35
+ print "This container was not started with 'sct dev'. Are you sure you want to continue? [y/N] ".red
36
+
37
+ answer = $stdin.readline.chomp.downcase
38
+
39
+ if answer != "y"
40
+ exit
41
+ end
42
+ end
43
+
44
+ user = options.root ? "root:root" : "$(id -u):$(id -g)"
45
+
46
+ system "docker exec -it --user #{user} #{container} #{command}"
47
+ end
48
+
49
+ end
50
+ end
@@ -17,51 +17,40 @@ module Sct
17
17
 
18
18
  global_option('--verbose') { $verbose = true }
19
19
 
20
- command :init do |c|
21
- c.syntax = 'sct init'
22
- c.description = 'setup sct'
23
-
24
- c.action do |args, options|
25
- UI.important("setting up sct")
26
- Sct::InitCommand.new.execute(args, options)
27
- end
28
- end
29
-
30
- command :hostfile do |c|
31
-
32
- c.syntax = 'sct hostfile'
33
- c.description = 'patch hostfile with kubernetes ip'
34
-
35
- c.action do |args, options|
36
- UI.important("Trying to patch hosts file...")
37
- Sct::HostfileCommand.new.execute(args, options)
38
- end
39
- end
40
-
41
20
  command :'mysql-proxy' do |c|
42
-
43
21
  c.syntax = 'sct mysql-proxy'
44
22
  c.description = 'setup google mysql proxy'
45
23
 
46
24
  c.action do |args, options|
47
25
  UI.important("Trying to setup mysql proxy")
48
- Sct::MysqlproxyCommand.new.execute(args, options)
26
+ Sct::MysqlproxyCommand.new.execute args, options
49
27
  end
50
-
51
28
  end
52
29
 
53
30
  command :'cluster' do |c|
54
-
55
31
  c.syntax = 'sct cluster'
56
32
  c.description = 'make changes to the cluster'
57
-
58
33
  end
59
34
 
60
35
  command :'shell' do |c|
61
-
62
36
  c.syntax = 'sct shell'
63
37
  c.description = 'run commands from the shell using docker containers'
38
+ c.option '--root', 'run as root user in the container'
64
39
 
40
+ c.action do |args, options|
41
+ Sct::ShellCommand.new.execute args, options
42
+ end
43
+ end
44
+
45
+ command :'dev' do |c|
46
+ c.syntax = 'sct dev'
47
+ c.description = 'start development container in the current directory'
48
+ c.option '--build', '(re)build images before starting'
49
+ c.option '--pull', 'pull latest images before starting'
50
+
51
+ c.action do |args, options|
52
+ Sct::DevCommand.new.execute args, options
53
+ end
65
54
  end
66
55
 
67
56
  run!
data/sct/lib/sct/tools.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  module Sct
2
2
  TOOLS = [
3
3
  :sct,
4
- :shell,
5
4
  :cluster
6
5
  ]
7
-
6
+
8
7
  # a list of all the config files we currently expect
9
- TOOL_CONFIG_FILES = [
10
-
11
- ]
12
- end
8
+ TOOL_CONFIG_FILES = []
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Sct
2
- VERSION = "0.1.35"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require_relative 'sct_core/core_ext/string'
2
- require_relative 'sct_core/config'
3
2
  require_relative 'sct_core/helper'
4
3
  require_relative 'sct_core/update_checker/update_checker'
5
4
  require_relative 'sct_core/command_executor'
@@ -11,4 +10,4 @@ require 'colored'
11
10
  require 'commander'
12
11
 
13
12
  # these need to be imported after commander
14
- require_relative 'sct_core/module'
13
+ require_relative 'sct_core/module'
@@ -5,13 +5,13 @@ module SctCore
5
5
  MAC_OS = "MacOS"
6
6
  UBUNTU = "Ubuntu"
7
7
 
8
- def self.to_hash(str)
8
+ def self.to_hash str
9
9
  Hash[
10
10
  str.split("\n").map{|i|i.split('=')}
11
11
  ]
12
12
  end
13
13
 
14
- def self.operatingSystem
14
+ def self.operating_system
15
15
  proc = `uname -a`
16
16
 
17
17
  case proc.downcase
@@ -29,7 +29,7 @@ module SctCore
29
29
  def self.homePath
30
30
  user = ENV["SUDO_USER"] || ENV["USER"]
31
31
 
32
- if self.operatingSystem == MAC_OS
32
+ if self.operating_system == MAC_OS
33
33
  home = "/Users"
34
34
  else
35
35
  home = "/home"
@@ -46,7 +46,7 @@ module SctCore
46
46
  return nil
47
47
  end
48
48
 
49
- def self.convertWindowsToWSLPath(path)
49
+ def self.convertWindowsToWSLPath path
50
50
  if self.is_windows?
51
51
  return path.gsub(/C:\\/, '/mnt/c/').gsub(/\\\\/, "/").gsub(/\\/, '/').gsub(/\r\n?/, '')
52
52
  end
@@ -54,7 +54,7 @@ module SctCore
54
54
  return path
55
55
  end
56
56
 
57
- def self.convertWSLToWindowsPath(path)
57
+ def self.convertWSLToWindowsPath path
58
58
  if self.is_windows?
59
59
  return path.gsub(/\/mnt\/c/, 'C:/').gsub(/\/\//, '/').gsub(/\\\\/, "/").gsub(/\r\n?/, '')
60
60
  end
@@ -67,7 +67,7 @@ module SctCore
67
67
  end
68
68
 
69
69
  def self.is_windows?
70
- return self.operatingSystem == WINDOWS
70
+ return self.operating_system == WINDOWS
71
71
  end
72
72
 
73
73
  def self.is_windows_administrator?
@@ -93,5 +93,6 @@ module SctCore
93
93
  self.ensure_sudo
94
94
  self.ensure_windows_administrator
95
95
  end
96
+
96
97
  end
97
98
  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.35
4
+ version: 1.0.5
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-12-24 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -200,17 +200,15 @@ files:
200
200
  - cluster/lib/cluster.rb
201
201
  - cluster/lib/cluster/commands_generator.rb
202
202
  - cluster/lib/cluster/module.rb
203
- - cluster/lib/cluster/resources/.DS_Store
204
- - cluster/lib/cluster/resources/corefile.yml
205
203
  - cluster/lib/cluster/runner.rb
206
204
  - sct/lib/.DS_Store
207
205
  - sct/lib/sct.rb
208
206
  - sct/lib/sct/.DS_Store
209
207
  - sct/lib/sct/cli_tools_distributor.rb
210
208
  - sct/lib/sct/command.rb
211
- - sct/lib/sct/commands/hostfile.rb
212
- - sct/lib/sct/commands/init.rb
209
+ - sct/lib/sct/commands/dev.rb
213
210
  - sct/lib/sct/commands/mysqlproxy.rb
211
+ - sct/lib/sct/commands/shell.rb
214
212
  - sct/lib/sct/commands_generator.rb
215
213
  - sct/lib/sct/tools.rb
216
214
  - sct/lib/sct/version.rb
@@ -218,7 +216,6 @@ files:
218
216
  - sct_core/lib/sct_core.rb
219
217
  - sct_core/lib/sct_core/.DS_Store
220
218
  - sct_core/lib/sct_core/command_executor.rb
221
- - sct_core/lib/sct_core/config.rb
222
219
  - sct_core/lib/sct_core/core_ext/string.rb
223
220
  - sct_core/lib/sct_core/helper.rb
224
221
  - sct_core/lib/sct_core/module.rb
@@ -227,10 +224,6 @@ files:
227
224
  - sct_core/lib/sct_core/ui/interface.rb
228
225
  - sct_core/lib/sct_core/ui/ui.rb
229
226
  - sct_core/lib/sct_core/update_checker/update_checker.rb
230
- - shell/lib/shell.rb
231
- - shell/lib/shell/commands_generator.rb
232
- - shell/lib/shell/module.rb
233
- - shell/lib/shell/runner.rb
234
227
  homepage: https://gitlab.com/proactive-software/packages/sct
235
228
  licenses:
236
229
  - MIT
@@ -244,7 +237,6 @@ require_paths:
244
237
  - cluster/lib
245
238
  - sct/lib
246
239
  - sct_core/lib
247
- - shell/lib
248
240
  required_ruby_version: !ruby/object:Gem::Requirement
249
241
  requirements:
250
242
  - - ">="
@@ -256,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
248
  - !ruby/object:Gem::Version
257
249
  version: '0'
258
250
  requirements: []
259
- rubygems_version: 3.1.2
251
+ rubygems_version: 3.0.8
260
252
  signing_key:
261
253
  specification_version: 4
262
254
  summary: Spend Cloud Tool.
@@ -1,45 +0,0 @@
1
- apiVersion: v1
2
- data:
3
- Corefile: |
4
- .:53 {
5
- errors
6
- health {
7
- lameduck 5s
8
- }
9
- ready
10
- kubernetes cluster.local in-addr.arpa ip6.arpa {
11
- pods insecure
12
- fallthrough in-addr.arpa ip6.arpa
13
- ttl 30
14
- }
15
- prometheus :9153
16
- forward . 8.8.8.8
17
- cache 30
18
- loop
19
- reload
20
- loadbalance
21
- }
22
- Corefile-backup: |
23
- .:53 {
24
- errors
25
- health {
26
- lameduck 5s
27
- }
28
- ready
29
- kubernetes cluster.local in-addr.arpa ip6.arpa {
30
- pods insecure
31
- fallthrough in-addr.arpa ip6.arpa
32
- ttl 30
33
- }
34
- prometheus :9153
35
- forward . /etc/resolv.conf
36
- cache 30
37
- loop
38
- reload
39
- loadbalance
40
- }
41
- kind: ConfigMap
42
- metadata:
43
- creationTimestamp: null
44
- name: coredns
45
- selfLink: /api/v1/namespaces/kube-system/configmaps/coredns