Package Version Hex Docs Erlang-compatible JavaScript-compatible

Melon 🍈

A Gleam library for running containers tailored to testing purposes.

Melon is inspired by Testcontainers and provides an API to configure, start and stop containers.

In contrast to other libraries, Melon doesn’t use the Docker Engine API, but simply searches for and uses the docker executable. This makes the discovery methods used by other libraries unnecessary. You can still use a remote Docker Engine by configuring a context accordingly.

This approach also makes it possible to support all non-browser targets (Erlang, Bun, Deno, and Node.js) without further dependencies, as consumers of this library don’t need to reach for a target-specific client like fetch and httpc in order to communicate with the Docker Engine API.

Demo 🍈

import gleam/io
import melon/container.{Megabyte, Port, Tcp}

pub fn main() {
  let start_result =
    container.new("postgres:16.3-alpine3.20")
    |> container.set_memory_limit(limit: "256", unit: Megabyte)
    |> container.add_exposed_port(
      host: "127.0.0.1",
      port: "5432",
      protocol: Tcp,
    )
    |> container.add_env(name: "POSTGRES_USER", value: "postgres")
    |> container.add_env(name: "POSTGRES_DB", value: "morty_smith")
    |> container.add_env(name: "POSTGRES_PASSWORD", value: "rick_sanchez")
    |> container.start()

  case start_result {
    Error(_) -> io.println("Couldn't start the container :(")
    Ok(container) -> {
      case container.mapped_port(container, port: "5432", protocol: Tcp) {
        Error(_) -> io.println("Couldn't find the mapped port :<")
        Ok(Port(host, port, _)) ->
          io.println(
            "The database is available on " <> host <> ":" <> port <> ".",
          )
      }
    }
  }
}

Changelog 🍈

Take a look at the changelog to get an overview of each release and its changes.

Contribution Guidelines 🍈

More information can be found here.

License 🍈

Melon is licensed under the MIT license.

✨ Search Document