docker_rails_proxy 0.1.11 → 0.1.16

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: 79b3dcd393e5a9b60e7cfe3188671314011b44f802ad471c1267442d52dc878b
4
- data.tar.gz: fb97c5c91622fefb42a69e9a3bea41b6420be47647aa73a1de58db6ba5adb938
3
+ metadata.gz: 8282c9ba08244394394df207bd38bd75332699cb68966f3e4e92feab3e63a4de
4
+ data.tar.gz: 2ae4f4bdefba0e1ca762968dc32e99f10fc6e5bf33d0425d0fbe736699682e2d
5
5
  SHA512:
6
- metadata.gz: 31de2c5a3f1f54b8dacc4e75c19a08f82b19c0c0aef99a53a36f3df49be1c7f6ba8466b6bfaed881df3fcdfd943637fdd868948337d45e69b296b709f82e44ce
7
- data.tar.gz: 4e70215519f80cff3d7f5e84155dba08b37a4aa4ec205f9a155077f57a96b1e472e6906453e364c59862d6af450fb2ab1dc49fc3e008771a25d606c2fa4a6571
6
+ metadata.gz: e490b98391af24d96d7cc791fb4305322da17e378c83f76c6fc3a465c0f4c07c3910bffc78346a76844401a3efd1f9365b9dbf21eca7bcb527ffd4d724e26d04
7
+ data.tar.gz: 8fb03b2ab38190e2e95887dac8069f25e414f9413d1ac236db248d2b58e9403e876d44cf8d172478dde8976789a039a6f03c16ca45e5a31bbba8b3f39f319142
data/README.md CHANGED
@@ -1,6 +1,28 @@
1
1
  ### To release a new version
2
2
 
3
- Update `lib/docker_rails_proxy/version.rb` with the new version and commit that change.
3
+ **Test locally**
4
+
5
+ change the version on `lib/docker_rails_proxy/version.rb`
6
+
7
+ and build the gem
8
+
9
+ ```
10
+ gem build docker_rails_proxy.gemspec [ruby-2.6.3]
11
+ Successfully built RubyGem
12
+ Name: docker_rails_proxy
13
+ Version: 0.1.13
14
+ File: docker_rails_proxy-0.1.13.gem
15
+ ```
16
+
17
+ on the repo when you want to test, i.e `~/Projects/Eureka`
18
+
19
+ install the local gem
20
+
21
+ ```
22
+ gem install docker_rails_proxy -l ~/Projects/docker_rails_proxy/docker_rails_proxy-0.1.13.gem
23
+ ```
24
+
25
+ Once it's ready, create the tag and push
4
26
 
5
27
  **Git Tag**
6
28
  ```bash
@@ -12,6 +34,5 @@ git push origin v0.0.1
12
34
 
13
35
  The user on rubygems.org is eureaktechteam@gmail.com. Credentials are in 1password "Eureka Tech" vault
14
36
  ```bash
15
- gem build docker_rails_proxy.gemspec
16
37
  gem push docker_rails_proxy-0.0.1.gem
17
38
  ```
@@ -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,10 +29,18 @@ module DockerRailsProxy
27
29
  include Rsync
28
30
  include Logger
29
31
 
30
- attr_reader :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
- def initialize(arguments:)
33
- @arguments = arguments
41
+ def initialize(arguments:, additional_arguments:)
42
+ @arguments = arguments
43
+ @additional_arguments = additional_arguments
34
44
  end
35
45
 
36
46
  class << self
@@ -70,7 +80,7 @@ module DockerRailsProxy
70
80
  raise NotImplementedError, 'Subclasses must implement a process method'
71
81
  end
72
82
 
73
- private
83
+ private
74
84
 
75
85
  def build_path(*args, &block)
76
86
  self.class.build_path(*args, &block)
@@ -83,16 +93,16 @@ module DockerRailsProxy
83
93
 
84
94
  def get_option(values, default: nil, array: false)
85
95
  flush_stdin
86
- print ": "
96
+ print ': '
87
97
  option = $stdin.gets.chomp
88
98
 
89
99
  return default if option.blank?
90
100
 
91
101
  if array
92
102
  options = option.split(',')
93
- return nil unless options.map{|o| o =~ NUMBER_REGEXP }.all?
103
+ return unless options.all? { |o| o =~ NUMBER_REGEXP }
94
104
 
95
- 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(',')
96
106
  else
97
107
  values[option.to_i] if option =~ NUMBER_REGEXP
98
108
  end
@@ -114,6 +124,23 @@ module DockerRailsProxy
114
124
  Timeout::timeout(0.1) { $stdin.gets.chomp } rescue break
115
125
  end
116
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
117
144
  end
118
145
 
119
146
  class AwsCli < Base
@@ -129,7 +156,7 @@ module DockerRailsProxy
129
156
  attr_accessor :vm_provisioner, :kubernetes_running
130
157
  end
131
158
 
132
- attr_accessor :app_container_id
159
+ attr_accessor :app_container_id, :docker_options
133
160
 
134
161
  before_initialize do
135
162
  unless system 'type docker &> /dev/null'
@@ -167,9 +194,10 @@ module DockerRailsProxy
167
194
  end if Docker.kubernetes_running
168
195
  end
169
196
 
197
+ after_initialize { self.docker_options = {} }
170
198
  after_initialize :set_app_container_id
171
199
 
172
- private
200
+ private
173
201
 
174
202
  def docker_compose?
175
203
  !!Docker.kubernetes_running == false
@@ -199,17 +227,39 @@ module DockerRailsProxy
199
227
  tty: false,
200
228
  container_id: app_container_id,
201
229
  replace_process: false,
202
- user: nil,
203
230
  **)
204
231
 
205
- options = []
232
+ docker_options['-ti'] = nil if tty
206
233
 
207
- options << '-ti' if tty
208
- options << "-u #{user}" if user
234
+ command = [
235
+ 'docker exec',
236
+ docker_options.map { |key, value| [key, value].compact.join(' ') },
237
+ container_id,
238
+ command
239
+ ].join(' '.freeze)
209
240
 
210
- command = "docker exec #{options.join(' '.freeze)} #{container_id} #{command}"
211
241
  replace_process ? exec(command) : system(command)
212
242
  end
243
+
244
+ def additional_arguments_parser
245
+ super do |opts|
246
+ opts.on('--docker-workdir WORKDIR', 'Working directory inside the container') do |workdir|
247
+ docker_options['-w'] = workdir
248
+ end
249
+
250
+ opts.on('--docker-user USER', 'Username or UID (format: <name|uid>[:<group|gid>])') do |user|
251
+ docker_options['-u'] = user
252
+ end
253
+
254
+ opts.on('--docker-tty', 'Allocate a pseudo-TTY') do |tty|
255
+ docker_options['-t'] = nil
256
+ end
257
+
258
+ opts.on('--docker-interactive', 'Keep STDIN open even if not attached') do |interactive|
259
+ docker_options['-i'] = nil
260
+ end
261
+ end
262
+ end
213
263
  end
214
264
 
215
265
  class DockerMainApp < Docker
@@ -2,20 +2,23 @@ module DockerRailsProxy
2
2
  class Cli
3
3
  class << self
4
4
  def invoke(arguments)
5
- command, *args = arguments
5
+ command, *all_arguments = arguments
6
+ arguments, additional_arguments = split_arguments(all_arguments)
6
7
 
7
8
  if command.nil?
8
9
  $stderr.puts <<-EOF
9
10
  #{"bin/#{APP_NAME} requires 1 argument.".bold}
10
11
 
11
- #{"Usage: bin/#{APP_NAME} <command> [<args>]".bold}
12
+ #{"Usage: bin/#{APP_NAME} <command> [<arguments>]".bold}
12
13
  EOF
13
14
  exit 1
14
15
  end
15
16
 
16
17
  if COMMANDS.include? command
17
- args << '-h' if args.empty?
18
- "DockerRailsProxy::#{command}".constantize.(arguments: args)
18
+ arguments << '-h' if arguments.empty?
19
+ "DockerRailsProxy::#{command}".constantize.call(
20
+ arguments: arguments, additional_arguments: additional_arguments
21
+ )
19
22
  else
20
23
  $stderr.puts <<-EOS
21
24
  #{'No such command'.yellow}
@@ -25,13 +28,22 @@ module DockerRailsProxy
25
28
 
26
29
  COMMANDS.each do |script|
27
30
  $stderr.puts <<-EOS
28
- #{script.parameterize.bold} [<args>]
31
+ #{script.parameterize.bold} [<arguments>]
29
32
  EOS
30
33
  end
31
34
 
32
35
  exit 1
33
36
  end
34
37
  end
38
+
39
+ private
40
+
41
+ def split_arguments(arguments)
42
+ return [arguments, []] unless (separator_index = arguments.index('--'))
43
+
44
+ arguments.delete_at(separator_index)
45
+ arguments.partition.with_index { |_, index| index < separator_index }
46
+ end
35
47
  end
36
48
  end
37
49
  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
@@ -37,7 +36,7 @@ module DockerRailsProxy
37
36
  self.from_scratch = if docker_compose?
38
37
  %x(docker-compose ps | grep -c #{APP_NAME}).to_i.zero?
39
38
  elsif kubernetes?
40
- %x(kubectl get deploy -l 'app=#{APP_NAME}' -o name).empty?
39
+ %x(kubectl get deployment #{APP_NAME} -o name).empty?
41
40
  end
42
41
  end
43
42
 
@@ -77,10 +76,12 @@ module DockerRailsProxy
77
76
  end
78
77
 
79
78
  def fswatch_start
79
+ logger.debug "fswatch command: #{FSWATCH_CMD}"
80
80
  logger.info 'fswatch has been started'
81
+
81
82
  PTY.spawn(FSWATCH_CMD) do |stdout, stdin, pid|
82
83
  begin
83
- stdout.each { |path| sync_or_kill(path: path, pid: pid) }
84
+ stdout.each { |path| sync_or_kill(path: path.strip, pid: pid) }
84
85
  rescue Errno::EIO
85
86
  logger.error EIO_ERROR
86
87
  end
@@ -98,7 +99,9 @@ module DockerRailsProxy
98
99
  return if stopping?
99
100
 
100
101
  if branch_name == (branch = current_branch)
102
+ logger.debug("syncing #{path}")
101
103
  sync source: path
104
+ logger.debug("#{path} synced")
102
105
  else
103
106
  $stderr.puts %(
104
107
  `git checkout #{branch}` was detected, stopping fswatch
@@ -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,14 +1,17 @@
1
1
  module DockerRailsProxy
2
2
  class Rails < SyncBack
3
+ attr_reader :args
4
+
3
5
  def process
4
- command, *args = arguments
6
+ command, *@args = arguments
5
7
 
6
8
  case command
7
- when 'c', 'console' then console args
8
- when 'db', 'dbconsole' then db args
9
- when 'logs' then logs args
9
+ when 'c', 'console' then console
10
+ when 'db', 'dbconsole' then db
11
+ when 'logs' then logs
10
12
  when 'restart', 'touch' then restart
11
13
  when 'secrets' then secrets
14
+ when 'credentials' then credentials
12
15
  else
13
16
  execute "bin/rails #{command} #{args.join(' ')}", tty: true
14
17
  end
@@ -16,11 +19,11 @@ module DockerRailsProxy
16
19
 
17
20
  private
18
21
 
19
- def console(args)
22
+ def console
20
23
  execute "bin/rails c #{args.join(' ')}", tty: true, replace_process: true
21
24
  end
22
25
 
23
- def db(args)
26
+ def db
24
27
  container_id = get_docker_container_id(:mysql)
25
28
 
26
29
  if container_id.empty?
@@ -36,7 +39,7 @@ module DockerRailsProxy
36
39
  )
37
40
  end
38
41
 
39
- def logs(args)
42
+ def logs
40
43
  execute "tail -f log/#{args.first || 'development'}.log", replace_process: true
41
44
  end
42
45
 
@@ -47,5 +50,12 @@ module DockerRailsProxy
47
50
  def secrets
48
51
  execute "bash -c 'EDITOR=vim bin/rails secrets:edit'", tty: true
49
52
  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
50
60
  end
51
61
  end
@@ -1,8 +1,7 @@
1
1
  module DockerRailsProxy
2
2
  class Rake < SyncBack
3
- def process
4
- command, *args = arguments
5
- execute "bin/rake #{command} #{args.join(' ')}"
3
+ builds ->(params:) do
4
+ Rails
6
5
  end
7
6
  end
8
7
  end
@@ -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,16 +1,16 @@
1
1
  module DockerRailsProxy
2
2
  module Callbacks
3
- INHERITABLE_CALLBACKS = %w(
3
+ INHERITABLE_CALLBACKS = %w[
4
4
  _before_initialize
5
5
  _after_initialize
6
6
  _validates
7
7
  _before_process
8
8
  _after_process
9
- ).freeze
9
+ ].freeze
10
10
 
11
- UNINHERITABLE_CALLBACKS = %w(
11
+ UNINHERITABLE_CALLBACKS = %w[
12
12
  _builds
13
- ).freeze
13
+ ].freeze
14
14
 
15
15
  def self.included(base)
16
16
  base.extend(ClassMethods)
@@ -50,12 +50,12 @@ 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, *rest) { resource.send(callback, *rest) }
54
54
  when ::Proc
55
55
  if callback.arity <= 0
56
- -> (resource) { resource.instance_exec(&callback) }
56
+ ->(resource) { resource.instance_exec(&callback) }
57
57
  else
58
- -> (resource, *rest) do
58
+ ->(resource, *rest) do
59
59
  if rest.empty?
60
60
  resource.instance_exec(resource, &callback)
61
61
  else
@@ -64,13 +64,13 @@ module DockerRailsProxy
64
64
  end
65
65
  end
66
66
  else
67
- -> (*) {}
67
+ ->(*) {}
68
68
  end
69
69
  end
70
70
 
71
71
  def _run_before_initialize_callbacks
72
72
  Array(_before_initialize).each do |callback|
73
- if (result = callback.call(self)).is_a? String
73
+ if (result = callback.call(self)).is_a?(String)
74
74
  $stderr.puts %(
75
75
  #{result}
76
76
  )
@@ -85,7 +85,7 @@ module DockerRailsProxy
85
85
 
86
86
  def _run_validation_callbacks(resource:)
87
87
  Array(_validates).each do |callback|
88
- if (result = callback.call(resource)).is_a? String
88
+ if (result = callback.call(resource)).is_a?(String)
89
89
  $stderr.puts %(
90
90
  #{result}
91
91
  )
@@ -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
- "> #{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.11'
2
+ VERSION = '0.1.16'
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_rails_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jairo
8
8
  - Vázquez
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-29 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:
@@ -60,7 +60,7 @@ homepage: https://github.com/jairovm/docker_rails_proxy
60
60
  licenses:
61
61
  - MIT
62
62
  metadata: {}
63
- post_install_message:
63
+ post_install_message:
64
64
  rdoc_options: []
65
65
  require_paths:
66
66
  - lib
@@ -75,9 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.7.6
80
- signing_key:
78
+ rubygems_version: 3.1.4
79
+ signing_key:
81
80
  specification_version: 4
82
81
  summary: docker, docker-compose and rails wrapper
83
82
  test_files: []