-module(testcontainers_gleam@container). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/testcontainers_gleam/container.gleam"). -export([new/1, with_exposed_port/2, with_exposed_ports/2, with_fixed_port/3, with_environment/3, with_cmd/2, with_bind_mount/4, with_bind_volume/4, with_label/3, with_waiting_strategy/2, with_auto_remove/2, with_reuse/2, with_network_mode/2, with_auth/3, with_check_image/2, with_pull_policy/2, container_id/1, mapped_port/2]). -export_type([container/0, pull_policy/0, elixir_pull_policy/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Docker container configuration and builder API.\n" "\n" " Use `new` to create a container definition, then chain `with_*` functions\n" " to configure it before passing it to `testcontainers_gleam.start_container`.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " import testcontainers_gleam\n" " import testcontainers_gleam/container\n" "\n" " let c =\n" " container.new(\"redis:7.4-alpine\")\n" " |> container.with_exposed_port(6379)\n" " |> container.with_environment(\"REDIS_PASSWORD\", \"secret\")\n" "\n" " let assert Ok(running) = testcontainers_gleam.start_container(c)\n" " ```\n" ). -type container() :: any(). -type pull_policy() :: always_pull | never_pull. -type elixir_pull_policy() :: any(). -file("src/testcontainers_gleam/container.gleam", 52). ?DOC( " Create a new container definition for the given Docker image.\n" "\n" " The returned container has default configuration; use the `with_*`\n" " functions to customize it before starting.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " container.new(\"postgres:16-alpine\")\n" " ```\n" ). -spec new(binary()) -> container(). new(Image) -> 'Elixir.Testcontainers.Container':new(Image). -file("src/testcontainers_gleam/container.gleam", 59). ?DOC( " Expose a single port from the container.\n" "\n" " The port will be mapped to a random host port. Use `mapped_port`\n" " after starting to get the assigned host port.\n" ). -spec with_exposed_port(container(), integer()) -> container(). with_exposed_port(Container, Port) -> 'Elixir.Testcontainers.Container':with_exposed_port(Container, Port). -file("src/testcontainers_gleam/container.gleam", 63). ?DOC(" Expose multiple ports from the container.\n"). -spec with_exposed_ports(container(), list(integer())) -> container(). with_exposed_ports(Container, Ports) -> 'Elixir.Testcontainers.Container':with_exposed_ports(Container, Ports). -file("src/testcontainers_gleam/container.gleam", 67). ?DOC(" Expose a container `port` and bind it to a fixed `host_port`.\n"). -spec with_fixed_port(container(), integer(), integer()) -> container(). with_fixed_port(Container, Port, Host_port) -> 'Elixir.Testcontainers.Container':with_fixed_port( Container, Port, Host_port ). -file("src/testcontainers_gleam/container.gleam", 75). ?DOC(" Set an environment variable on the container.\n"). -spec with_environment(container(), binary(), binary()) -> container(). with_environment(Container, Key, Value) -> 'Elixir.Testcontainers.Container':with_environment(Container, Key, Value). -file("src/testcontainers_gleam/container.gleam", 83). ?DOC(" Set the command to run inside the container.\n"). -spec with_cmd(container(), list(binary())) -> container(). with_cmd(Container, Cmd) -> 'Elixir.Testcontainers.Container':with_cmd(Container, Cmd). -file("src/testcontainers_gleam/container.gleam", 89). ?DOC( " Mount a host path into the container.\n" "\n" " The `options` string controls mount flags (e.g. `\"ro\"` or `\"rw\"`).\n" ). -spec with_bind_mount(container(), binary(), binary(), binary()) -> container(). with_bind_mount(Container, Host_src, Dest, Options) -> 'Elixir.Testcontainers.Container':with_bind_mount( Container, Host_src, Dest, Options ). -file("src/testcontainers_gleam/container.gleam", 98). ?DOC(" Mount a named Docker volume into the container.\n"). -spec with_bind_volume(container(), binary(), binary(), boolean()) -> container(). with_bind_volume(Container, Volume, Dest, Read_only) -> 'Elixir.Testcontainers.Container':with_bind_volume( Container, Volume, Dest, Read_only ). -file("src/testcontainers_gleam/container.gleam", 107). ?DOC(" Add a label to the container.\n"). -spec with_label(container(), binary(), binary()) -> container(). with_label(Container, Key, Value) -> 'Elixir.Testcontainers.Container':with_label(Container, Key, Value). -file("src/testcontainers_gleam/container.gleam", 113). ?DOC( " Add a wait strategy to determine when the container is ready.\n" "\n" " See `testcontainers_gleam/wait_strategy` for available strategies.\n" ). -spec with_waiting_strategy( container(), testcontainers_gleam@wait_strategy:wait_strategy() ) -> container(). with_waiting_strategy(Container, Strategy) -> 'Elixir.Testcontainers.Container':with_waiting_strategy(Container, Strategy). -file("src/testcontainers_gleam/container.gleam", 120). ?DOC(" Set whether Docker should automatically remove the container when it exits.\n"). -spec with_auto_remove(container(), boolean()) -> container(). with_auto_remove(Container, Auto_remove) -> 'Elixir.Testcontainers.Container':with_auto_remove(Container, Auto_remove). -file("src/testcontainers_gleam/container.gleam", 124). ?DOC(" Enable or disable container reuse across test runs.\n"). -spec with_reuse(container(), boolean()) -> container(). with_reuse(Container, Reuse) -> 'Elixir.Testcontainers.Container':with_reuse(Container, Reuse). -file("src/testcontainers_gleam/container.gleam", 128). ?DOC(" Set the Docker network mode (e.g. `\"bridge\"`, `\"host\"`, `\"none\"`).\n"). -spec with_network_mode(container(), binary()) -> container(). with_network_mode(Container, Mode) -> 'Elixir.Testcontainers.Container':with_network_mode(Container, Mode). -file("src/testcontainers_gleam/container.gleam", 132). ?DOC(" Set registry authentication credentials for pulling the image.\n"). -spec with_auth(container(), binary(), binary()) -> container(). with_auth(Container, Username, Password) -> 'Elixir.Testcontainers.Container':with_auth(Container, Username, Password). -file("src/testcontainers_gleam/container.gleam", 140). ?DOC(" Set a check image pattern to verify the image name.\n"). -spec with_check_image(container(), binary()) -> container(). with_check_image(Container, Pattern) -> 'Elixir.Testcontainers.Container':with_check_image(Container, Pattern). -file("src/testcontainers_gleam/container.gleam", 143). ?DOC(" Set the image pull policy. Defaults to `AlwaysPull`.\n"). -spec with_pull_policy(container(), pull_policy()) -> container(). with_pull_policy(Container, Policy) -> Elixir_policy = case Policy of always_pull -> 'Elixir.Testcontainers.PullPolicy':always_pull(); never_pull -> 'Elixir.Testcontainers.PullPolicy':never_pull() end, 'Elixir.Testcontainers.Container':with_pull_policy(Container, Elixir_policy). -file("src/testcontainers_gleam/container.gleam", 158). ?DOC( " Get the container ID of a running container.\n" "\n" " Only meaningful after the container has been started.\n" "\n" " ## Panics\n" "\n" " Panics if called on a container that has not been started.\n" ). -spec container_id(container()) -> binary(). container_id(Container) -> Id@1 = case gleam@dynamic@decode:run( maps:get(erlang:binary_to_atom(<<"container_id"/utf8>>), Container), {decoder, fun gleam@dynamic@decode:decode_string/1} ) of {ok, Id} -> Id; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"testcontainers_gleam/container"/utf8>>, function => <<"container_id"/utf8>>, line => 159, value => _assert_fail, start => 5430, 'end' => 5552, pattern_start => 5441, pattern_end => 5447}) end, Id@1. -file("src/testcontainers_gleam/container.gleam", 171). ?DOC( " Get the host port mapped to an exposed container port.\n" "\n" " Returns `Ok(port)` if the mapping exists, or `Error(Nil)` if the\n" " port was not exposed or has not been mapped yet.\n" ). -spec mapped_port(container(), integer()) -> {ok, integer()} | {error, nil}. mapped_port(Container, Port) -> _pipe = 'Elixir.Testcontainers.Container':mapped_port(Container, Port), _pipe@1 = gleam@dynamic@decode:run( _pipe, {decoder, fun gleam@dynamic@decode:decode_int/1} ), gleam@result:replace_error(_pipe@1, nil).