docker_rails_proxy 0.1 → 0.1.1

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
  SHA1:
3
- metadata.gz: e054684446e381e85f5a034bdf97b68f34cecbc8
4
- data.tar.gz: '08563be16ae0fae359a12fe46c799cee34fd4785'
3
+ metadata.gz: 43babff9d7eadd9268d58e475813c95334b07637
4
+ data.tar.gz: 1216cbfd498b85552cbcaf4c46f2149c17beb2a8
5
5
  SHA512:
6
- metadata.gz: a4868a69273f6b96a5a78a14d81072616399bf091cc91f5a19dd7ef9504911fb33df03b9aa04523b9f3ac41290de24a200d516141615b5c78029bba1d34bb736
7
- data.tar.gz: 8997b53995275162011777f74e5b7c5a03c0db763c5231b5c1764a8b9a02fd8baab3196fe492b54bc30cb562a2aeacf60f62ac088eb67b9004961a592bd1c367
6
+ metadata.gz: b0af44e98d35bc23b4063edf5fcb79ab9191e7efd4d53300718c9a838b6f5ef243a7779cb6f46f24d1509e1afed84a979a04494fa9e2f2303ab8471dbcdc63ca
7
+ data.tar.gz: c0e3788f76daa3c87bc406b81fdc6326a8b48c5df8b1c796412e45af288db680f81f3fcf527898e410946e27c1156752a8b579cce6898880baa9d21dd7d43f38
@@ -2,7 +2,7 @@ module DockerRailsProxy
2
2
  class Compose < Docker
3
3
  class Down < self
4
4
  def process
5
- return unless docker_machine?
5
+ return unless docker_compose?
6
6
 
7
7
  containers = %x(
8
8
  docker-compose ps | grep '#{APP_NAME}' | awk '{print $1}' | xargs
@@ -3,7 +3,7 @@ module DockerRailsProxy
3
3
  class Proxy < self
4
4
  def process
5
5
  command, *args = arguments
6
- system "docker-compose #{command} #{args.join(' ')}" if docker_machine?
6
+ system "docker-compose #{command} #{args.join(' ')}" if docker_compose?
7
7
  end
8
8
  end
9
9
  end
@@ -34,9 +34,9 @@ module DockerRailsProxy
34
34
  after_initialize :parse_options!, :set_defaults
35
35
 
36
36
  before_process do
37
- self.from_scratch = if docker_machine?
37
+ self.from_scratch = if docker_compose?
38
38
  %x(docker-compose ps | grep -c #{APP_NAME}).to_i.zero?
39
- elsif minikube?
39
+ elsif kubernetes?
40
40
  %x(kubectl get deploy -l 'app=#{APP_NAME}' -o name).empty?
41
41
  end
42
42
  end
@@ -44,7 +44,7 @@ module DockerRailsProxy
44
44
  after_process { fswatch_start }
45
45
 
46
46
  def process
47
- system 'docker-compose up -d' if docker_machine?
47
+ system 'docker-compose up -d' if docker_compose?
48
48
  sync_app_and_gems_folders
49
49
 
50
50
  set_app_container_id if app_container_id.empty?
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
  require 'optparse'
2
3
  require 'yaml'
3
4
 
@@ -26,7 +27,7 @@ module DockerRailsProxy
26
27
  end
27
28
 
28
29
  before_process do
29
- Dir.mkdir('tmp/.kube') unless Dir.exist?('tmp/.kube')
30
+ FileUtils.mkdir_p 'tmp/.kube'
30
31
 
31
32
  absolute_dir = File.dirname(options[:path])
32
33
 
@@ -31,14 +31,14 @@ module DockerRailsProxy
31
31
 
32
32
  def _rsync_host
33
33
  @_rsync_host ||= begin
34
- ip = ENV['DOCKER_HOST'].to_s.sub('tcp://', '').sub(/:\d+$/, '')
34
+ ip = ENV.fetch('DOCKER_HOST') { '127.0.0.1' }.to_s.sub('tcp://', '').sub(/:\d+$/, '')
35
35
  port = '10873'
36
36
 
37
37
  loop do
38
38
  break if (port = %x(kubectl get svc "#{APP_NAME}" -o jsonpath='{.spec.ports[?(@.name=="rsync")].nodePort}' 2> /dev/null).strip).present?
39
39
  sleep 5
40
40
  logger.info 'Waiting for rsync port ...'
41
- end if Docker.vm_provisioner == :minikube
41
+ end if Docker.kubernetes_running
42
42
 
43
43
  "rsync://#{ip}:#{port}"
44
44
  end
@@ -1,3 +1,3 @@
1
1
  module DockerRailsProxy
2
- VERSION = '0.1'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -126,13 +126,19 @@ module DockerRailsProxy
126
126
 
127
127
  class Docker < Base
128
128
  class << self
129
- attr_accessor :vm_provisioner
129
+ attr_accessor :vm_provisioner, :kubernetes_running
130
130
  end
131
131
 
132
132
  attr_accessor :app_container_id
133
133
 
134
134
  before_initialize do
135
- if ENV['DOCKER_HOST'].nil?
135
+ unless system 'type docker &> /dev/null'
136
+ 'Please install docker before continuing.'
137
+ end
138
+ end
139
+
140
+ before_initialize do
141
+ unless system 'docker ps &> /dev/null'
136
142
  %(
137
143
  Couldn't connect to Docker daemon you might need to run:
138
144
  docker-machine start default
@@ -142,25 +148,35 @@ module DockerRailsProxy
142
148
  end
143
149
 
144
150
  before_initialize do
145
- Docker.vm_provisioner = ENV['DOCKER_CERT_PATH'].include?('.minikube') ? :minikube : :docker_machine
151
+ if ENV['DOCKER_CERT_PATH'].present?
152
+ Docker.vm_provisioner = ENV['DOCKER_CERT_PATH'].include?('.minikube') ? :minikube : :docker_machine
153
+ end
154
+
155
+ Docker.vm_provisioner ||= :docker_for_mac
156
+ end
157
+
158
+ before_initialize do
159
+ if system 'docker images | grep -c kube-apiserver &> /dev/null'
160
+ Docker.kubernetes_running = true
161
+ end
146
162
  end
147
163
 
148
164
  before_initialize do
149
165
  unless system 'type kubectl &> /dev/null'
150
166
  'kubectl is required, `brew install kubectl`'
151
- end if Docker.vm_provisioner == :minikube
167
+ end if Docker.kubernetes_running
152
168
  end
153
169
 
154
170
  after_initialize :set_app_container_id
155
171
 
156
172
  private
157
173
 
158
- def docker_machine?
159
- Docker.vm_provisioner == :docker_machine
174
+ def docker_compose?
175
+ !!Docker.kubernetes_running == false
160
176
  end
161
177
 
162
- def minikube?
163
- Docker.vm_provisioner == :minikube
178
+ def kubernetes?
179
+ Docker.kubernetes_running
164
180
  end
165
181
 
166
182
  def set_app_container_id
@@ -168,9 +184,9 @@ module DockerRailsProxy
168
184
  end
169
185
 
170
186
  def get_docker_container_id(app, container: nil)
171
- if docker_machine?
187
+ if docker_compose?
172
188
  %x(docker ps -q --filter "name=^/#{[app, container].compact.join('_')}$").strip
173
- elsif minikube?
189
+ elsif kubernetes?
174
190
  pod_name = %x(kubectl get pod -l "app=#{app}" 2> /dev/null | grep Running | awk '{print $1}').strip
175
191
  return '' if pod_name.empty?
176
192
 
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.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-22 00:00:00.000000000 Z
12
+ date: 2018-01-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Configures docker-compose and provides rails command helpers
15
15
  email: