docker_rails_proxy 0.1.11 → 0.1.12
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 +4 -4
- data/lib/docker_rails_proxy.rb +43 -9
- data/lib/docker_rails_proxy/cli.rb +16 -5
- data/lib/docker_rails_proxy/commands/rails.rb +9 -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/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a53bc4f12cc8991f7c3026e473dd14dbc4eed8d4924d6246c4926fd25e0a6243
|
4
|
+
data.tar.gz: 1664d26230d94e06c147b76ccca5a8efb23e658dbdd3ad9e41b5d3d86056270e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42f5d772ceca2b8c58be856bfced34fb65f2af43855dec6ac687a11783eb0cadf7881eca3ad4432b0a9481eef58cc3ccc008018dd73c6679b37cdc4f4ceec1f3
|
7
|
+
data.tar.gz: 59a0762778db54a0ba17577647a34af954196caaf345c690809bb18433fa5ff6781364a54acfcd24c56bd12cf1d06a1c19c628345508e0be255154f85f91758a
|
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
|
@@ -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,21 @@ 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
|
+
[arguments.split(' '), additional_arguments.to_s.split(' ')]
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
end
|
@@ -1,12 +1,14 @@
|
|
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
|
12
14
|
else
|
@@ -16,11 +18,11 @@ module DockerRailsProxy
|
|
16
18
|
|
17
19
|
private
|
18
20
|
|
19
|
-
def console
|
21
|
+
def console
|
20
22
|
execute "bin/rails c #{args.join(' ')}", tty: true, replace_process: true
|
21
23
|
end
|
22
24
|
|
23
|
-
def db
|
25
|
+
def db
|
24
26
|
container_id = get_docker_container_id(:mysql)
|
25
27
|
|
26
28
|
if container_id.empty?
|
@@ -36,7 +38,7 @@ module DockerRailsProxy
|
|
36
38
|
)
|
37
39
|
end
|
38
40
|
|
39
|
-
def logs
|
41
|
+
def logs
|
40
42
|
execute "tail -f log/#{args.first || 'development'}.log", replace_process: true
|
41
43
|
end
|
42
44
|
|
@@ -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
|
)
|
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.
|
4
|
+
version: 0.1.12
|
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:
|
12
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Configures docker-compose and provides rails command helpers
|
15
15
|
email:
|
@@ -75,8 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
|
79
|
-
rubygems_version: 2.7.6
|
78
|
+
rubygems_version: 3.0.3
|
80
79
|
signing_key:
|
81
80
|
specification_version: 4
|
82
81
|
summary: docker, docker-compose and rails wrapper
|