docker_rails_proxy 0.1.16 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docker_rails_proxy/commands/compose/up.rb +1 -1
- data/lib/docker_rails_proxy/commands/kubectl/bash.rb +25 -21
- data/lib/docker_rails_proxy/commands/kubectl.rb +6 -4
- data/lib/docker_rails_proxy/commands/rails/credentials.rb +34 -0
- data/lib/docker_rails_proxy/commands/rails.rb +11 -9
- data/lib/docker_rails_proxy/concerns/callbacks.rb +3 -11
- data/lib/docker_rails_proxy/concerns/rsync.rb +6 -5
- data/lib/docker_rails_proxy/version.rb +1 -1
- data/lib/docker_rails_proxy.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5819c64cc069f6c72b3bc21c5aaeab20d328ff6d52fd55d4563f7ecb10ede4d
|
4
|
+
data.tar.gz: 5ca639cd06e1b88e618b2a877db695609e91aecfaecdb8dbc91e2ca2c735ed2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dd69e7851a48e3b577a13f6514f41f750396370908118fe02f4e1fac613b6992d51c696e5dc32e7444f94cd5dc5188925b1618f078c408da7eb5611a1491f8d
|
7
|
+
data.tar.gz: 02da3a720928ffccb54bfc7331c27a72bed11c9e5c07c627ec701f08929e02c487871a2b91c0b5a7672261705271fb74d391788e766a6fae054fc160b855aa8d
|
@@ -3,17 +3,22 @@ require 'json'
|
|
3
3
|
module DockerRailsProxy
|
4
4
|
class Kubectl < Base
|
5
5
|
class Bash < self
|
6
|
+
UNNEEDED_ATTRIBUTES = %w[livenessProbe readinessProbe command lifecycle].freeze
|
7
|
+
ACCEPTED_STATUSES = %w[Running Failed].freeze
|
8
|
+
|
6
9
|
attr_accessor :data
|
7
10
|
|
8
11
|
before_process do
|
9
|
-
self.data = JSON.parse
|
12
|
+
self.data = JSON.parse(
|
13
|
+
kubectl_output("get pod #{cloned_pod_name} -o json")
|
14
|
+
)
|
10
15
|
end
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
17
|
+
before_process do
|
18
|
+
UNNEEDED_ATTRIBUTES.each { |attribute| container.delete(attribute) }
|
19
|
+
end
|
16
20
|
|
21
|
+
def process
|
17
22
|
overrides = {
|
18
23
|
metadata: {
|
19
24
|
annotations: {
|
@@ -37,8 +42,8 @@ module DockerRailsProxy
|
|
37
42
|
tty: true,
|
38
43
|
resources: {
|
39
44
|
requests: {
|
40
|
-
cpu: '
|
41
|
-
memory: '
|
45
|
+
cpu: '250m',
|
46
|
+
memory: '500Mi',
|
42
47
|
}
|
43
48
|
}
|
44
49
|
})
|
@@ -49,28 +54,27 @@ module DockerRailsProxy
|
|
49
54
|
pod_name = "#{container['name']}-bash-#{Time.now.strftime '%Y%m%d%H%M%S'}"
|
50
55
|
puts "Starting #{pod_name} pod ..."
|
51
56
|
|
52
|
-
kubectl <<-
|
57
|
+
kubectl <<-RUN_COMMAND
|
53
58
|
run #{pod_name} --rm -i --tty \
|
54
59
|
--image='#{container['image']}' \
|
55
|
-
--generator='run-pod/v1' \
|
56
60
|
--overrides='#{overrides.to_json}'
|
57
|
-
|
61
|
+
RUN_COMMAND
|
58
62
|
end
|
59
63
|
|
60
|
-
|
64
|
+
private
|
61
65
|
|
62
|
-
def
|
63
|
-
@
|
64
|
-
pods = kubectl_output(<<-
|
65
|
-
get pods -o jsonpath='{range .items[*]}{.metadata.name},{.status.phase}{" "}{end}'
|
66
|
-
|
66
|
+
def cloned_pod_name
|
67
|
+
@cloned_pod_name ||= begin
|
68
|
+
pods = kubectl_output(<<-GET_PODS).split(" ")
|
69
|
+
get pods -o jsonpath='{range .items[*]}{.metadata.name},{.status.phase}{" "}{end}'
|
70
|
+
GET_PODS
|
67
71
|
|
68
72
|
pods = pods.map do |values|
|
69
73
|
name, phase = values.split(',')
|
70
|
-
phase
|
74
|
+
ACCEPTED_STATUSES.include?(phase) ? name : nil
|
71
75
|
end.compact
|
72
76
|
|
73
|
-
until_get_option
|
77
|
+
until_get_option(pods, "Choose a pod and press [ENTER]")
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
@@ -79,9 +83,9 @@ module DockerRailsProxy
|
|
79
83
|
containers = data.dig('spec', 'containers')
|
80
84
|
|
81
85
|
if containers.size > 1
|
82
|
-
names = containers.map{|
|
83
|
-
name = until_get_option
|
84
|
-
containers.
|
86
|
+
names = containers.map { |container| container['name'] }
|
87
|
+
name = until_get_option(names, "Choose a container and press [ENTER]")
|
88
|
+
containers.find { |container| container['name'] == name }
|
85
89
|
else
|
86
90
|
containers.first
|
87
91
|
end
|
@@ -10,7 +10,7 @@ module DockerRailsProxy
|
|
10
10
|
end
|
11
11
|
|
12
12
|
validates do
|
13
|
-
unless File.exist?
|
13
|
+
unless File.exist?(KUBECONFIG_PATH)
|
14
14
|
<<-EOS
|
15
15
|
|
16
16
|
kubeconfig is required, run this command to set it
|
@@ -19,7 +19,7 @@ module DockerRailsProxy
|
|
19
19
|
end unless arguments.first == 'set-kubeconfig'
|
20
20
|
end
|
21
21
|
|
22
|
-
builds ->
|
22
|
+
builds ->(params:) do
|
23
23
|
case params[:arguments].first
|
24
24
|
when 'bash' then Bash
|
25
25
|
when 'set-kubeconfig' then SetKubeconfig
|
@@ -30,10 +30,12 @@ module DockerRailsProxy
|
|
30
30
|
kubectl arguments.join(' ')
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
private
|
34
34
|
|
35
35
|
def kubectl(command)
|
36
|
-
|
36
|
+
cmd = "kubectl --kubeconfig='#{KUBECONFIG_PATH}' #{command}"
|
37
|
+
cmd << " -- #{additional_arguments.join(', ')}" unless additional_arguments.empty?
|
38
|
+
exec cmd
|
37
39
|
end
|
38
40
|
|
39
41
|
def kubectl_output(command)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module DockerRailsProxy
|
2
|
+
class Rails < SyncBack
|
3
|
+
class Credentials < self
|
4
|
+
attr_accessor :options
|
5
|
+
|
6
|
+
after_initialize { self.options = {} }
|
7
|
+
after_initialize { opt_parser.parse!(arguments) }
|
8
|
+
|
9
|
+
validates { '--environment is required' if options[:environment].nil? }
|
10
|
+
|
11
|
+
def process
|
12
|
+
command = "EDITOR=vim bin/rails credentials:edit --environment #{options[:environment]}"
|
13
|
+
execute "bash -c '#{command}'", tty: true
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def opt_parser
|
19
|
+
@opt_parser ||= OptionParser.new do |opts|
|
20
|
+
opts.banner = "Usage: bin/#{APP_NAME} rails credentials [options]"
|
21
|
+
|
22
|
+
opts.on(
|
23
|
+
'--environment ENVIRONMENT', 'App environment'
|
24
|
+
) { |environment| options[:environment] = environment }
|
25
|
+
|
26
|
+
opts.on('-h', '--help', 'Display this screen') do
|
27
|
+
puts opts
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -2,6 +2,16 @@ module DockerRailsProxy
|
|
2
2
|
class Rails < SyncBack
|
3
3
|
attr_reader :args
|
4
4
|
|
5
|
+
autoload :Credentials, 'docker_rails_proxy/commands/rails/credentials'
|
6
|
+
|
7
|
+
builds ->(params:) do
|
8
|
+
case params[:arguments].first
|
9
|
+
when 'credentials' then Credentials
|
10
|
+
else
|
11
|
+
DockerRailsProxy::Rails
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
def process
|
6
16
|
command, *@args = arguments
|
7
17
|
|
@@ -11,13 +21,12 @@ module DockerRailsProxy
|
|
11
21
|
when 'logs' then logs
|
12
22
|
when 'restart', 'touch' then restart
|
13
23
|
when 'secrets' then secrets
|
14
|
-
when 'credentials' then credentials
|
15
24
|
else
|
16
25
|
execute "bin/rails #{command} #{args.join(' ')}", tty: true
|
17
26
|
end
|
18
27
|
end
|
19
28
|
|
20
|
-
|
29
|
+
private
|
21
30
|
|
22
31
|
def console
|
23
32
|
execute "bin/rails c #{args.join(' ')}", tty: true, replace_process: true
|
@@ -50,12 +59,5 @@ module DockerRailsProxy
|
|
50
59
|
def secrets
|
51
60
|
execute "bash -c 'EDITOR=vim bin/rails secrets:edit'", tty: true
|
52
61
|
end
|
53
|
-
|
54
|
-
def credentials
|
55
|
-
# Temporary solution to use credentials in Rails 5.2
|
56
|
-
# Future version will use the --environment argument instead
|
57
|
-
command = "RAILS_ENV=#{args.first} EDITOR=vim bin/rails credentials:edit"
|
58
|
-
execute "bash -c '#{command}'", tty: true
|
59
|
-
end
|
60
62
|
end
|
61
63
|
end
|
@@ -50,18 +50,10 @@ module DockerRailsProxy
|
|
50
50
|
def _make_lambda(callback:)
|
51
51
|
case callback
|
52
52
|
when Symbol
|
53
|
-
->(resource, *
|
53
|
+
->(resource, *args, **kw_args) { resource.send(callback, *args, **kw_args) }
|
54
54
|
when ::Proc
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
->(resource, *rest) do
|
59
|
-
if rest.empty?
|
60
|
-
resource.instance_exec(resource, &callback)
|
61
|
-
else
|
62
|
-
resource.instance_exec(*rest, &callback)
|
63
|
-
end
|
64
|
-
end
|
55
|
+
lambda do |resource, *args, **kw_args|
|
56
|
+
resource.instance_exec(*args, **kw_args, &callback)
|
65
57
|
end
|
66
58
|
else
|
67
59
|
->(*) {}
|
@@ -64,12 +64,13 @@ module DockerRailsProxy
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def sync(options)
|
67
|
-
return if source_in_exclusions?(options)
|
68
|
-
source, target, volume = normalize_options(options)
|
67
|
+
return if source_in_exclusions?(**options)
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
source, target, volume = normalize_options(**options)
|
70
|
+
|
71
|
+
result = send(
|
72
|
+
"sync_#{volume}", source: source, target: target, reverse: options[:reverse]
|
73
|
+
)
|
73
74
|
|
74
75
|
if result && options[:silent].eql?(false)
|
75
76
|
DockerRailsProxy.logger.info "#{source} =======> #{target}"
|
data/lib/docker_rails_proxy.rb
CHANGED
@@ -61,7 +61,7 @@ module DockerRailsProxy
|
|
61
61
|
|
62
62
|
klass.send :_run_before_initialize_callbacks
|
63
63
|
|
64
|
-
resource = klass.new(options)
|
64
|
+
resource = klass.new(**options)
|
65
65
|
|
66
66
|
klass.send :_run_after_initialize_callbacks, resource: resource
|
67
67
|
|
@@ -113,7 +113,7 @@ module DockerRailsProxy
|
|
113
113
|
|
114
114
|
while value.nil? do
|
115
115
|
print_options(values, message)
|
116
|
-
value = get_option(values, options)
|
116
|
+
value = get_option(values, **options)
|
117
117
|
end
|
118
118
|
|
119
119
|
value
|
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.
|
4
|
+
version: 0.2.3
|
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: 2021-
|
12
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Configures docker-compose and provides rails command helpers
|
15
15
|
email:
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/docker_rails_proxy/commands/kubectl/bash.rb
|
38
38
|
- lib/docker_rails_proxy/commands/kubectl/set_kubeconfig.rb
|
39
39
|
- lib/docker_rails_proxy/commands/rails.rb
|
40
|
+
- lib/docker_rails_proxy/commands/rails/credentials.rb
|
40
41
|
- lib/docker_rails_proxy/commands/rake.rb
|
41
42
|
- lib/docker_rails_proxy/commands/rspec.rb
|
42
43
|
- lib/docker_rails_proxy/commands/spring.rb
|
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
76
|
- !ruby/object:Gem::Version
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.2.17
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
82
|
summary: docker, docker-compose and rails wrapper
|