Skip to content

Commit

Permalink
Support tc.host
Browse files Browse the repository at this point in the history
Read `tc.host` property from `~/.testcontainers.properties` file.
  • Loading branch information
eddumelendez committed Feb 16, 2024
1 parent 94597a5 commit e769d79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
testcontainers-core (0.2.0)
docker-api (~> 2.2)
properties-ruby (~> 0.0.4)

GEM
remote: https://rubygems.org/
Expand All @@ -15,13 +16,16 @@ GEM
json (2.6.3)
language_server-protocol (3.17.0.3)
lint_roller (1.0.0)
logeasy (0.0.8)
minitest (5.18.0)
minitest-hooks (1.5.0)
minitest (> 5.3)
multi_json (1.15.0)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
properties-ruby (0.0.4)
logeasy (>= 0.0.4)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.8.0)
Expand Down Expand Up @@ -63,6 +67,7 @@ PLATFORMS
DEPENDENCIES
minitest (~> 5.0)
minitest-hooks (~> 1.5)
properties-ruby (~> 0.0.4)
rake (~> 13.0)
standard (~> 1.3)
testcontainers-core!
Expand Down
12 changes: 11 additions & 1 deletion core/lib/testcontainers/docker_container.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'properties-ruby'
module Testcontainers
# The DockerContainer class is used to manage Docker containers.
# It provides an interface to create, start, stop, and manipulate containers
Expand Down Expand Up @@ -472,7 +473,16 @@ def use
# @raise [ConnectionError] If the connection to the Docker daemon fails.
# @raise [NotFoundError] If Docker is unable to find the image.
def start
Docker::Image.create({"fromImage" => @image}.merge(@image_create_options))
properties = Utils::Properties.load_from_file(File.expand_path('~/.testcontainers.properties'))
tc_host = properties.get(:"tc.host")

if tc_host && !tc_host.empty?
Docker.url = tc_host
end

connection = Docker::Connection.new(Docker.url, Docker.options)

Docker::Image.create({"fromImage" => @image}.merge(@image_create_options), connection)

@_container ||= Docker::Container.create(_container_create_options)
@_container.start
Expand Down
1 change: 1 addition & 0 deletions core/testcontainers-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Gem::Specification.new do |spec|

# Uncomment to register a new dependency of your gem
spec.add_dependency "docker-api", "~> 2.2"
spec.add_dependency "properties-ruby", "~> 0.0.4"

spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "minitest", "~> 5.0"
Expand Down

0 comments on commit e769d79

Please sign in to comment.