docker_rails_proxy 0.1.16 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8282c9ba08244394394df207bd38bd75332699cb68966f3e4e92feab3e63a4de
4
- data.tar.gz: 2ae4f4bdefba0e1ca762968dc32e99f10fc6e5bf33d0425d0fbe736699682e2d
3
+ metadata.gz: a5819c64cc069f6c72b3bc21c5aaeab20d328ff6d52fd55d4563f7ecb10ede4d
4
+ data.tar.gz: 5ca639cd06e1b88e618b2a877db695609e91aecfaecdb8dbc91e2ca2c735ed2e
5
5
  SHA512:
6
- metadata.gz: e490b98391af24d96d7cc791fb4305322da17e378c83f76c6fc3a465c0f4c07c3910bffc78346a76844401a3efd1f9365b9dbf21eca7bcb527ffd4d724e26d04
7
- data.tar.gz: 8fb03b2ab38190e2e95887dac8069f25e414f9413d1ac236db248d2b58e9403e876d44cf8d172478dde8976789a039a6f03c16ca45e5a31bbba8b3f39f319142
6
+ metadata.gz: 4dd69e7851a48e3b577a13f6514f41f750396370908118fe02f4e1fac613b6992d51c696e5dc32e7444f94cd5dc5188925b1618f078c408da7eb5611a1491f8d
7
+ data.tar.gz: 02da3a720928ffccb54bfc7331c27a72bed11c9e5c07c627ec701f08929e02c487871a2b91c0b5a7672261705271fb74d391788e766a6fae054fc160b855aa8d
@@ -51,7 +51,7 @@ module DockerRailsProxy
51
51
  seed if from_scratch?
52
52
  end
53
53
 
54
- private
54
+ private
55
55
 
56
56
  def seed
57
57
  logger.info "Seeding #{APP_NAME} data"
@@ -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 kubectl_output("get pod #{pod} -o json")
12
+ self.data = JSON.parse(
13
+ kubectl_output("get pod #{cloned_pod_name} -o json")
14
+ )
10
15
  end
11
16
 
12
- def process
13
- %w[livenessProbe readinessProbe command lifecycle].each do |attr|
14
- container.delete attr
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: '100m',
41
- memory: '300Mi',
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 <<-EOS
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
- EOS
61
+ RUN_COMMAND
58
62
  end
59
63
 
60
- private
64
+ private
61
65
 
62
- def pod
63
- @pod_name ||= begin
64
- pods = kubectl_output(<<-EOS).split(" ")
65
- get pods -o jsonpath='{range .items[*]}{.metadata.name},{.status.phase}{" "}{end}'}
66
- EOS
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 == 'Running' ? name : nil
74
+ ACCEPTED_STATUSES.include?(phase) ? name : nil
71
75
  end.compact
72
76
 
73
- until_get_option pods, "Choose a pod and press [ENTER]"
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{|c| c['name'] }
83
- name = until_get_option names, "Choose a container and press [ENTER]"
84
- containers.detect{|c| c['name'] == name }
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? KUBECONFIG_PATH
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 -> (params:) do
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
- private
33
+ private
34
34
 
35
35
  def kubectl(command)
36
- exec "kubectl --kubeconfig='#{KUBECONFIG_PATH}' #{command}"
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
- private
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, *rest) { resource.send(callback, *rest) }
53
+ ->(resource, *args, **kw_args) { resource.send(callback, *args, **kw_args) }
54
54
  when ::Proc
55
- if callback.arity <= 0
56
- ->(resource) { resource.instance_exec(&callback) }
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
- result = send "sync_#{volume}", {
71
- source: source, target: target, reverse: options[:reverse]
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}"
@@ -1,3 +1,3 @@
1
1
  module DockerRailsProxy
2
- VERSION = '0.1.16'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -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.1.16
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-03-12 00:00:00.000000000 Z
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.1.4
79
+ rubygems_version: 3.2.17
79
80
  signing_key:
80
81
  specification_version: 4
81
82
  summary: docker, docker-compose and rails wrapper