docker_rails_proxy 0.0.10 → 0.0.12
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.
- checksums.yaml +4 -4
- data/lib/docker_rails_proxy.rb +11 -0
- data/lib/docker_rails_proxy/commands/kubectl.rb +45 -0
- data/lib/docker_rails_proxy/commands/kubectl/bash.rb +77 -0
- data/lib/docker_rails_proxy/commands/kubectl/set_kubeconfig.rb +70 -0
- data/lib/docker_rails_proxy/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3a12d0b5a75064d9d2536c11ccd90898c8d88f6
|
4
|
+
data.tar.gz: 279c5c537357f88c68cad0dd49ba48d7b2b224d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d9e1bbfb5714a48d34b7b42846677db5b5278876b066a4289fa465b1d2a3baa465e6743700078f43a39641fea4943aca27bb6c8ccc6d9fc0b55a004929c04be
|
7
|
+
data.tar.gz: d59f6de86cc746002b3f59a9bfcf3d4d4ddaf0aebae75f8e8bbc4018f81c0c6de70b2da1a864853f5de1702c33092a4cdcaf25e4e4f8e0009eec161e769e386c
|
data/lib/docker_rails_proxy.rb
CHANGED
@@ -98,6 +98,17 @@ module DockerRailsProxy
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
def until_get_option(values, message, options = {})
|
102
|
+
value = nil
|
103
|
+
|
104
|
+
while value.nil? do
|
105
|
+
print_options(values, message)
|
106
|
+
value = get_option(values, options)
|
107
|
+
end
|
108
|
+
|
109
|
+
value
|
110
|
+
end
|
111
|
+
|
101
112
|
def flush_stdin
|
102
113
|
loop do
|
103
114
|
Timeout::timeout(0.1) { $stdin.gets.chomp } rescue break
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module DockerRailsProxy
|
4
|
+
class Kubectl < Base
|
5
|
+
autoload :Bash, 'docker_rails_proxy/commands/kubectl/bash'
|
6
|
+
autoload :SetKubeconfig, 'docker_rails_proxy/commands/kubectl/set_kubeconfig'
|
7
|
+
|
8
|
+
KUBECONFIG_PATH = build_path('tmp/.kube/kubeconfig')
|
9
|
+
|
10
|
+
before_initialize do
|
11
|
+
'kubectl is required, `brew install kubectl`' unless system 'type kubectl &> /dev/null'
|
12
|
+
end
|
13
|
+
|
14
|
+
validates do
|
15
|
+
unless File.exist? KUBECONFIG_PATH
|
16
|
+
<<-EOS
|
17
|
+
|
18
|
+
kubeconfig is required, run this command to set it
|
19
|
+
`bin/#{APP_NAME} kubectl set-kubeconfig --path /path/kubeconfig`
|
20
|
+
EOS
|
21
|
+
end unless arguments.first == 'set-kubeconfig'
|
22
|
+
end
|
23
|
+
|
24
|
+
builds -> (params:) do
|
25
|
+
case params[:arguments].first
|
26
|
+
when 'bash' then Bash
|
27
|
+
when 'set-kubeconfig' then SetKubeconfig
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def process
|
32
|
+
kubectl arguments.join(' ')
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def kubectl(command)
|
38
|
+
exec "kubectl --kubeconfig='#{KUBECONFIG_PATH}' #{command}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def kubectl_output(command)
|
42
|
+
%x(kubectl --kubeconfig='#{KUBECONFIG_PATH}' #{command}).strip
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module DockerRailsProxy
|
5
|
+
class Kubectl < Base
|
6
|
+
class Bash < self
|
7
|
+
attr_accessor :data
|
8
|
+
|
9
|
+
before_process do
|
10
|
+
self.data = JSON.parse kubectl_output("get #{pod} -o json")
|
11
|
+
end
|
12
|
+
|
13
|
+
def process
|
14
|
+
%w[livenessProbe readinessProbe command].each do |attr|
|
15
|
+
container.delete attr
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
overrides = {
|
20
|
+
metadata: {
|
21
|
+
annotations: {
|
22
|
+
'iam.amazonaws.com/role' => data.dig('metadata', 'annotations', 'iam.amazonaws.com/role')
|
23
|
+
}
|
24
|
+
},
|
25
|
+
spec: {
|
26
|
+
volumes: data.dig('spec', 'volumes'),
|
27
|
+
imagePullSecrets: data.dig('spec', 'imagePullSecrets'),
|
28
|
+
securityContext: data.dig('spec', 'securityContext'),
|
29
|
+
serviceAccount: data.dig('spec', 'serviceAccount'),
|
30
|
+
serviceAccountName: data.dig('spec', 'serviceAccountName'),
|
31
|
+
containers: [
|
32
|
+
container.merge!({
|
33
|
+
args: %w[bash],
|
34
|
+
stdin: true,
|
35
|
+
stdinOnce: true,
|
36
|
+
tty: true
|
37
|
+
})
|
38
|
+
]
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
pod_name = "#{container['name']}-bash-#{Time.now.to_i}"
|
43
|
+
puts "Starting #{pod_name} pod ..."
|
44
|
+
|
45
|
+
kubectl <<-EOS
|
46
|
+
run #{pod_name} --rm -i --tty \
|
47
|
+
--image='#{container['image']}' \
|
48
|
+
--generator='run-pod/v1' \
|
49
|
+
--overrides='#{overrides.to_json}'
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def pod
|
56
|
+
@pod_name ||= begin
|
57
|
+
pods = kubectl_output('get pods -o name').split(' ')
|
58
|
+
until_get_option pods, "Choose a pod and press [ENTER]"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def container
|
63
|
+
@container ||= begin
|
64
|
+
containers = data.dig('spec', 'containers')
|
65
|
+
|
66
|
+
if containers.size > 1
|
67
|
+
names = containers.map{|c| c['name'] }
|
68
|
+
name = until_get_option names, "Choose a container and press [ENTER]"
|
69
|
+
containers.detect{|c| c['name'] == name }
|
70
|
+
else
|
71
|
+
containers.first
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module DockerRailsProxy
|
5
|
+
class Kubectl < Base
|
6
|
+
class SetKubeconfig < self
|
7
|
+
attr_accessor :options, :data
|
8
|
+
|
9
|
+
after_initialize { self.options = {} }
|
10
|
+
after_initialize { opt_parser.parse!(arguments) }
|
11
|
+
|
12
|
+
validates do
|
13
|
+
if options[:path].nil?
|
14
|
+
'--path is required'
|
15
|
+
elsif !File.exist?(options[:path])
|
16
|
+
"#{options[:path]} kubeconfig does not exist."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
validates do
|
21
|
+
self.data = YAML.load_file(options[:path])
|
22
|
+
|
23
|
+
unless (data['kind'] == 'Config')
|
24
|
+
"#{options[:path]} is not a valid kubeconfig file"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
before_process do
|
29
|
+
Dir.mkdir('tmp/.kube') unless Dir.exist?('tmp/.kube')
|
30
|
+
|
31
|
+
absolute_dir = File.dirname(options[:path])
|
32
|
+
|
33
|
+
data['clusters'].each do |hash|
|
34
|
+
cluster = hash['cluster']
|
35
|
+
cluster['certificate-authority'] = File.absolute_path(cluster['certificate-authority'], absolute_dir)
|
36
|
+
end
|
37
|
+
|
38
|
+
data['users'].each do |hash|
|
39
|
+
user = hash['user']
|
40
|
+
user['client-certificate'] = File.absolute_path(user['client-certificate'], absolute_dir)
|
41
|
+
user['client-key'] = File.absolute_path(user['client-key'], absolute_dir)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def process
|
46
|
+
File.write(KUBECONFIG_PATH, data.to_yaml)
|
47
|
+
puts 'kubeconfig was set correctly'
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def opt_parser
|
53
|
+
@opt_parser ||= OptionParser.new do |opts|
|
54
|
+
opts.banner = "Usage: bin/#{APP_NAME} kubectl #{self.class.name.demodulize.parameterize} [options]"
|
55
|
+
|
56
|
+
opts.on('--path PATH', 'kubeconfig file path') do |path|
|
57
|
+
options[:path] = path
|
58
|
+
end
|
59
|
+
|
60
|
+
yield opts if block_given?
|
61
|
+
|
62
|
+
opts.on('-h', '--help', 'Display this screen') do
|
63
|
+
puts opts
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker_rails_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jairo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Configures docker-compose and provides rails command helpers
|
15
15
|
email:
|
@@ -33,6 +33,9 @@ files:
|
|
33
33
|
- lib/docker_rails_proxy/commands/data_bags.rb
|
34
34
|
- lib/docker_rails_proxy/commands/data_bags/pull.rb
|
35
35
|
- lib/docker_rails_proxy/commands/data_bags/push.rb
|
36
|
+
- lib/docker_rails_proxy/commands/kubectl.rb
|
37
|
+
- lib/docker_rails_proxy/commands/kubectl/bash.rb
|
38
|
+
- lib/docker_rails_proxy/commands/kubectl/set_kubeconfig.rb
|
36
39
|
- lib/docker_rails_proxy/commands/rails.rb
|
37
40
|
- lib/docker_rails_proxy/commands/rake.rb
|
38
41
|
- lib/docker_rails_proxy/commands/rspec.rb
|