docker_rails_proxy 0.2 → 0.2.4

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
  SHA256:
3
- metadata.gz: 560e55ef710ff5dd7ca014076a8f0d901392e9f6f6a4d9f90bff13afe508c8ae
4
- data.tar.gz: 6797397a319714e456ecd65452f930ede67355a361c34b5cd57d688d2617105a
3
+ metadata.gz: 873a065cab149074c38e094de0a69f8c7950c1e3a91d6caf7a4caee810e926a7
4
+ data.tar.gz: c03370b0ae15790291cbd9ac9fd3f00290f181c2ad78aab345bce9a613104498
5
5
  SHA512:
6
- metadata.gz: 45dc24ae60670e8cd95d128aea8e6dfc9583060e27f7c1158dc4047150620db549790ec243f30543afbf38af0327b0bc960d7a9f7efb63cc862985fa2f3625e6
7
- data.tar.gz: 8e9c17b1182e1e59032ac550199fef05f80535c4f2275afc51f2d7aebee06597cf9cdf8c5ce5c6478edabfe7c25fed64a4c4a50afafee9b9adedb5bea053c2f6
6
+ metadata.gz: 1bba82f568174c4337fbadc1bc56326ec3d4d42a8845361838b171e9aad9faff53269fedb64e4ff88c99a0adeb23af890715799fb98708b415ae4c20d6630590
7
+ data.tar.gz: 8281e2ccd0a694134903cf80de6e40b9533dcb12549a7ed0194657a2649bfcdbceb1349fa8aac5f49784783ad61fb2790fbeab7da40dea8a1561ca3593e3511c
@@ -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
@@ -59,12 +59,5 @@ module DockerRailsProxy
59
59
  def secrets
60
60
  execute "bash -c 'EDITOR=vim bin/rails secrets:edit'", tty: true
61
61
  end
62
-
63
- def credentials
64
- # Temporary solution to use credentials in Rails 5.2
65
- # Future version will use the --environment argument instead
66
- command = "RAILS_ENV=#{args.first} EDITOR=vim bin/rails credentials:edit"
67
- execute "bash -c '#{command}'", tty: true
68
- end
69
62
  end
70
63
  end
@@ -36,7 +36,7 @@ module DockerRailsProxy
36
36
  def _rsync_host
37
37
  @_rsync_host ||= begin
38
38
  ip = ENV.fetch('DOCKER_HOST') { '127.0.0.1' }.to_s.sub('tcp://', '').sub(/:\d+$/, '')
39
- port = '10873'
39
+ port = ENV.fetch('RSYNC_PORT') { '10873' }
40
40
 
41
41
  loop do
42
42
  break if (port = %x(kubectl get svc "#{APP_NAME}" -o jsonpath='{.spec.ports[?(@.name=="rsync")].nodePort}' 2> /dev/null).strip).present?
@@ -1,3 +1,3 @@
1
1
  module DockerRailsProxy
2
- VERSION = '0.2'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -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.2'
4
+ version: 0.2.4
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-04-05 00:00:00.000000000 Z
12
+ date: 2022-02-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Configures docker-compose and provides rails command helpers
15
15
  email:
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.2.3
79
+ rubygems_version: 3.2.15
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: docker, docker-compose and rails wrapper