Skip to content
Merged
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
20 changes: 19 additions & 1 deletion lib/connection/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ defmodule Testcontainers.Connection do
user_agent: Constants.user_agent()
)

options = maybe_add_tls_options(options, docker_host_url)
options =
options
|> maybe_add_tls_options(docker_host_url)
|> maybe_add_unix_socket_options(docker_host_url)

{Connection.new(options), docker_host_url, docker_host}
end
Expand Down Expand Up @@ -93,6 +96,21 @@ defmodule Testcontainers.Connection do
end
end

# hackney 4 pools always connect over TCP, which breaks http+unix:// URLs
# (the socket path is resolved as a hostname). Bypass the pool for unix sockets.
defp maybe_add_unix_socket_options(options, url) do
if DockerUrl.unix_socket?(url) do
adapter_opts = [
recv_timeout: Keyword.get(options, :recv_timeout, @timeout),
pool: false
]

Keyword.put(options, :adapter, {Tesla.Adapter.Hackney, adapter_opts})
else
options
end
end

defp get_docker_host_url do
case get_docker_host() do
{:ok, docker_host} ->
Expand Down
15 changes: 14 additions & 1 deletion lib/connection/dockerurl.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
defmodule Testcontainers.DockerUrl do
@moduledoc false

@test_client Tesla.client([], Tesla.Adapter.Hackney)
# pool: false is required for http+unix:// URLs on hackney 4, see Testcontainers.Connection
@test_client Tesla.client([], {Tesla.Adapter.Hackney, pool: false})

def construct(docker_host) do
case URI.parse(docker_host) do
Expand Down Expand Up @@ -60,4 +61,16 @@ defmodule Testcontainers.DockerUrl do
end

def https?(_), do: false

@doc """
Returns true if the URL uses the `http+unix` scheme.
"""
def unix_socket?(url) when is_binary(url) do
case URI.parse(url) do
%URI{scheme: "http+unix"} -> true
_ -> false
end
end

def unix_socket?(_), do: false
end
21 changes: 13 additions & 8 deletions lib/container/minio_container.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
defmodule Testcontainers.MinioContainer do
@moduledoc """
Provides functionality for creating and managing Minio container configurations.

> #### Deprecated {: .warning}
>
> The `minio/minio` image has been removed from Docker Hub, so `new/0` raises.
> Use `Testcontainers.MinistackContainer` for an S3-compatible container instead.
"""

alias Testcontainers.Container
Expand All @@ -15,7 +20,6 @@ defmodule Testcontainers.MinioContainer do
@default_password "minioadmin"
@default_s3_port 9000
@default_ui_port 9001
@default_wait_timeout 60_000

@type t :: %__MODULE__{}

Expand All @@ -28,13 +32,14 @@ defmodule Testcontainers.MinioContainer do
reuse: false
]

def new,
do: %__MODULE__{
image: @default_image_with_tag,
username: @default_username,
password: @default_password,
wait_timeout: @default_wait_timeout
}
@deprecated "minio/minio is no longer available on Docker Hub, use Testcontainers.MinistackContainer instead"
def new do
raise ArgumentError, """
Testcontainers.MinioContainer is no longer supported: the #{@default_image_with_tag} image \
has been removed from Docker Hub. Use Testcontainers.MinistackContainer instead, which \
provides an S3-compatible API.
"""
end

@doc """
Set the reuse flag to reuse the container if it is already running.
Expand Down
Loading
Loading