Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tc.host in ~/.testcontainers.properties #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading