docker_rails_proxy 0.1.10 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -2
- data/lib/docker_rails_proxy.rb +44 -10
- data/lib/docker_rails_proxy/cli.rb +23 -5
- data/lib/docker_rails_proxy/commands/compose/up.rb +6 -2
- data/lib/docker_rails_proxy/commands/rails.rb +17 -7
- data/lib/docker_rails_proxy/commands/rake.rb +2 -3
- data/lib/docker_rails_proxy/concerns/callbacks.rb +10 -10
- data/lib/docker_rails_proxy/concerns/logger.rb +1 -1
- data/lib/docker_rails_proxy/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11cc5b5ffa094628db0143b27de25323c7c6e610ff51f3bc3cfd308c0d944e0e
|
4
|
+
data.tar.gz: c151d104cbc5835d2afa116c667eee6241ff728d7fb66df49b4a80ad34b07473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7177b8ff7a8918bb156065c3e5832269d70cccf1b8575544b06e455e085e6b0d77743d07fdd84e00ec55f1b6dc00cd7ae308c65080e588c5484a76293b1dc387
|
7
|
+
data.tar.gz: 83ab38f68fef1981fb682dd57e2f4cb7063a143017e322bc57fb6431affda117cecf52c8cca23b73fe8c8b9066282b3e79583325bd68eeca639596b41d757a3c
|
data/README.md
CHANGED
@@ -1,6 +1,28 @@
|
|
1
1
|
### To release a new version
|
2
2
|
|
3
|
-
|
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
|
```
|
data/lib/docker_rails_proxy.rb
CHANGED
@@ -27,10 +27,11 @@ module DockerRailsProxy
|
|
27
27
|
include Rsync
|
28
28
|
include Logger
|
29
29
|
|
30
|
-
attr_reader :arguments
|
30
|
+
attr_reader :arguments, :additional_arguments
|
31
31
|
|
32
|
-
def initialize(arguments:)
|
33
|
-
@arguments
|
32
|
+
def initialize(arguments:, additional_arguments:)
|
33
|
+
@arguments = arguments
|
34
|
+
@additional_arguments = additional_arguments
|
34
35
|
end
|
35
36
|
|
36
37
|
class << self
|
@@ -129,7 +130,7 @@ module DockerRailsProxy
|
|
129
130
|
attr_accessor :vm_provisioner, :kubernetes_running
|
130
131
|
end
|
131
132
|
|
132
|
-
attr_accessor :app_container_id
|
133
|
+
attr_accessor :app_container_id, :docker_options
|
133
134
|
|
134
135
|
before_initialize do
|
135
136
|
unless system 'type docker &> /dev/null'
|
@@ -167,6 +168,8 @@ module DockerRailsProxy
|
|
167
168
|
end if Docker.kubernetes_running
|
168
169
|
end
|
169
170
|
|
171
|
+
after_initialize { self.docker_options = {} }
|
172
|
+
after_initialize { docker_arguments_parser.parse!(additional_arguments) }
|
170
173
|
after_initialize :set_app_container_id
|
171
174
|
|
172
175
|
private
|
@@ -185,7 +188,7 @@ module DockerRailsProxy
|
|
185
188
|
|
186
189
|
def get_docker_container_id(app, container: nil)
|
187
190
|
if docker_compose?
|
188
|
-
%x(docker ps -q --filter "name
|
191
|
+
%x(docker ps -q --filter "name=#{[app, container].compact.join('_')}$").strip
|
189
192
|
elsif kubernetes?
|
190
193
|
pod_name = %x(kubectl get pod -l "app=#{app}" 2> /dev/null | grep Running | awk '{print $1}').strip
|
191
194
|
return '' if pod_name.empty?
|
@@ -199,17 +202,48 @@ module DockerRailsProxy
|
|
199
202
|
tty: false,
|
200
203
|
container_id: app_container_id,
|
201
204
|
replace_process: false,
|
202
|
-
user: nil,
|
203
205
|
**)
|
204
206
|
|
205
|
-
|
207
|
+
docker_options['-ti'] = nil if tty
|
206
208
|
|
207
|
-
|
208
|
-
|
209
|
+
command = [
|
210
|
+
'docker exec',
|
211
|
+
docker_options.map { |key, value| [key, value].compact.join(' ') },
|
212
|
+
container_id,
|
213
|
+
command
|
214
|
+
].join(' '.freeze)
|
209
215
|
|
210
|
-
command = "docker exec #{options.join(' '.freeze)} #{container_id} #{command}"
|
211
216
|
replace_process ? exec(command) : system(command)
|
212
217
|
end
|
218
|
+
|
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|
|
224
|
+
docker_options['-w'] = workdir
|
225
|
+
end
|
226
|
+
|
227
|
+
opts.on('-u', '--user USER', 'Username or UID (format: <name|uid>[:<group|gid>])') do |user|
|
228
|
+
docker_options['-u'] = user
|
229
|
+
end
|
230
|
+
|
231
|
+
opts.on('-t', '--tty', 'Allocate a pseudo-TTY') do |tty|
|
232
|
+
docker_options['-t'] = nil
|
233
|
+
end
|
234
|
+
|
235
|
+
opts.on('-i', '--interactive', 'Keep STDIN open even if not attached') do |interactive|
|
236
|
+
docker_options['-i'] = nil
|
237
|
+
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
|
+
end
|
246
|
+
end
|
213
247
|
end
|
214
248
|
|
215
249
|
class DockerMainApp < Docker
|
@@ -2,20 +2,23 @@ module DockerRailsProxy
|
|
2
2
|
class Cli
|
3
3
|
class << self
|
4
4
|
def invoke(arguments)
|
5
|
-
command, *
|
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> [<
|
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
|
-
|
18
|
-
"DockerRailsProxy::#{command}".constantize.(
|
18
|
+
arguments << '-h' if arguments.empty?
|
19
|
+
"DockerRailsProxy::#{command}".constantize.(
|
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,28 @@ module DockerRailsProxy
|
|
25
28
|
|
26
29
|
COMMANDS.each do |script|
|
27
30
|
$stderr.puts <<-EOS
|
28
|
-
#{script.parameterize.bold} [<
|
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
|
+
arguments = arguments.join(' ') if arguments.is_a?(Array)
|
43
|
+
arguments, additional_arguments = arguments.split(' -- ')
|
44
|
+
[parse_arguments(arguments), parse_arguments(additional_arguments)]
|
45
|
+
end
|
46
|
+
|
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
|
52
|
+
end
|
35
53
|
end
|
36
54
|
end
|
37
55
|
end
|
@@ -37,7 +37,7 @@ module DockerRailsProxy
|
|
37
37
|
self.from_scratch = if docker_compose?
|
38
38
|
%x(docker-compose ps | grep -c #{APP_NAME}).to_i.zero?
|
39
39
|
elsif kubernetes?
|
40
|
-
%x(kubectl get
|
40
|
+
%x(kubectl get deployment #{APP_NAME} -o name).empty?
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -77,10 +77,12 @@ module DockerRailsProxy
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def fswatch_start
|
80
|
+
logger.debug "fswatch command: #{FSWATCH_CMD}"
|
80
81
|
logger.info 'fswatch has been started'
|
82
|
+
|
81
83
|
PTY.spawn(FSWATCH_CMD) do |stdout, stdin, pid|
|
82
84
|
begin
|
83
|
-
stdout.each { |path| sync_or_kill(path: path, pid: pid) }
|
85
|
+
stdout.each { |path| sync_or_kill(path: path.strip, pid: pid) }
|
84
86
|
rescue Errno::EIO
|
85
87
|
logger.error EIO_ERROR
|
86
88
|
end
|
@@ -98,7 +100,9 @@ module DockerRailsProxy
|
|
98
100
|
return if stopping?
|
99
101
|
|
100
102
|
if branch_name == (branch = current_branch)
|
103
|
+
logger.debug("syncing #{path}")
|
101
104
|
sync source: path
|
105
|
+
logger.debug("#{path} synced")
|
102
106
|
else
|
103
107
|
$stderr.puts %(
|
104
108
|
`git checkout #{branch}` was detected, stopping fswatch
|
@@ -1,14 +1,17 @@
|
|
1
1
|
module DockerRailsProxy
|
2
2
|
class Rails < SyncBack
|
3
|
+
attr_reader :args
|
4
|
+
|
3
5
|
def process
|
4
|
-
command,
|
6
|
+
command, *@args = arguments
|
5
7
|
|
6
8
|
case command
|
7
|
-
when 'c', 'console' then console
|
8
|
-
when 'db', 'dbconsole' then db
|
9
|
-
when 'logs' then logs
|
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
|
22
|
+
def console
|
20
23
|
execute "bin/rails c #{args.join(' ')}", tty: true, replace_process: true
|
21
24
|
end
|
22
25
|
|
23
|
-
def db
|
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
|
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,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
|
-
|
9
|
+
].freeze
|
10
10
|
|
11
|
-
UNINHERITABLE_CALLBACKS = %w
|
11
|
+
UNINHERITABLE_CALLBACKS = %w[
|
12
12
|
_builds
|
13
|
-
|
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
|
-
->
|
53
|
+
->(resource, *rest) { resource.send(callback, *rest) }
|
54
54
|
when ::Proc
|
55
55
|
if callback.arity <= 0
|
56
|
-
->
|
56
|
+
->(resource) { resource.instance_exec(&callback) }
|
57
57
|
else
|
58
|
-
->
|
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?
|
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?
|
88
|
+
if (result = callback.call(resource)).is_a?(String)
|
89
89
|
$stderr.puts %(
|
90
90
|
#{result}
|
91
91
|
)
|
@@ -12,7 +12,7 @@ module DockerRailsProxy
|
|
12
12
|
def logger
|
13
13
|
@logger ||= ::Logger.new(STDOUT).tap do |log|
|
14
14
|
log.formatter = proc do |severity, datetime, progname, msg|
|
15
|
-
"
|
15
|
+
"#{severity[0]}, [#{datetime.strftime('%Y-%m-%d %T')}] -- : #{msg}\n"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
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.
|
4
|
+
version: 0.1.15
|
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:
|
12
|
+
date: 2021-01-21 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
|
-
|
79
|
-
|
80
|
-
signing_key:
|
78
|
+
rubygems_version: 3.0.3
|
79
|
+
signing_key:
|
81
80
|
specification_version: 4
|
82
81
|
summary: docker, docker-compose and rails wrapper
|
83
82
|
test_files: []
|