The following two features were added to erlexec.
Container: exec:run_container/1: run a command in a container
You describe the container in a map, and erlexec builds the podman or docker command line and runs it:
exec:run_container(#{
image => "alpine:3.20",
command => "echo hello",
env => #{"FOO" => "bar"},
volumes => [{"/tmp", "/work", "ro"}],
ports => [{"127.0.0.1", 8080, 80}],
cpu_limit => "500m",
memory_limit => "256M",
timeout => 5000
}).
- The runtime defaults to
auto, which preferspodmanand falls back todocker. You can also name one explicitly or give a path to an executable. - Runtime paths are cached in
persistent_term. A cached path that no longer exists is dropped and looked up again. removedefaults totrue, so containers are removed when they exit.timeoutuses the normal exec timeout. Onlyon_timeout => killis supported.exec_optionspasses extra options through toexec:run_link/2.
The full list of spec keys is in the exec_container module docs.
Graph: exec:run_graph/2: run a pipeline of commands
A graph is a list of tasks. Each task’s stdout or stderr can be routed to another task’s stdin, to one or more tasks, or to a file:
Graph = [
#{id => producer,
cmd => "printf 'a\nb\nc\n'",
stdout => [filter],
#{id => filter,
cmd => "grep '^b$'"}
],
{ok, [{stdout, [<<"b\n">>]}]} = exec:run_graph(Graph, [sync, stdout]).
syncblocks the caller and returns the collected output. Without it,run_graph/2returns{ok, Worker, GraphOsPid}and sends messages to the caller.- In async mode,
monitorreports when the whole graph finishes, andtask_monitorreports each task as it finishes. - A per-task
timeoutcan be set in the task map.timeoutin the graph options limits the whole graph’s run time. statsreturns resource usage per task.- Options that aren’t graph-specific, such as
timeoutandstats, are passed to every task.
Feedback is welcome, especially on the graph options and the container spec keys. If you try either one, tell me what didn’t behave as you expected.