Skip to content

Commit eb61382

Browse files
committed
feat: refine testcontainer properties setup
Parse properties earlier to allow controlling Ryuk container config, specifically supporting the `with_privileged` flag.
1 parent aa580d3 commit eb61382

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/testcontainers.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,29 @@ defmodule Testcontainers do
5050
defp setup(options) do
5151
{conn, docker_host_url, docker_host} = Connection.get_connection(options)
5252

53+
# Read properties first so we can configure Ryuk appropriately
54+
{:ok, properties} = PropertiesParser.read_property_sources()
55+
5356
session_id =
5457
:crypto.hash(:sha, "#{inspect(self())}#{DateTime.utc_now() |> DateTime.to_string()}")
5558
|> Base.encode16()
5659

60+
ryuk_privileged = Map.get(properties, "ryuk.container.privileged", "false") == "true"
61+
5762
ryuk_config =
5863
Container.new("testcontainers/ryuk:#{Constants.ryuk_version()}")
5964
|> Container.with_exposed_port(8080)
6065
|> then(&apply_docker_socket_volume_binding(&1, docker_host))
6166
|> Container.with_auto_remove(true)
67+
|> Container.with_privileged(ryuk_privileged)
6268

6369
with {:ok, _} <- Api.pull_image(ryuk_config.image, conn),
6470
{:ok, docker_hostname} <- get_docker_hostname(docker_host_url, conn),
6571
{:ok, ryuk_container_id} <- Api.create_container(ryuk_config, conn),
6672
:ok <- Api.start_container(ryuk_container_id, conn),
6773
{:ok, container} <- Api.get_container(ryuk_container_id, conn),
6874
{:ok, socket} <- create_ryuk_socket(container, docker_hostname),
69-
:ok <- register_ryuk_filter(session_id, socket),
70-
{:ok, properties} <- PropertiesParser.read_property_file() do
75+
:ok <- register_ryuk_filter(session_id, socket) do
7176
Logger.info("Testcontainers initialized")
7277

7378
{:ok,

0 commit comments

Comments
 (0)