docker_rails_proxy 0.1.15 → 0.1.16

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: 11cc5b5ffa094628db0143b27de25323c7c6e610ff51f3bc3cfd308c0d944e0e
4
- data.tar.gz: c151d104cbc5835d2afa116c667eee6241ff728d7fb66df49b4a80ad34b07473
3
+ metadata.gz: 8282c9ba08244394394df207bd38bd75332699cb68966f3e4e92feab3e63a4de
4
+ data.tar.gz: 2ae4f4bdefba0e1ca762968dc32e99f10fc6e5bf33d0425d0fbe736699682e2d
5
5
  SHA512:
6
- metadata.gz: 7177b8ff7a8918bb156065c3e5832269d70cccf1b8575544b06e455e085e6b0d77743d07fdd84e00ec55f1b6dc00cd7ae308c65080e588c5484a76293b1dc387
7
- data.tar.gz: 83ab38f68fef1981fb682dd57e2f4cb7063a143017e322bc57fb6431affda117cecf52c8cca23b73fe8c8b9066282b3e79583325bd68eeca639596b41d757a3c
6
+ metadata.gz: e490b98391af24d96d7cc791fb4305322da17e378c83f76c6fc3a465c0f4c07c3910bffc78346a76844401a3efd1f9365b9dbf21eca7bcb527ffd4d724e26d04
7
+ data.tar.gz: 8fb03b2ab38190e2e95887dac8069f25e414f9413d1ac236db248d2b58e9403e876d44cf8d172478dde8976789a039a6f03c16ca45e5a31bbba8b3f39f319142
@@ -1,3 +1,5 @@
1
+ require 'optparse'
2
+
1
3
  Dir[File.expand_path('../docker_rails_proxy/extends/*.rb', __FILE__)].map do |f|
2
4
  require f
3
5
  end
@@ -27,7 +29,14 @@ module DockerRailsProxy
27
29
  include Rsync
28
30
  include Logger
29
31
 
30
- attr_reader :arguments, :additional_arguments
32
+ attr_accessor :additional_arguments_options
33
+ attr_reader :arguments, :additional_arguments
34
+
35
+ after_initialize { self.additional_arguments_options = {} }
36
+ after_initialize { additional_arguments_parser.parse!(additional_arguments) }
37
+ after_initialize do
38
+ DockerRailsProxy.log_level(level: additional_arguments_options[:debug])
39
+ end
31
40
 
32
41
  def initialize(arguments:, additional_arguments:)
33
42
  @arguments = arguments
@@ -71,7 +80,7 @@ module DockerRailsProxy
71
80
  raise NotImplementedError, 'Subclasses must implement a process method'
72
81
  end
73
82
 
74
- private
83
+ private
75
84
 
76
85
  def build_path(*args, &block)
77
86
  self.class.build_path(*args, &block)
@@ -84,16 +93,16 @@ module DockerRailsProxy
84
93
 
85
94
  def get_option(values, default: nil, array: false)
86
95
  flush_stdin
87
- print ": "
96
+ print ': '
88
97
  option = $stdin.gets.chomp
89
98
 
90
99
  return default if option.blank?
91
100
 
92
101
  if array
93
102
  options = option.split(',')
94
- return nil unless options.map{|o| o =~ NUMBER_REGEXP }.all?
103
+ return unless options.all? { |o| o =~ NUMBER_REGEXP }
95
104
 
96
- options.map{|o| values[o.to_i].split(',') }.flatten.compact.uniq.join(',')
105
+ options.map { |o| values[o.to_i].split(',') }.flatten.compact.uniq.join(',')
97
106
  else
98
107
  values[option.to_i] if option =~ NUMBER_REGEXP
99
108
  end
@@ -115,6 +124,23 @@ module DockerRailsProxy
115
124
  Timeout::timeout(0.1) { $stdin.gets.chomp } rescue break
116
125
  end
117
126
  end
127
+
128
+ def additional_arguments_parser
129
+ @additional_arguments_parser ||= OptionParser.new do |opts|
130
+ opts.banner = "Usage: bin/#{APP_NAME} #{self.class.name.demodulize.parameterize} [<arguments>] -- [<additional_arguments>]".bold
131
+
132
+ opts.on('--debug', 'Debug mode') do |debug|
133
+ additional_arguments_options[:debug] = ::Logger::DEBUG
134
+ end
135
+
136
+ yield opts if block_given?
137
+
138
+ opts.on('-h', '--help', 'Display this screen') do
139
+ puts opts
140
+ exit
141
+ end
142
+ end
143
+ end
118
144
  end
119
145
 
120
146
  class AwsCli < Base
@@ -169,10 +195,9 @@ module DockerRailsProxy
169
195
  end
170
196
 
171
197
  after_initialize { self.docker_options = {} }
172
- after_initialize { docker_arguments_parser.parse!(additional_arguments) }
173
198
  after_initialize :set_app_container_id
174
199
 
175
- private
200
+ private
176
201
 
177
202
  def docker_compose?
178
203
  !!Docker.kubernetes_running == false
@@ -216,32 +241,23 @@ module DockerRailsProxy
216
241
  replace_process ? exec(command) : system(command)
217
242
  end
218
243
 
219
- def docker_arguments_parser
220
- @docker_arguments_parser ||= OptionParser.new do |opts|
221
- opts.banner = "Usage: bin/#{APP_NAME} #{self.class.name.demodulize.parameterize} -- [<docker exec arguments>]".bold
222
-
223
- opts.on('-w', '--workdir WORKDIR', 'Working directory inside the container') do |workdir|
244
+ def additional_arguments_parser
245
+ super do |opts|
246
+ opts.on('--docker-workdir WORKDIR', 'Working directory inside the container') do |workdir|
224
247
  docker_options['-w'] = workdir
225
248
  end
226
249
 
227
- opts.on('-u', '--user USER', 'Username or UID (format: <name|uid>[:<group|gid>])') do |user|
250
+ opts.on('--docker-user USER', 'Username or UID (format: <name|uid>[:<group|gid>])') do |user|
228
251
  docker_options['-u'] = user
229
252
  end
230
253
 
231
- opts.on('-t', '--tty', 'Allocate a pseudo-TTY') do |tty|
254
+ opts.on('--docker-tty', 'Allocate a pseudo-TTY') do |tty|
232
255
  docker_options['-t'] = nil
233
256
  end
234
257
 
235
- opts.on('-i', '--interactive', 'Keep STDIN open even if not attached') do |interactive|
258
+ opts.on('--docker-interactive', 'Keep STDIN open even if not attached') do |interactive|
236
259
  docker_options['-i'] = nil
237
260
  end
238
-
239
- yield opts if block_given?
240
-
241
- opts.on('-h', '--help', 'Display this screen') do
242
- puts opts
243
- exit
244
- end
245
261
  end
246
262
  end
247
263
  end
@@ -2,8 +2,8 @@ module DockerRailsProxy
2
2
  class Cli
3
3
  class << self
4
4
  def invoke(arguments)
5
- command, *all_arguments = arguments
6
- arguments, additional_arguments = split_arguments(all_arguments)
5
+ command, *all_arguments = arguments
6
+ arguments, additional_arguments = split_arguments(all_arguments)
7
7
 
8
8
  if command.nil?
9
9
  $stderr.puts <<-EOF
@@ -16,7 +16,7 @@ module DockerRailsProxy
16
16
 
17
17
  if COMMANDS.include? command
18
18
  arguments << '-h' if arguments.empty?
19
- "DockerRailsProxy::#{command}".constantize.(
19
+ "DockerRailsProxy::#{command}".constantize.call(
20
20
  arguments: arguments, additional_arguments: additional_arguments
21
21
  )
22
22
  else
@@ -39,16 +39,10 @@ module DockerRailsProxy
39
39
  private
40
40
 
41
41
  def split_arguments(arguments)
42
- arguments = arguments.join(' ') if arguments.is_a?(Array)
43
- arguments, additional_arguments = arguments.split(' -- ')
44
- [parse_arguments(arguments), parse_arguments(additional_arguments)]
45
- end
42
+ return [arguments, []] unless (separator_index = arguments.index('--'))
46
43
 
47
- def parse_arguments(arguments)
48
- arguments.to_s.split(/\ -/).each_with_index.map do |argument, index|
49
- argument = "-#{argument}" unless index.zero?
50
- argument.match(/([^ ]+)\s*(.*)/m).captures.reject(&:blank?)
51
- end.compact.flatten
44
+ arguments.delete_at(separator_index)
45
+ arguments.partition.with_index { |_, index| index < separator_index }
52
46
  end
53
47
  end
54
48
  end
@@ -1,5 +1,3 @@
1
- require 'optparse'
2
-
3
1
  module DockerRailsProxy
4
2
  class Build < Docker
5
3
  attr_accessor :options
@@ -1,5 +1,4 @@
1
1
  require 'pty'
2
- require 'optparse'
3
2
 
4
3
  module DockerRailsProxy
5
4
  class Compose < Docker
@@ -1,5 +1,3 @@
1
- require 'optparse'
2
-
3
1
  module DockerRailsProxy
4
2
  class DataBags < AwsCli
5
3
  autoload :Pull, 'docker_rails_proxy/commands/data_bags/pull'
@@ -1,5 +1,3 @@
1
- require 'optparse'
2
-
3
1
  module DockerRailsProxy
4
2
  class Kubectl < Base
5
3
  autoload :Bash, 'docker_rails_proxy/commands/kubectl/bash'
@@ -1,4 +1,3 @@
1
- require 'optparse'
2
1
  require 'json'
3
2
 
4
3
  module DockerRailsProxy
@@ -1,5 +1,4 @@
1
1
  require 'fileutils'
2
- require 'optparse'
3
2
  require 'yaml'
4
3
 
5
4
  module DockerRailsProxy
@@ -1,5 +1,3 @@
1
- require 'optparse'
2
-
3
1
  module DockerRailsProxy
4
2
  class Ssh < DockerMainApp
5
3
  def process
@@ -1,5 +1,3 @@
1
- require 'optparse'
2
-
3
1
  module DockerRailsProxy
4
2
  class Stack < AwsCli
5
3
  autoload :Create, 'docker_rails_proxy/commands/stack/create'
@@ -1,6 +1,18 @@
1
1
  require 'logger'
2
2
 
3
3
  module DockerRailsProxy
4
+ def self.logger
5
+ @logger ||= ::Logger.new(STDOUT).tap do |log|
6
+ log.formatter = proc do |severity, datetime, progname, msg|
7
+ "#{severity[0]}, [#{datetime.strftime('%Y-%m-%d %T')}] -- : #{msg}\n"
8
+ end
9
+ end
10
+ end
11
+
12
+ def self.log_level(level: nil)
13
+ logger.level = level || ::Logger::INFO
14
+ end
15
+
4
16
  module Logger
5
17
  class << self
6
18
  def included(base)
@@ -10,16 +22,12 @@ module DockerRailsProxy
10
22
 
11
23
  module ClassMethods
12
24
  def logger
13
- @logger ||= ::Logger.new(STDOUT).tap do |log|
14
- log.formatter = proc do |severity, datetime, progname, msg|
15
- "#{severity[0]}, [#{datetime.strftime('%Y-%m-%d %T')}] -- : #{msg}\n"
16
- end
17
- end
25
+ ::DockerRailsProxy.logger
18
26
  end
19
27
  end
20
28
 
21
29
  def logger
22
- self.class.logger
30
+ ::DockerRailsProxy.logger
23
31
  end
24
32
  end
25
33
  end
@@ -31,7 +31,7 @@ module DockerRailsProxy
31
31
  _rsync.sync source: source, reverse: reverse, silent: silent
32
32
  end
33
33
 
34
- private
34
+ private
35
35
 
36
36
  def _rsync_host
37
37
  @_rsync_host ||= begin
@@ -72,7 +72,7 @@ module DockerRailsProxy
72
72
  }
73
73
 
74
74
  if result && options[:silent].eql?(false)
75
- puts "#{source} =======> #{target}"
75
+ DockerRailsProxy.logger.info "#{source} =======> #{target}"
76
76
  end
77
77
 
78
78
  result
@@ -1,3 +1,3 @@
1
1
  module DockerRailsProxy
2
- VERSION = '0.1.15'
2
+ VERSION = '0.1.16'
3
3
  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.1.15
4
+ version: 0.1.16
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-01-21 00:00:00.000000000 Z
12
+ date: 2021-03-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Configures docker-compose and provides rails command helpers
15
15
  email:
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.0.3
78
+ rubygems_version: 3.1.4
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: docker, docker-compose and rails wrapper