diff --git a/gleam.toml b/gleam.toml deleted file mode 100644 index cadc3b6..0000000 --- a/gleam.toml +++ /dev/null @@ -1,2 +0,0 @@ -name = "testcontainers_elixir" -dependencies = { gleam_stdlib = "~> 0.31", gleam_http = "~> 3.5", gleam_hackney = "~> 1.1"} diff --git a/lib/testcontainers_elixir.ex b/lib/testcontainers_elixir.ex index e61b7c5..0b2173a 100644 --- a/lib/testcontainers_elixir.ex +++ b/lib/testcontainers_elixir.ex @@ -5,8 +5,29 @@ defmodule TestcontainersElixir do """ def hello do - :hello.parse_docker_host(System.get_env("DOCKER_HOST", "")) - |> IO.inspect() - :hello.fetch_hello("world") + DockerEngineAPI.Connection.new( + base_url: base_url() + ) + |> DockerEngineAPI.Api.Image.image_list() end + + @socket_path "unix:///var/run/docker.sock" + @default_version "v1.43" + + defp base_url() do + host = Application.get_env(:docker, :host) || System.get_env("DOCKER_HOST", @socket_path) + version = + case Application.get_env(:docker, :version) do + nil -> @default_version + version -> version + end + + + "#{normalize_host(host)}/#{version}" + |> String.trim_trailing("/") + end + + defp normalize_host("tcp://" <> host), do: "http://" <> host + defp normalize_host("unix://" <> host), do: "http+unix://" <> URI.encode_www_form(host) + end diff --git a/manifest.toml b/manifest.toml deleted file mode 100644 index 96624ab..0000000 --- a/manifest.toml +++ /dev/null @@ -1,21 +0,0 @@ -# This file was generated by Gleam -# You typically do not need to edit this file - -packages = [ - { name = "certifi", version = "2.12.0", build_tools = ["rebar3"], requirements = [], otp_app = "certifi", source = "hex", outer_checksum = "EE68D85DF22E554040CDB4BE100F33873AC6051387BAF6A8F6CE82272340FF1C" }, - { name = "gleam_hackney", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_http", "hackney", "gleam_stdlib"], otp_app = "gleam_hackney", source = "hex", outer_checksum = "CA69AD9061C4A8775A7BD445DE33ECEFD87379AF8E5B028F3DD0216BECA5DD0B" }, - { name = "gleam_http", version = "3.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "FAE9AE3EB1CA90C2194615D20FFFD1E28B630E84DACA670B28D959B37BCBB02C" }, - { name = "gleam_stdlib", version = "0.31.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "6D1BC5B4D4179B9FEE866B1E69FE180AC2CE485AD90047C0B32B2CA984052736" }, - { name = "hackney", version = "1.20.0", build_tools = ["rebar3"], requirements = ["parse_trans", "ssl_verify_fun", "unicode_util_compat", "idna", "certifi", "metrics", "mimerl"], otp_app = "hackney", source = "hex", outer_checksum = "8CEE84C3BBE32F148D45806F8084537E8B181F70C9BF69814FC24105F5B04FB6" }, - { name = "idna", version = "6.1.1", build_tools = ["rebar3"], requirements = ["unicode_util_compat"], otp_app = "idna", source = "hex", outer_checksum = "92376EB7894412ED19AC475E4A86F7B413C1B9FBB5BD16DCCD57934157944CEA" }, - { name = "metrics", version = "1.0.1", build_tools = ["rebar3"], requirements = [], otp_app = "metrics", source = "hex", outer_checksum = "69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16" }, - { name = "mimerl", version = "1.2.0", build_tools = ["rebar3"], requirements = [], otp_app = "mimerl", source = "hex", outer_checksum = "F278585650AA581986264638EBF698F8BB19DF297F66AD91B18910DFC6E19323" }, - { name = "parse_trans", version = "3.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "parse_trans", source = "hex", outer_checksum = "620A406CE75DADA827B82E453C19CF06776BE266F5A67CFF34E1EF2CBB60E49A" }, - { name = "ssl_verify_fun", version = "1.1.7", build_tools = ["mix", "rebar3", "make"], requirements = [], otp_app = "ssl_verify_fun", source = "hex", outer_checksum = "FE4C190E8F37401D30167C8C405EDA19469F34577987C76DDE613E838BBC67F8" }, - { name = "unicode_util_compat", version = "0.7.0", build_tools = ["rebar3"], requirements = [], otp_app = "unicode_util_compat", source = "hex", outer_checksum = "25EEE6D67DF61960CF6A794239566599B09E17E668D3700247BC498638152521" }, -] - -[requirements] -gleam_hackney = { version = "~> 1.1" } -gleam_http = { version = "~> 3.5" } -gleam_stdlib = { version = "~> 0.31" } diff --git a/mix.exs b/mix.exs index 14faa4a..81195ad 100644 --- a/mix.exs +++ b/mix.exs @@ -1,4 +1,4 @@ -defmodule Meetup.MixProject do +defmodule TestcontainersElixir.MixProject do use Mix.Project @app :testcontainers_elixir @@ -9,20 +9,7 @@ defmodule Meetup.MixProject do app: @app, version: @version, elixir: "~> 1.15", - elixirc_paths: elixirc_paths(Mix.env()), name: "#{@app}", - archives: [mix_gleam: "~> 0.6.1"], - compilers: [:gleam | Mix.compilers()], - aliases: [ - "deps.get": ["deps.get", "gleam.deps.get"] - ], - erlc_paths: [ - "build/dev/erlang/#{@app}/_gleam_artefacts", - # For Gleam < v0.25.0 - "build/dev/erlang/#{@app}/build" - ], - erlc_include_path: "build/dev/erlang/#{@app}/include", - start_permanent: Mix.env() == :prod, aliases: aliases(), deps: deps() ] @@ -37,20 +24,13 @@ defmodule Meetup.MixProject do ] end - # Specifies which paths to compile per environment. - # , "test/support"] - defp elixirc_paths(:test), do: ["lib"] - defp elixirc_paths(_), do: ["lib"] - # Specifies your project dependencies. # # Type `mix help deps` for examples and options. defp deps do [ - {:mix_gleam, "~> 0.6"}, - {:gleam_hackney, "~> 1.1"}, - {:gleam_http, "~> 3.5"}, - {:ex_license, "~> 0.1.0"} + {:ex_license, "~> 0.1.0"}, + {:docker_engine_api, git: "https://github.com/jarlah/docker-engine-api.git", tag: "1.43.0-hackney"} ] end diff --git a/mix.lock b/mix.lock index afc3067..d698123 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,8 @@ %{ "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"}, + "docker": {:git, "https://github.com/hexedpackets/docker-elixir.git", "b4f8b929691ce2bf9f11743def49009de460431b", [tag: "0.4.0"]}, + "docker_api": {:git, "https://github.com/hexedpackets/docker-elixir.git", "b4f8b929691ce2bf9f11743def49009de460431b", [tag: "0.4.0"]}, + "docker_engine_api": {:git, "https://github.com/jarlah/docker-engine-api.git", "12247693d92eaa48d4470648508762ff98bf9680", [tag: "1.43.0-hackney"]}, "ex_license": {:hex, :ex_license, "0.1.1", "bbdaba704f861894da3ae80e4399984379f19de1cca4ecf7d799616c832b8821", [:mix], [], "hexpm", "dd95aaaba0c9c6f0e9be2db3e9fac0bf69784557e04f700f94e90629f5e24e1d"}, "gleam_fetch": {:hex, :gleam_fetch, "0.2.1", "ae5b960e62858354e1f075d6c857730648218b18ef1f13b5dc93f15e109767ca", [:gleam], [{:gleam_http, "~> 3.1", [hex: :gleam_http, repo: "hexpm", optional: false]}, {:gleam_javascript, "~> 0.3", [hex: :gleam_javascript, repo: "hexpm", optional: false]}, {:gleam_stdlib, "~> 0.31", [hex: :gleam_stdlib, repo: "hexpm", optional: false]}], "hexpm", "f64e93c754d948b2d37abc4add5482fe0faed4b99c79e66012dde96bedc40544"}, "gleam_hackney": {:hex, :gleam_hackney, "1.1.0", "f6b1e413490b0214f0f1c3f2a8d720ee2149329e18a632d91c5657bbe3aad964", [:gleam], [{:gleam_http, "~> 3.0", [hex: :gleam_http, repo: "hexpm", optional: false]}, {:gleam_stdlib, "~> 0.18", [hex: :gleam_stdlib, repo: "hexpm", optional: false]}, {:hackney, "~> 1.18", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "ca69ad9061c4a8775a7bd445de33ecefd87379af8e5b028f3dd0216beca5dd0b"}, @@ -7,12 +10,16 @@ "gleam_javascript": {:hex, :gleam_javascript, "0.6.1", "11905461026750b61177ca911e87b49edff6e2384c98c4d78d074029f8fd83e8", [:gleam], [{:gleam_stdlib, "~> 0.19", [hex: :gleam_stdlib, repo: "hexpm", optional: false]}], "hexpm", "bfebb63abe4a1694e07defd19b160c2980304b5d775a89d4b02e7de7c9d8008b"}, "gleam_stdlib": {:hex, :gleam_stdlib, "0.31.0", "128cbff56a6a5fd4b53b6eafb2d87a8b53ce00957bc27789055d9e53eff88118", [:gleam], [], "hexpm", "6d1bc5b4d4179b9fee866b1e69fe180ac2ce485ad90047c0b32b2ca984052736"}, "gleeunit": {:hex, :gleeunit, "0.11.0", "2008028d27f2fec9c055883a9f100dd1672584e583c7386ee67b5aeae263520f", [:gleam], [{:gleam_stdlib, "~> 0.27", [hex: :gleam_stdlib, repo: "hexpm", optional: false]}], "hexpm", "1397e5c4ac4108769ee979939ac39bf7870659c5afb714630deeee16b8272ad5"}, - "hackney": {:hex, :hackney, "1.20.0", "299bb56c21d08dbf86da44a9733eb926062a00045b5ba4912f5d209b36f3f418", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "8cee84c3bbe32f148d45806f8084537e8b181f70c9bf69814fc24105f5b04fb6"}, + "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, + "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, + "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, "mix_gleam": {:hex, :mix_gleam, "0.6.1", "d701fb4f9d97c786c09910f71a5441a11ef435fc09eeed67e60e90c2c92f21cf", [:mix], [], "hexpm", "3db42d762fa9bbff1cb69f57ba3f2063130742b6b5a7ab06759cc45f2c8f74ab"}, "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, + "poison": {:hex, :poison, "5.0.0", "d2b54589ab4157bbb82ec2050757779bfed724463a544b6e20d79855a9e43b24", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "11dc6117c501b80c62a7594f941d043982a1bd05a1184280c0d9166eb4d8d3fc"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, + "tesla": {:hex, :tesla, "1.7.0", "a62dda2f80d4f8a925eb7b8c5b78c461e0eb996672719fe1a63b26321a5f8b4e", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.13", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:msgpax, "~> 2.3", [hex: :msgpax, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2e64f01ebfdb026209b47bc651a0e65203fcff4ae79c11efb73c4852b00dc313"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, } diff --git a/src/hello.gleam b/src/hello.gleam deleted file mode 100644 index c01176d..0000000 --- a/src/hello.gleam +++ /dev/null @@ -1,53 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -import gleam/hackney -import gleam/http/request -import gleam/uri -import gleam/option.{None, Option, Some, unwrap} - -pub fn fetch_hello(name: String) -> String { - let assert Ok(request) = - request.to("https://test-api.service.hmrc.gov.uk/hello/" <> name) - - let assert Ok(response) = - request - |> request.prepend_header("accept", "application/vnd.hmrc.1.0+json") - |> hackney.send - - response.body -} - -pub type DockerHost { - DockerHost( - scheme: String, - socket_host: Option(String), - socket_port: Option(Int), - host: Option(String), - port: Option(Int), - ) -} - -// a function to parse DOCKER_HOST env var value -// will crash if provided with nil String for docker_host -pub fn parse_docker_host(docker_host: String) -> Option(DockerHost) { - let assert Ok(uri) = uri.parse(docker_host) - let assert scheme = unwrap(uri.scheme, "no scheme") - case scheme { - "tcp" | "http" -> - Some(DockerHost( - scheme: scheme, - socket_host: None, - socket_port: None, - host: uri.host, - port: uri.port, - )) - "unix" | "npipe" -> - Some(DockerHost( - scheme: scheme, - socket_host: Some("localhost"), - socket_port: Some(2375), - host: uri.host, - port: uri.port, - )) - _ -> None - } -} diff --git a/test/test_helper.exs b/test/test_helper.exs index c0ec306..869559e 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,2 +1 @@ -# do i need this file? ExUnit.start() diff --git a/test/testcontainers_elixir_test.exs b/test/testcontainers_elixir_test.exs index ed1ed2e..f957ab9 100644 --- a/test/testcontainers_elixir_test.exs +++ b/test/testcontainers_elixir_test.exs @@ -3,6 +3,7 @@ defmodule TestcontainersElixirTest do doctest TestcontainersElixir test "greets the world" do - assert TestcontainersElixir.hello() == "{\"message\":\"Hello World\"}" + {:ok, list} = TestcontainersElixir.hello() + assert is_number(length(list)) end end