deis-interactive 0.0.1 → 0.0.3

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
  SHA1:
3
- metadata.gz: 9eaaad20980391f761d494697ebc109d4cf74c31
4
- data.tar.gz: ac52c7695114c4a7a48b2191308ed1e5ec3733ea
3
+ metadata.gz: 1650e0c2a5a4cedc3f0b96b5295ddbca67abded1
4
+ data.tar.gz: ab4b1fcc90cba3860fe71d21e7f21d0bd494aec4
5
5
  SHA512:
6
- metadata.gz: b8c13d3f7ecef910ee63e29a79339a49cfe04905fdedb8c2834ff26fcca65f485c9fc44f054d7de4ae5bd4196ce684d41f861c7c64d581ab686b7a56b003b80a
7
- data.tar.gz: 122becac77d7867bd9b231644b37e0be87a691874274fdf36faca1e1708c5a714336a54f79a4d35d04771faab97c91dfa1a33d3d48b803c5324b81eb2daa4de2
6
+ metadata.gz: 315d3534f8b14bad83b5fdbb3c80cbcefe0d431de7e135859e7817810ec5ff3975f1358ebd273495d862577d79bf0fec1eb55dd83f9741a302bfbc0630cf7d31
7
+ data.tar.gz: d30d620da15a99839d869dcb95ae58f5a1f3aa3423d84e1d87e8fe99a8f2279555f6d9ba6debf813e3388f92fdef122ba7a4f64df6cf71cdefee73a36b5fba01
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ tmp
18
18
  vendor/
19
19
  .idea/
20
20
  binstubs/
21
+ .byebug_history
data/README.md CHANGED
@@ -27,6 +27,16 @@ Runing console for your Rails app:
27
27
 
28
28
  $ bundle exec deis-rails console -a MY-APP
29
29
 
30
+ Logs for your Rails app:
31
+
32
+ $ bundle exec deis-rails logs -a MY-APP -p MY-PROCESS -f
33
+
34
+
35
+ Execute a bash:
36
+
37
+ $ bundle exec deis-rails exec -a MY-APP bash ARGS
38
+
39
+
30
40
  ## Contributing
31
41
 
32
42
  1. Fork it
data/bin/deis-rails CHANGED
@@ -1,49 +1,37 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "thor"
4
- require "shellwords"
5
4
 
6
5
  class DeisRails < Thor
7
6
  desc "console -a APP", "run console on an app"
8
7
  method_option :app, aliases: ["a"], type: :string, required: true, desc: "Name of the app"
9
8
  def console
9
+ require_relative "../lib/deis-interactive/rails/console"
10
10
  app = options[:app]
11
- DeisRailsConsole.new(app).run
12
- end
13
- end
14
-
15
- class DeisRailsConsole
16
- attr_reader :app
17
-
18
- def initialize(app)
19
- @app = app
11
+ DeisInteractive::Rails::Console.new(app).perform
20
12
  end
21
13
 
22
- def run
23
- puts "Run rails console attaching to #{container_id}"
24
- exec "kubectl exec -it --namespace #{app} #{container_id} -- bash -c #{Shellwords.escape(bash)}"
25
- end
26
-
27
- def process
28
- ENV['DEIS_CONSOLE_PROCESS'] || "web"
29
- end
30
-
31
- def container_id
32
- @container_id ||= (
33
- sample_container_id = container_ids.sample
34
- if (sample_container_id.nil?)
35
- raise "Error. None container of #{process} is found. kubectl won't be able to attach to run a console session"
36
- end
37
- sample_container_id.split("/").last
38
- )
14
+ desc "exec -a APP COMMAND PARAMS", "run console on an app"
15
+ method_option :app, aliases: ["a"], type: :string, required: true, desc: "Name of the app"
16
+ def exec(command, *params)
17
+ require_relative "../lib/deis-interactive/rails/exec"
18
+ app = options[:app]
19
+ require 'byebug'
20
+ debugger
21
+ DeisInteractive::Rails::Exec.new(app, command, params).perform
39
22
  end
40
23
 
41
- def container_ids
42
- `kubectl get pods --namespace #{app} -o name | grep #{app}-#{process}`.split("\n").reject(&:empty?)
43
- end
44
24
 
45
- def bash
46
- ". /app/.profile.d/ruby.sh && PATH=/app/.heroku/node/bin:$PATH /app/bin/rails c"
25
+ desc "logs [-f] -a APP [-d PROCESS]", "logs on an app"
26
+ method_option :app, aliases: ["a"], type: :string, required: true, desc: "Name of the app"
27
+ method_option :process, aliases: ["p"], type: :string, required: false, desc: "Processes to be logged on"
28
+ method_option :follow, aliases: ["f"], type: :boolean, required: false, desc: "Tail the log"
29
+ def logs
30
+ require_relative "../lib/deis-interactive/rails/logs"
31
+ app = options[:app]
32
+ process = options[:process]
33
+ follow = options[:follow]
34
+ DeisInteractive::Rails::Logs.new(app, process, follow: follow).perform
47
35
  end
48
36
  end
49
37
 
@@ -0,0 +1,29 @@
1
+ module DeisInteractive
2
+ module Rails
3
+ class Base
4
+ attr_reader :app, :process
5
+
6
+ def initialize(app, process)
7
+ @app = app
8
+ @process = process
9
+ end
10
+
11
+ def processes_pattern
12
+ patterns = [app]
13
+ patterns << process if process
14
+ patterns.join("-")
15
+ end
16
+
17
+ def pod_ids
18
+ @pod_ids ||= (
19
+ puts "Fetching pod ids..."
20
+ output= `kubectl get pods --namespace #{app} -o name | grep #{processes_pattern}`
21
+ output.split("\n").reject(&:empty?).map do |str|
22
+ str.split("/").last
23
+ end
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,31 @@
1
+ require_relative 'base'
2
+ require "shellwords"
3
+
4
+ module DeisInteractive
5
+ module Rails
6
+ class Console < Base
7
+ def initialize(app)
8
+ super(app, ENV['DEIS_CONSOLE_PROCESS'] || "web")
9
+ end
10
+
11
+ def perform
12
+ puts "Run rails console attaching to #{pod_id}"
13
+ exec "kubectl exec -it --namespace #{app} #{pod_id} -- bash -c #{Shellwords.escape(bash)}"
14
+ end
15
+
16
+ def pod_id
17
+ @pod_id ||= (
18
+ sample_pod_id = pod_ids.sample
19
+ if (sample_pod_id.nil?)
20
+ raise "Error. No pod of #{process} is found. kubectl won't be able to attach to run a console session"
21
+ end
22
+ sample_pod_id
23
+ )
24
+ end
25
+
26
+ def bash
27
+ ". /app/.profile.d/ruby.sh && PATH=/app/.heroku/node/bin:$PATH /app/bin/rails c"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,46 @@
1
+ require_relative 'base'
2
+ require "shellwords"
3
+
4
+ module DeisInteractive
5
+ module Rails
6
+ class Exec < Base
7
+ attr_reader :cmd
8
+ attr_reader :params
9
+
10
+ def initialize(app, cmd, params)
11
+ super(app, ENV['DEIS_CONSOLE_PROCESS'] || "web")
12
+ @cmd = cmd
13
+ @params = params
14
+ end
15
+
16
+ def args
17
+ result = [cmd]
18
+ if params
19
+ result += params
20
+ end
21
+ result
22
+ end
23
+
24
+ def escaped_args
25
+ args.map do |arg|
26
+ Shellwords.escape(arg)
27
+ end.join(" ")
28
+ end
29
+
30
+ def perform
31
+ puts "Execute #{args} on #{pod_id}"
32
+ exec "kubectl exec -it --namespace #{app} #{pod_id} -- bash -c #{escaped_args}"
33
+ end
34
+
35
+ def pod_id
36
+ @pod_id ||= (
37
+ sample_pod_id = pod_ids.sample
38
+ if (sample_pod_id.nil?)
39
+ raise "Error. No pod of #{process} is found. kubectl won't be able to attach to run a console session"
40
+ end
41
+ sample_pod_id
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'base'
2
+ require "shellwords"
3
+
4
+ module DeisInteractive
5
+ module Rails
6
+ class Logs < Base
7
+ attr_reader :follow
8
+
9
+ def initialize(app, process, follow: false)
10
+ super(app, process)
11
+ @follow = follow
12
+ end
13
+
14
+ def perform
15
+ if process.nil?
16
+ puts "Logging on all pods"
17
+ else
18
+ puts "Logging on pod of process #{process}"
19
+ end
20
+
21
+ log_pods
22
+ end
23
+
24
+ def kube_options
25
+ if follow
26
+ "-f"
27
+ end
28
+ end
29
+
30
+ def log_pods
31
+ pod_ids.each do |pod_id|
32
+ log_pod(pod_id)
33
+ end
34
+ end
35
+
36
+ def log_pod(pod_id)
37
+ fork do
38
+ exec "kubectl logs #{kube_options} #{pod_id} --namespace #{app}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module DeisInteractive
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deis-interactive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phuong Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-30 00:00:00.000000000 Z
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,10 @@ files:
52
52
  - README.md
53
53
  - bin/deis-rails
54
54
  - deis-interactive.gemspec
55
+ - lib/deis-interactive/rails/base.rb
56
+ - lib/deis-interactive/rails/console.rb
57
+ - lib/deis-interactive/rails/exec.rb
58
+ - lib/deis-interactive/rails/logs.rb
55
59
  - lib/deis-interactive/version.rb
56
60
  homepage: https://github.com/phuongnd08/deis-interactive
57
61
  licenses:
@@ -73,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
77
  version: '0'
74
78
  requirements: []
75
79
  rubyforge_project:
76
- rubygems_version: 2.6.11
80
+ rubygems_version: 2.4.5.3
77
81
  signing_key:
78
82
  specification_version: 4
79
83
  summary: Wrapper for kubectl to quickly launch console to a deis app