Puck.Sandbox.Runtime.Template (Puck v0.2.23)

Copy Markdown View Source

Reusable sandbox configuration template.

Example

template = Puck.Sandbox.Runtime.Template.new(adapter: MyAdapter, config: %{image: "python:3.12"})
{:ok, sandbox} = Puck.Sandbox.Runtime.create(template)

# With overrides
{:ok, sandbox} = Puck.Sandbox.Runtime.create(@python_template, memory_mb: 1024)

Summary

Functions

Merges override config into template config.

Creates a new template.

Returns the backend tuple for Runtime.create/1.

Types

t()

@type t() :: %Puck.Sandbox.Runtime.Template{adapter: module(), config: map()}

Functions

merge(template, overrides)

Merges override config into template config.

Uses deep merge for nested maps, with overrides taking precedence.

Examples

template = Template.new({Docker, %{image: "python", memory_mb: 256}})
merged = Template.merge(template, %{memory_mb: 512, cpu: 2})
# => %{image: "python", memory_mb: 512, cpu: 2}

new(attrs)

Creates a new template.

Examples

# Keyword syntax
Template.new(adapter: Docker, config: %{image: "python:3.12"})

# Tuple syntax (same as Runtime.create/1)
Template.new({Docker, %{image: "python:3.12", memory_mb: 512}})
Template.new({Docker, image: "python:3.12", memory_mb: 512})

to_backend(template, overrides \\ %{})

Returns the backend tuple for Runtime.create/1.

Examples

template = Template.new({Docker, %{image: "python"}})
Template.to_backend(template)
# => {Docker, %{image: "python"}}

Template.to_backend(template, %{memory_mb: 512})
# => {Docker, %{image: "python", memory_mb: 512}}