Skip to content

Commit

Permalink
add reaper and test it
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Oct 12, 2023
1 parent ef63601 commit c6001de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
35 changes: 21 additions & 14 deletions lib/reaper.ex
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
defmodule TestcontainersElixir.Reaper do
use GenServer

@impl true
@spec init(Tesla.Env.client()) :: {:ok, DockerEngineAPI.Model.ContainerCreateResponse.t()}
def start_link(connection) do
GenServer.start_link(__MODULE__, connection)
end

def init(connection) do
request = %DockerEngineAPI.Model.ContainerCreateRequest{
Image: "testcontainers/ryuk:0.5.1",
ExposedPorts: %{"8080" => %{}},
HostConfig: %{
PortBindings: %{"8080" => [%{"HostPort" => "8080"}]},
Privileged: true,
Binds: ["/var/run/docker.sock:/var/run/docker.sock:rw"]
},
Env: ["RYUK_PORT=8080"]
}
{:ok, container} =
connection
|> DockerEngineAPI.Api.Container.container_create(
%DockerEngineAPI.Model.ContainerCreateRequest{
Image: "testcontainers/ryuk:0.5.1",
ExposedPorts: %{"8080" => %{}},
HostConfig: %{
PortBindings: %{"8080" => [%{"HostPort" => ""}]},
Privileged: true,
Binds: ["/var/run/docker.sock:/var/run/docker.sock:rw"]
},
Env: ["RYUK_PORT=8080"]
}
)

{:ok, container} =
connection |> DockerEngineAPI.Api.Container.container_start(container."Id")

{:ok, container} = connection |> DockerEngineAPI.Api.Container.container_create(request)
{:ok, container} = connection |> DockerEngineAPI.Api.Container.container_start(container."Id")
# TODO establish socket connection
# TODO send first message
# TODO return {:ok, {container, socket}} for ex
Expand Down
9 changes: 4 additions & 5 deletions lib/testcontainers_elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ defmodule TestcontainersElixir do
"""

def hello do
DockerEngineAPI.Connection.new(
base_url: "http+unix://%2Fvar%2Frun%2Fdocker.sock/v1.43"
)
|> DockerEngineAPI.Api.Image.image_list()
connection =
DockerEngineAPI.Connection.new(base_url: "http+unix://%2Fvar%2Frun%2Fdocker.sock/v1.43")
{:ok, _pid} = connection |> TestcontainersElixir.Reaper.start_link()
connection |> DockerEngineAPI.Api.Image.image_list()
end

end
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ defmodule TestcontainersElixir.MixProject do
defp deps do
[
{:ex_license, "~> 0.1.0"},
{:docker_engine_api, git: "https://github.com/jarlah/docker-engine-api-elixir.git", tag: "1.43.0.1-hackney"}
{:docker_engine_api,
git: "https://github.com/jarlah/docker-engine-api-elixir.git", tag: "1.43.0.1-hackney"}
]
end

Expand Down

0 comments on commit c6001de

Please sign in to comment.