Commit 79242441 authored by Terence Lee's avatar Terence Lee

debug output for running app, connect to server after nginx has started,

network retry incase nginx hasn't bound to the port yet
parent cf80709c
...@@ -3,4 +3,5 @@ source "https://rubygems.org" ...@@ -3,4 +3,5 @@ source "https://rubygems.org"
group :development do group :development do
gem "docker-api" gem "docker-api"
gem "rspec" gem "rspec"
gem "concurrent-ruby"
end end
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
concurrent-ruby (0.8.0)
ref (~> 1.0, >= 1.0.5)
diff-lcs (1.2.5) diff-lcs (1.2.5)
docker-api (1.21.4) docker-api (1.21.4)
excon (>= 0.38.0) excon (>= 0.38.0)
json json
excon (0.45.3) excon (0.45.3)
json (1.8.2) json (1.8.2)
ref (1.0.5)
rspec (3.2.0) rspec (3.2.0)
rspec-core (~> 3.2.0) rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0) rspec-expectations (~> 3.2.0)
...@@ -25,6 +28,7 @@ PLATFORMS ...@@ -25,6 +28,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
concurrent-ruby
docker-api docker-api
rspec rspec
......
...@@ -3,6 +3,7 @@ require "net/http" ...@@ -3,6 +3,7 @@ require "net/http"
require "fileutils" require "fileutils"
require "json" require "json"
require "docker" require "docker"
require "concurrent/atomic/count_down_latch"
require_relative "path_helper" require_relative "path_helper"
class AppRunner class AppRunner
...@@ -29,21 +30,34 @@ class AppRunner ...@@ -29,21 +30,34 @@ class AppRunner
end end
def run def run
#@container.tap(&:start).attach { |stream, chunk| puts "#{stream}: #{chunk}" } latch = Concurrent::CountDownLatch.new(1)
@container.start run_thread = Thread.new {
sleep(1) latch.wait(0.5)
yield(@container) yield(@container)
}
container_thread = Thread.new {
@container.tap(&:start).attach do |stream, chunk|
puts "#{stream}: #{chunk}" if @debug
latch.count_down if chunk.include?("Starting nginx...")
end
}
run_thread.join
@container.stop @container.stop
container_thread.join
end end
def get(path) def get(path, max_retries = 5)
response = nil response = nil
run do run do
uri = URI("http://#{HOST_IP}:#{HOST_PORT}/#{path}") network_retry(max_retries) do
response = Net::HTTP.get_response(uri) uri = URI("http://#{HOST_IP}:#{HOST_PORT}/#{path}")
response = Net::HTTP.get_response(uri)
end
end end
return response response
end end
def destroy def destroy
...@@ -54,6 +68,17 @@ class AppRunner ...@@ -54,6 +68,17 @@ class AppRunner
end end
private private
def network_retry(max_retries, retry_count = 0)
yield
rescue Errno::ECONNRESET, EOFError
if retry_count < max_retries
puts "Retry Count: #{retry_count}" if @debug
sleep(0.01 * retry_count)
retry_count += 1
retry
end
end
def build_image(fixture) def build_image(fixture)
image = nil image = nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment