containerbridge

package
v0.331.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package containerbridge runs external CLI tools inside Docker containers and surfaces their output as Go values. It is the shared substrate for the urh_*, firmware_extract, and fap_build Spec families — any Spec that wants to hand work off to a maintained third-party CLI without reimplementing it in Go.

Why Docker

Each external tool ships its own dependency graph (urh-ng wants Python + PyQt + scientific Python; ufbt wants the Flipper SDK + a pinned Python/clang chain; unblob wants ~30 extractor binaries). Pinning these on the host runs counter to PromptZero's "bring your own toolchain" posture. Docker images give a hermetic, version-pinned runtime that the operator can mirror to a private registry for air-gapped engagements.

Concurrency

Each Run spawns a fresh container; multiple parallel calls are safe. The package keeps no shared state — config-by-call.

Failure modes

Run returns:

  • a *RunError with .ExitCode != 0 when the container ran but the containerised tool exited non-zero (i.e. the Spec should report a tool error to the agent);
  • a wrapped error when Docker itself failed (binary missing, image pull required network, daemon unreachable). Spec handlers should surface these distinctly so the operator can fix the host toolchain.

Index

Constants

This section is empty.

Variables

View Source
var ErrDockerUnavailable = errors.New("containerbridge: docker binary not found on PATH")

ErrDockerUnavailable is returned when the docker binary cannot be invoked. Distinct from a tool-level error so callers can surface a helpful "install Docker" hint rather than a generic exec failure.

Functions

func Available

func Available() bool

Available reports whether the docker CLI is reachable. Cached after first call for the lifetime of the process — Docker's presence does not change at runtime.

Types

type Config

type Config struct {
	// Image is the docker image reference (e.g. "ghcr.io/onekey-sec/unblob:latest").
	// Required.
	Image string

	// Args are the entrypoint arguments passed to the container.
	Args []string

	// Env is the environment exposed to the container.
	Env map[string]string

	// Mounts are bind mounts from the host into the container.
	Mounts []Mount

	// Stdin streams into the container's stdin. Nil means no stdin.
	Stdin io.Reader

	// Network controls --network. Empty defaults to "none" — most tool
	// runs do not need network and the safe default avoids data
	// exfiltration risk.
	Network string

	// Timeout caps the entire run. Zero defaults to 5 minutes.
	Timeout time.Duration

	// User runs the container as a specific UID:GID. Empty leaves it
	// at the image's default. Set to e.g. "1000:1000" to match the
	// host operator and simplify volume-mounted output.
	User string

	// WorkDir sets the container working directory.
	WorkDir string

	// Sandbox extras — read-only rootfs, drop capabilities. Set true
	// for tools that don't need to mutate the rootfs (most parsers).
	ReadOnlyRootfs bool

	// AllocateTTY forces -t. Generally not needed — only set true for
	// tools that misbehave without one.
	AllocateTTY bool
}

Config describes one containerised invocation.

All fields are optional except Image. Stdin is delivered via the container's stdin pipe; large inputs are fine (the bridge does not buffer the input — it streams). Output is captured into a byte buffer to make it convenient for the calling Spec; if the tool generates hundreds of MB the caller should switch to volume-mounted output paths rather than stdout capture.

type Mount

type Mount struct {
	HostPath      string
	ContainerPath string
	ReadOnly      bool
}

Mount declares one host-path → container-path bind mount.

type RunError

type RunError struct {
	ExitCode int
	Stderr   string
}

RunError wraps a non-zero exit. errors.As works as expected.

func (*RunError) Error

func (e *RunError) Error() string

type RunResult

type RunResult struct {
	Stdout []byte
	Stderr []byte

	// ExitCode is 0 when the tool exited successfully, non-zero
	// otherwise. Always populated, even on RunError.
	ExitCode int

	// Duration is the wall-clock time the container ran.
	Duration time.Duration
}

RunResult captures the stdout/stderr of a containerised invocation.

func Run

func Run(ctx context.Context, cfg Config) (RunResult, error)

Run executes one container according to cfg.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL