View Source Dagger (dagger v0.12.4)
The Dagger SDK for Elixir.
Prerequisite
The SDK depends on docker and dagger commands, please make sure those
commands are presents on your PATH.
Getting Started
Let's try this script below
Mix.install([:dagger])
# 1
Application.ensure_all_started(:inets)
# 2
{:ok, client} = Dagger.connect()
# 3
{:ok, output} =
client
|> Dagger.Client.container()
|> Dagger.Container.from("hexpm/elixir:1.14.4-erlang-25.3-debian-buster-20230227-slim")
|> Dagger.Container.with_exec(["elixir", "--version"])
|> Dagger.Container.stdout()
IO.puts(output)
# 4
Dagger.close(client)Here's what script do:
- Start
:inetsapplication in order to use:httpcas a HTTP client. - Connecting to the Dagger Engine with
Dagger.connect/1. - Create a new container from
hexpm/elixir:1.14.4-erlang-25.3-debian-buster-20230227-slimand calling a commandelixirwith flag--version, get the standard output from latest command and printing it to standard output. - Close the connection.
Summary
Functions
Disconnecting the client from Dagger Engine session.
Connecting to Dagger.
When calling this function, it try to connect in ordered:
- Use session from
DAGGER_SESSION_PORTandDAGGER_SESSION_TOKENshell environment variables. - If (1) doesn't specified, it will lookup a binary defined in
_EXPERIMENTAL_DAGGER_CLI_BINand start a session. - Download the latest binary from Dagger and start a session.
Options
:workdir(String.t/0) - Sets the engine workdir.:log_output- The log device to write the progress. The default value is:stderr.:connect_timeout(timeout/0) - Sets timeout when connect to the engine. The default value is10000.:query_timeout(timeout/0) - Sets timeout when executing a query. The default value is:infinity.
Similar to connect/1 but raise exception when found an error.
Connect to Dagger Engine and close connection automatically after fun executed.
See connect/1 for available options.