docker_rails_proxy 0.0.12 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docker_rails_proxy/commands/bundle.rb +1 -1
- data/lib/docker_rails_proxy/commands/compose/down.rb +2 -0
- data/lib/docker_rails_proxy/commands/compose/override.rb +1 -1
- data/lib/docker_rails_proxy/commands/compose/proxy.rb +1 -1
- data/lib/docker_rails_proxy/commands/compose/up.rb +25 -16
- data/lib/docker_rails_proxy/commands/data_bags/pull.rb +1 -1
- data/lib/docker_rails_proxy/commands/data_bags/push.rb +1 -1
- data/lib/docker_rails_proxy/commands/rails.rb +17 -10
- data/lib/docker_rails_proxy/commands/rake.rb +1 -1
- data/lib/docker_rails_proxy/commands/rspec.rb +1 -1
- data/lib/docker_rails_proxy/commands/spring.rb +1 -1
- data/lib/docker_rails_proxy/commands/ssh.rb +1 -1
- data/lib/docker_rails_proxy/commands/webpack.rb +1 -1
- data/lib/docker_rails_proxy/commands/webpack_dev_server.rb +1 -1
- data/lib/docker_rails_proxy/commands/yarn.rb +1 -1
- data/lib/docker_rails_proxy/concerns/logger.rb +25 -0
- data/lib/docker_rails_proxy/concerns/rsync.rb +11 -2
- data/lib/docker_rails_proxy/version.rb +1 -1
- data/lib/docker_rails_proxy.rb +57 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e054684446e381e85f5a034bdf97b68f34cecbc8
|
4
|
+
data.tar.gz: '08563be16ae0fae359a12fe46c799cee34fd4785'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4868a69273f6b96a5a78a14d81072616399bf091cc91f5a19dd7ef9504911fb33df03b9aa04523b9f3ac41290de24a200d516141615b5c78029bba1d34bb736
|
7
|
+
data.tar.gz: 8997b53995275162011777f74e5b7c5a03c0db763c5231b5c1764a8b9a02fd8baab3196fe492b54bc30cb562a2aeacf60f62ac088eb67b9004961a592bd1c367
|
@@ -9,7 +9,7 @@ module DockerRailsProxy
|
|
9
9
|
--latency=0.1 \
|
10
10
|
--exclude '.git' \
|
11
11
|
--exclude '4913' \
|
12
|
-
"#{APP_PATH
|
12
|
+
"#{[APP_PATH, GEMS_PATH].compact.join('" "')}" | xargs -0 -n1 -I{} echo {}
|
13
13
|
EOS
|
14
14
|
|
15
15
|
EIO_ERROR = %(
|
@@ -34,55 +34,64 @@ module DockerRailsProxy
|
|
34
34
|
after_initialize :parse_options!, :set_defaults
|
35
35
|
|
36
36
|
before_process do
|
37
|
-
self.from_scratch =
|
37
|
+
self.from_scratch = if docker_machine?
|
38
|
+
%x(docker-compose ps | grep -c #{APP_NAME}).to_i.zero?
|
39
|
+
elsif minikube?
|
40
|
+
%x(kubectl get deploy -l 'app=#{APP_NAME}' -o name).empty?
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
44
|
after_process { fswatch_start }
|
41
45
|
|
42
46
|
def process
|
43
|
-
system 'docker-compose up -d'
|
47
|
+
system 'docker-compose up -d' if docker_machine?
|
44
48
|
sync_app_and_gems_folders
|
45
|
-
|
46
|
-
|
49
|
+
|
50
|
+
set_app_container_id if app_container_id.empty?
|
51
|
+
run_bundle_install if options[:bundle]
|
52
|
+
seed if from_scratch?
|
47
53
|
end
|
48
54
|
|
49
55
|
private
|
50
56
|
|
51
57
|
def seed
|
52
|
-
|
53
|
-
|
54
|
-
|
58
|
+
logger.info "Seeding #{APP_NAME} data"
|
59
|
+
|
60
|
+
loop do
|
61
|
+
break if execute "bin/rake db:reset"
|
62
|
+
sleep 5
|
63
|
+
end
|
55
64
|
end
|
56
65
|
|
57
66
|
def sync_app_and_gems_folders
|
58
67
|
rsync_app
|
59
|
-
sync source: GEMS_PATH
|
68
|
+
sync source: GEMS_PATH if GEMS_PATH.present?
|
60
69
|
end
|
61
70
|
|
62
71
|
def rsync_app
|
63
72
|
loop do
|
64
73
|
break if sync(source: APP_PATH)
|
65
|
-
|
66
|
-
sleep
|
74
|
+
logger.info "waiting for rsync-volume service on #{_rsync_host}"
|
75
|
+
sleep 5
|
67
76
|
end
|
68
77
|
end
|
69
78
|
|
70
79
|
def fswatch_start
|
71
|
-
|
80
|
+
logger.info 'fswatch has been started'
|
72
81
|
PTY.spawn(FSWATCH_CMD) do |stdout, stdin, pid|
|
73
82
|
begin
|
74
83
|
stdout.each { |path| sync_or_kill(path: path, pid: pid) }
|
75
84
|
rescue Errno::EIO
|
76
|
-
|
85
|
+
logger.error EIO_ERROR
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
80
89
|
rescue PTY::ChildExited
|
81
|
-
|
90
|
+
logger.error '"The fswatch process exited!'
|
82
91
|
|
83
92
|
# Captures Ctrl-C
|
84
93
|
rescue Exception
|
85
|
-
|
94
|
+
logger.info 'fswatch has been stopped'
|
86
95
|
end
|
87
96
|
|
88
97
|
def sync_or_kill(path:, pid:)
|
@@ -106,7 +115,7 @@ module DockerRailsProxy
|
|
106
115
|
|
107
116
|
# since new gems may have been added, we need bundle install
|
108
117
|
def run_bundle_install
|
109
|
-
|
118
|
+
execute "bundle install"
|
110
119
|
end
|
111
120
|
|
112
121
|
def parse_options!
|
@@ -9,31 +9,38 @@ module DockerRailsProxy
|
|
9
9
|
when 'logs' then logs args
|
10
10
|
when 'restart', 'touch' then restart
|
11
11
|
else
|
12
|
-
|
12
|
+
execute "bin/rails #{command} #{args.join(' ')}", tty: true
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def console(args)
|
19
|
-
|
19
|
+
execute "bin/rails c #{args.join(' ')}", tty: true, replace_process: true
|
20
20
|
end
|
21
21
|
|
22
22
|
def db(args)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
container_id = get_docker_container_id(:mysql)
|
24
|
+
|
25
|
+
if container_id.empty?
|
26
|
+
logger.error "Couldn't connect to mysql container, make sure it's running"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
execute(
|
31
|
+
"mysql #{args.first || "#{APP_NAME}_development"}",
|
32
|
+
container_id: container_id,
|
33
|
+
tty: true,
|
34
|
+
replace_process: true
|
35
|
+
)
|
27
36
|
end
|
28
37
|
|
29
38
|
def logs(args)
|
30
|
-
|
31
|
-
docker exec #{APP_NAME} tail -f log/#{args.first || 'development'}.log
|
32
|
-
EOS
|
39
|
+
execute "tail -f log/#{args.first || 'development'}.log", replace_process: true
|
33
40
|
end
|
34
41
|
|
35
42
|
def restart
|
36
|
-
|
43
|
+
execute "touch tmp/restart.txt", replace_process: true
|
37
44
|
end
|
38
45
|
end
|
39
46
|
end
|
@@ -2,7 +2,7 @@ module DockerRailsProxy
|
|
2
2
|
class WebpackDevServer < DockerMainApp
|
3
3
|
def process
|
4
4
|
command, *args = arguments
|
5
|
-
|
5
|
+
execute "bin/webpack-dev-server #{command} #{args.join(' ')}"
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module DockerRailsProxy
|
4
|
+
module Logger
|
5
|
+
class << self
|
6
|
+
def included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
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
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def logger
|
22
|
+
self.class.logger
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -31,7 +31,16 @@ module DockerRailsProxy
|
|
31
31
|
|
32
32
|
def _rsync_host
|
33
33
|
@_rsync_host ||= begin
|
34
|
-
|
34
|
+
ip = ENV['DOCKER_HOST'].to_s.sub('tcp://', '').sub(/:\d+$/, '')
|
35
|
+
port = '10873'
|
36
|
+
|
37
|
+
loop do
|
38
|
+
break if (port = %x(kubectl get svc "#{APP_NAME}" -o jsonpath='{.spec.ports[?(@.name=="rsync")].nodePort}' 2> /dev/null).strip).present?
|
39
|
+
sleep 5
|
40
|
+
logger.info 'Waiting for rsync port ...'
|
41
|
+
end if Docker.vm_provisioner == :minikube
|
42
|
+
|
43
|
+
"rsync://#{ip}:#{port}"
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
@@ -67,7 +76,7 @@ module DockerRailsProxy
|
|
67
76
|
def normalize_options(source:, reverse: false, **)
|
68
77
|
values = if source.include? APP_PATH
|
69
78
|
["#{APP_PATH}/", 'app']
|
70
|
-
elsif source.include?
|
79
|
+
elsif GEMS_PATH.present? and source.include?(GEMS_PATH)
|
71
80
|
["#{GEMS_PATH}/", 'gems']
|
72
81
|
else
|
73
82
|
$stderr.puts "There is no rsync volume related with this path: #{source}"
|
data/lib/docker_rails_proxy.rb
CHANGED
@@ -16,6 +16,7 @@ module DockerRailsProxy
|
|
16
16
|
autoload :InheritableAttributes, 'docker_rails_proxy/concerns/inheritable_attributes'
|
17
17
|
autoload :Callbacks, 'docker_rails_proxy/concerns/callbacks'
|
18
18
|
autoload :Rsync, 'docker_rails_proxy/concerns/rsync'
|
19
|
+
autoload :Logger, 'docker_rails_proxy/concerns/logger'
|
19
20
|
|
20
21
|
autoload :Cli, 'docker_rails_proxy/cli'
|
21
22
|
autoload :VERSION, 'docker_rails_proxy/version'
|
@@ -24,6 +25,7 @@ module DockerRailsProxy
|
|
24
25
|
include InheritableAttributes
|
25
26
|
include Callbacks
|
26
27
|
include Rsync
|
28
|
+
include Logger
|
27
29
|
|
28
30
|
attr_reader :arguments
|
29
31
|
|
@@ -41,9 +43,7 @@ module DockerRailsProxy
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def execute(options)
|
44
|
-
system
|
45
|
-
#{build_path("bin/#{APP_NAME}")} #{command} #{options}
|
46
|
-
EOS
|
46
|
+
system "#{build_path("bin/#{APP_NAME}")} #{command} #{options}"
|
47
47
|
end
|
48
48
|
|
49
49
|
def call(options)
|
@@ -125,22 +125,71 @@ module DockerRailsProxy
|
|
125
125
|
end
|
126
126
|
|
127
127
|
class Docker < Base
|
128
|
+
class << self
|
129
|
+
attr_accessor :vm_provisioner
|
130
|
+
end
|
131
|
+
|
132
|
+
attr_accessor :app_container_id
|
133
|
+
|
128
134
|
before_initialize do
|
129
135
|
if ENV['DOCKER_HOST'].nil?
|
130
136
|
%(
|
131
137
|
Couldn't connect to Docker daemon you might need to run:
|
132
138
|
docker-machine start default
|
133
|
-
eval $(docker-machine env default)
|
139
|
+
eval $(docker-machine env default) or eval $(minikube docker-env)
|
134
140
|
)
|
135
141
|
end
|
136
142
|
end
|
143
|
+
|
144
|
+
before_initialize do
|
145
|
+
Docker.vm_provisioner = ENV['DOCKER_CERT_PATH'].include?('.minikube') ? :minikube : :docker_machine
|
146
|
+
end
|
147
|
+
|
148
|
+
before_initialize do
|
149
|
+
unless system 'type kubectl &> /dev/null'
|
150
|
+
'kubectl is required, `brew install kubectl`'
|
151
|
+
end if Docker.vm_provisioner == :minikube
|
152
|
+
end
|
153
|
+
|
154
|
+
after_initialize :set_app_container_id
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
def docker_machine?
|
159
|
+
Docker.vm_provisioner == :docker_machine
|
160
|
+
end
|
161
|
+
|
162
|
+
def minikube?
|
163
|
+
Docker.vm_provisioner == :minikube
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_app_container_id
|
167
|
+
self.app_container_id = get_docker_container_id(APP_NAME)
|
168
|
+
end
|
169
|
+
|
170
|
+
def get_docker_container_id(app, container: nil)
|
171
|
+
if docker_machine?
|
172
|
+
%x(docker ps -q --filter "name=^/#{[app, container].compact.join('_')}$").strip
|
173
|
+
elsif minikube?
|
174
|
+
pod_name = %x(kubectl get pod -l "app=#{app}" 2> /dev/null | grep Running | awk '{print $1}').strip
|
175
|
+
return '' if pod_name.empty?
|
176
|
+
|
177
|
+
full_id = %x(kubectl get pod #{pod_name} -o jsonpath='{ .status.containerStatuses[?(@.name=="#{container || app}")].containerID }').strip
|
178
|
+
full_id.split('//').last
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def execute(command, tty: false, container_id: app_container_id, replace_process: false, **)
|
183
|
+
command = "docker exec #{tty ? '-ti' : nil} #{container_id} #{command}"
|
184
|
+
replace_process ? exec(command) : system(command)
|
185
|
+
end
|
137
186
|
end
|
138
187
|
|
139
188
|
class DockerMainApp < Docker
|
140
|
-
|
141
|
-
|
189
|
+
after_initialize do
|
190
|
+
if app_container_id.empty?
|
142
191
|
%(
|
143
|
-
Couldn't connect to #{APP_NAME} container you might need to run:
|
192
|
+
Couldn't connect to #{APP_NAME}'s container you might need to run:
|
144
193
|
bin/#{APP_NAME} compose up
|
145
194
|
)
|
146
195
|
end
|
@@ -151,7 +200,7 @@ module DockerRailsProxy
|
|
151
200
|
end
|
152
201
|
|
153
202
|
class SyncBack < DockerMainApp
|
154
|
-
after_process {
|
203
|
+
after_process { execute "chown -R nobody:nogroup ." }
|
155
204
|
after_process { sync source: APP_PATH, reverse: true }
|
156
205
|
end
|
157
206
|
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.
|
4
|
+
version: '0.1'
|
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: 2017-12-
|
12
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Configures docker-compose and provides rails command helpers
|
15
15
|
email:
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/docker_rails_proxy/commands/yarn.rb
|
50
50
|
- lib/docker_rails_proxy/concerns/callbacks.rb
|
51
51
|
- lib/docker_rails_proxy/concerns/inheritable_attributes.rb
|
52
|
+
- lib/docker_rails_proxy/concerns/logger.rb
|
52
53
|
- lib/docker_rails_proxy/concerns/rsync.rb
|
53
54
|
- lib/docker_rails_proxy/extends/colorization.rb
|
54
55
|
- lib/docker_rails_proxy/extends/fixnum_support.rb
|