Skip to content

Commit e5fbf4f

Browse files
Merge pull request #81 from PedroI920224/support-tc-host-javaproperties
[Feature] Add support for TC.host using JavaProperties
2 parents 6907a35 + e3ebc53 commit e5fbf4f

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PATH
1515
specs:
1616
testcontainers-core (0.2.0)
1717
docker-api (~> 2.2)
18+
java-properties (~> 0.3.0)
1819

1920
PATH
2021
remote: elasticsearch
@@ -104,6 +105,7 @@ GEM
104105
ruby2_keywords (>= 0.0.4)
105106
faraday-net_http (3.0.2)
106107
ffi (1.15.5)
108+
java-properties (0.3.0)
107109
json (2.6.3)
108110
language_server-protocol (3.17.0.3)
109111
lint_roller (1.0.0)

core/Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PATH
33
specs:
44
testcontainers-core (0.2.0)
55
docker-api (~> 2.2)
6+
java-properties (~> 0.3.0)
67

78
GEM
89
remote: https://rubygems.org/
@@ -12,6 +13,7 @@ GEM
1213
excon (>= 0.47.0)
1314
multi_json
1415
excon (0.99.0)
16+
java-properties (0.3.0)
1517
json (2.6.3)
1618
language_server-protocol (3.17.0.3)
1719
lint_roller (1.0.0)

core/lib/testcontainers/docker_container.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "java-properties"
2+
13
module Testcontainers
24
# The DockerContainer class is used to manage Docker containers.
35
# It provides an interface to create, start, stop, and manipulate containers
@@ -472,7 +474,19 @@ def use
472474
# @raise [ConnectionError] If the connection to the Docker daemon fails.
473475
# @raise [NotFoundError] If Docker is unable to find the image.
474476
def start
475-
Docker::Image.create({"fromImage" => @image}.merge(@image_create_options))
477+
expanded_path = File.expand_path("~/.testcontainers.properties")
478+
479+
properties = File.exist?(expanded_path) ? JavaProperties.load(expanded_path) : {}
480+
481+
tc_host = ENV["TESTCONTAINERS_HOST"] || properties[:"tc.host"]
482+
483+
if tc_host && !tc_host.empty?
484+
Docker.url = tc_host
485+
end
486+
487+
connection = Docker::Connection.new(Docker.url, Docker.options)
488+
489+
Docker::Image.create({"fromImage" => @image}.merge(@image_create_options), connection)
476490

477491
@_container ||= Docker::Container.create(_container_create_options)
478492
@_container.start

core/testcontainers-core.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
3131

3232
# Uncomment to register a new dependency of your gem
3333
spec.add_dependency "docker-api", "~> 2.2"
34+
spec.add_dependency "java-properties", "~> 0.3.0"
3435

3536
spec.add_development_dependency "rake", "~> 13.0"
3637
spec.add_development_dependency "minitest", "~> 5.0"

0 commit comments

Comments
 (0)