ExDaytona.Image (ex_daytona v0.4.0)

Copy Markdown View Source

Declarative image definitions for building sandboxes (and snapshots) from a Dockerfile instead of a prebuilt snapshot.

image =
  ExDaytona.Image.from("ubuntu:22.04")
  |> ExDaytona.Image.run("apt-get update && apt-get install -y curl git")
  |> ExDaytona.Image.env(%{"LANG" => "C.UTF-8"})
  |> ExDaytona.Image.workdir("/workspace")

{:ok, sandbox} = ExDaytona.Sandbox.create(client, image: image)

# Watch the build as it happens
ExDaytona.Sandbox.stream_build_logs(sandbox, &IO.write/1)

A raw Dockerfile works too — ExDaytona.Sandbox.create/2 accepts image: "FROM ubuntu:22.04\n..." directly, and raw/1 wraps one in an %ExDaytona.Image{}.

Local files go in via add_local_file/3 and add_local_dir/3 — they become COPY instructions backed by a build context that ExDaytona.Sandbox.create/2 uploads to Daytona's object storage automatically:

image =
  ExDaytona.Image.from("elixir:1.20-alpine")
  |> ExDaytona.Image.add_local_file("mix.exs", "/workspace/mix.exs")
  |> ExDaytona.Image.add_local_dir("config", "/workspace/config")

The rest of the DSL covers context-free instructions (RUN, ENV, WORKDIR, USER, LABEL, EXPOSE, ENTRYPOINT, CMD) plus instruction/2 as an escape hatch for anything else.

Summary

Types

A local build context: uploaded before the build, COPY-able in it.

t()

Functions

Copy a local directory (recursively) into the image at remote_path. Uploaded as a build context when the sandbox is created.

Copy a local file into the image at remote_path (a trailing / keeps the file's name). The file is uploaded as a build context when the sandbox is created.

The ExDaytona.Model.CreateBuildInfo for this image — what ExDaytona.Sandbox.create/2 sends when given image:, and what the low-level snapshot API takes as buildInfo.

Set the CMD (exec form).

Render the definition to Dockerfile content.

Set the ENTRYPOINT (exec form).

Append ENV instructions from a map.

Append an EXPOSE instruction.

Start an image definition from a base image reference.

Append an arbitrary Dockerfile instruction line — the escape hatch for anything the DSL doesn't cover.

Append a LABEL instruction.

Wrap a complete raw Dockerfile.

Append a RUN instruction.

Append a USER instruction.

Append a WORKDIR instruction.

Types

context()

@type context() :: %{source_path: String.t(), archive_path: String.t()}

A local build context: uploaded before the build, COPY-able in it.

t()

@type t() :: %ExDaytona.Image{
  base: String.t() | nil,
  contexts: [context()],
  instructions: [String.t()],
  raw: String.t() | nil
}

Functions

add_local_dir(image, local_path, remote_path)

@spec add_local_dir(t(), Path.t(), String.t()) :: t()

Copy a local directory (recursively) into the image at remote_path. Uploaded as a build context when the sandbox is created.

add_local_file(image, local_path, remote_path)

@spec add_local_file(t(), Path.t(), String.t()) :: t()

Copy a local file into the image at remote_path (a trailing / keeps the file's name). The file is uploaded as a build context when the sandbox is created.

Raises ArgumentError if the path does not exist or is not a regular file — fail at definition time, not at build time.

build_info(image)

@spec build_info(t() | String.t()) :: ExDaytona.Model.CreateBuildInfo.t()

The ExDaytona.Model.CreateBuildInfo for this image — what ExDaytona.Sandbox.create/2 sends when given image:, and what the low-level snapshot API takes as buildInfo.

cmd(image, argv)

@spec cmd(t(), [String.t()]) :: t()

Set the CMD (exec form).

dockerfile(dockerfile)

@spec dockerfile(t() | String.t()) :: String.t()

Render the definition to Dockerfile content.

entrypoint(image, argv)

@spec entrypoint(t(), [String.t()]) :: t()

Set the ENTRYPOINT (exec form).

env(image, vars)

@spec env(t(), %{optional(String.t()) => String.t()}) :: t()

Append ENV instructions from a map.

expose(image, port)

@spec expose(t(), pos_integer()) :: t()

Append an EXPOSE instruction.

from(base)

@spec from(String.t()) :: t()

Start an image definition from a base image reference.

instruction(image, line)

@spec instruction(t(), String.t()) :: t()

Append an arbitrary Dockerfile instruction line — the escape hatch for anything the DSL doesn't cover.

label(image, key, value)

@spec label(t(), String.t(), String.t()) :: t()

Append a LABEL instruction.

raw(dockerfile)

@spec raw(String.t()) :: t()

Wrap a complete raw Dockerfile.

run(image, command)

@spec run(t(), String.t()) :: t()

Append a RUN instruction.

user(image, name)

@spec user(t(), String.t()) :: t()

Append a USER instruction.

workdir(image, dir)

@spec workdir(t(), String.t()) :: t()

Append a WORKDIR instruction.