engineutil

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 101 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DaggerSessionIDEnv       = "_DAGGER_SESSION_ID"
	DaggerClientIDEnv        = "_DAGGER_NESTED_CLIENT_ID"
	DaggerCallDigestEnv      = "_DAGGER_CALL_DIGEST"
	DaggerEngineVersionEnv   = "_DAGGER_ENGINE_VERSION"
	DaggerRedirectStdinEnv   = "_DAGGER_REDIRECT_STDIN"
	DaggerRedirectStdoutEnv  = "_DAGGER_REDIRECT_STDOUT"
	DaggerRedirectStderrEnv  = "_DAGGER_REDIRECT_STDERR"
	DaggerHostnameAliasesEnv = "_DAGGER_HOSTNAME_ALIASES"
	DaggerNoInitEnv          = "_DAGGER_NOINIT"

	DaggerSessionPortEnv  = "DAGGER_SESSION_PORT"
	DaggerSessionTokenEnv = "DAGGER_SESSION_TOKEN"
	DaggerEngineNumCPUEnv = "DAGGER_ENGINE_NUM_CPU"

	DaggerQemuEmulatorMountPoint = "/dev/.dagger_qemu_emulator"
)
View Source
const (
	// Exec errors will only include the last this number of bytes of output.
	MaxExecErrorOutputBytes = 100 * 1024

	// TruncationMessage is the message that will be prepended to truncated output.
	TruncationMessage = "[omitting %d bytes]..."

	// MaxFileContentsChunkSize sets the maximum chunk size for ReadFile calls
	// Equals around 95% of the max message size (4MB) in
	// order to keep space for any Protocol Buffers overhead:
	MaxFileContentsChunkSize = 3984588

	// MaxFileContentsSize sets the limit of the maximum file size
	// that can be retrieved using File.Contents, currently set to 128MB:
	MaxFileContentsSize = 128 << 20

	// MetaMountDestPath is the special path that the shim writes metadata to.
	MetaMountDestPath           = "/.dagger_meta_mount"
	MetaMountExitCodePath       = "exitCode"
	MetaMountStdoutPath         = "stdout"
	MetaMountStderrPath         = "stderr"
	MetaMountCombinedOutputPath = "combinedOutput"
)
View Source
const InstrumentationLibrary = "dagger.io/engine.buildkit"

Variables

View Source
var SkipInputs = fmt.Errorf("skip inputs") //nolint:staticcheck // Err prefix isn't convention for Walk control errors

Functions

func NewSecretScrubReader

func NewSecretScrubReader(
	r io.Reader,
	env []string,
	secretEnvs []string,
	secretFiles []string,
) (io.Reader, error)

func ReadSnapshotPath

func ReadSnapshotPath(ctx context.Context, c *Client, mntable bkcache.MountableRef, filePath string, limit int) ([]byte, error)

func RunInNetNS

func RunInNetNS[T any](
	ctx context.Context,
	c *Client,
	ns Namespaced,
	fn func() (T, error),
) (T, error)

func ShutdownGlobalNamespaceWorkerPool

func ShutdownGlobalNamespaceWorkerPool()

ShutdownGlobalNamespaceWorkerPool gracefully shuts down the global namespace worker pool This should be called during application shutdown

func StateIdx

func StateIdx(ctx context.Context, st llb.State, idx solverpb.OutputIndex, c *llb.Constraints) llb.State

func Tracer

func Tracer(ctx context.Context) trace.Tracer

Types

type BlobOp

type BlobOp struct {
	*OpDAG
	*pb.SourceOp
}

func (*BlobOp) Digest

func (op *BlobOp) Digest() (digest.Digest, error)

type Client

type Client struct {
	*Opts
	// contains filtered or unexported fields
}

Client is dagger's internal engine utility client

func NewClient

func NewClient(ctx context.Context, opts *Opts) (*Client, error)

func (*Client) AbsPath

func (c *Client) AbsPath(ctx context.Context, path string) (string, error)

Return the absolute path of the given path as calculated by the caller's host using OS-specific rules.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, id string, process executor.ProcessInfo) (err error)

func (*Client) ExportContainerImage

func (c *Client) ExportContainerImage(
	ctx context.Context,
	destPath string,
	inputByPlatform map[string]ContainerExport,
	forceCompression string,
	tarExport bool,
	_ string,
	useOCIMediaTypes bool,
) (*imageexport.ExportResponse, error)

func (*Client) GetCredential

func (c *Client) GetCredential(ctx context.Context, protocol, host, path string) (*git.CredentialInfo, error)

func (*Client) GetGitConfig

func (c *Client) GetGitConfig(ctx context.Context) ([]*git.GitConfigEntry, error)

func (*Client) GetSessionCaller

func (c *Client) GetSessionCaller(ctx context.Context) (_ SessionCaller, rerr error)

func (*Client) IOReaderExport

func (c *Client) IOReaderExport(ctx context.Context, r io.Reader, destPath string, destMode os.FileMode) (rerr error)

IOReaderExport exports the contents of an io.Reader to the caller's local fs as a file TODO: de-dupe this with the above method to extent possible

func (*Client) ListenHostToContainer

func (c *Client) ListenHostToContainer(
	ctx context.Context,
	hostListenAddr, proto, upstream string,
) (*h2c.ListenResponse, func() error, error)

func (*Client) LocalDirExport

func (c *Client) LocalDirExport(
	ctx context.Context,
	srcPath string,
	destPath string,
	merge bool,
	removePaths []string,
) (rerr error)

func (*Client) LocalFileExport

func (c *Client) LocalFileExport(
	ctx context.Context,
	srcPath string,
	filePath string,
	destPath string,
	allowParentDirPath bool,
) (rerr error)

func (*Client) NewNetworkNamespace

func (c *Client) NewNetworkNamespace(ctx context.Context, hostname string) (Namespaced, error)

func (*Client) OpenPipe

func (c *Client) OpenPipe(
	ctx context.Context,
) (io.ReadWriteCloser, error)

func (*Client) OpenTerminal

func (c *Client) OpenTerminal(
	ctx context.Context,
) (*TerminalClient, error)

func (*Client) PromptAllowLLM

func (c *Client) PromptAllowLLM(ctx context.Context, moduleRepoURL string) error

func (*Client) PromptHumanHelp

func (c *Client) PromptHumanHelp(ctx context.Context, title, question string) (string, error)

func (*Client) PublishContainerImage

func (c *Client) PublishContainerImage(
	ctx context.Context,
	inputByPlatform map[string]ContainerExport,
	refName string,
	useOCIMediaTypes bool,
	forceCompression string,
) (*imageexport.ExportResponse, error)

func (*Client) ReadCallerHostFile

func (c *Client) ReadCallerHostFile(ctx context.Context, path string) ([]byte, error)

func (*Client) ReadImage

func (c *Client) ReadImage(
	ctx context.Context,
	name string,
) (*ImageReader, error)

func (*Client) Run

func (c *Client) Run(
	ctx context.Context,
	id string,
	rootMount executor.Mount,
	mounts []executor.Mount,
	procInfo executor.ProcessInfo,
	started chan<- struct{},
	causeCtx trace.SpanContext,
	execMD *ExecutionMetadata,
	sessionID string,
	callerClientID string,
	nestedClientMetadata *engine.ClientMetadata,
	nestedClientModule dagql.AnyObjectResult,
	nestedClientFunctionCall dagql.Typed,
	nestedClientEnv dagql.AnyObjectResult,
) (rerr error)

func (*Client) StatCallerHostPath

func (c *Client) StatCallerHostPath(ctx context.Context, path string, returnAbsPath bool) (*fsutiltypes.Stat, error)

func (*Client) WriteContainerImageTarball

func (c *Client) WriteContainerImageTarball(
	ctx context.Context,
	w io.Writer,
	inputByPlatform map[string]ContainerExport,
	useOCIMediaTypes bool,
	forceCompression string,
) error

func (*Client) WriteImage

func (c *Client) WriteImage(
	ctx context.Context,
	name string,
) (*ImageWriter, error)

type ContainerExport

type ContainerExport struct {
	Ref         bkcache.ImmutableRef
	Config      dockerspec.DockerOCIImageConfig
	Annotations []containerutil.ContainerAnnotation
}

type DiffOp

type DiffOp struct {
	*OpDAG
	*pb.DiffOp
}

type ExecOp

type ExecOp struct {
	*OpDAG
	*pb.ExecOp
}

func (*ExecOp) Input

func (exec *ExecOp) Input(i pb.InputIndex) *OpDAG

func (*ExecOp) OutputMount

func (exec *ExecOp) OutputMount() *pb.Mount

func (*ExecOp) OutputMountBase

func (exec *ExecOp) OutputMountBase() *OpDAG

type ExecutionMetadata

type ExecutionMetadata struct {
	// Internal execution initiated by dagger and not the user.
	// Used when executing the module runtime itself.
	Internal bool

	// UseRecipeIDsByDefault configures nested clients started by this exec to
	// resolve id() as recipe-form IDs unless explicitly requested otherwise.
	UseRecipeIDsByDefault bool

	CallDigest digest.Digest

	// hostname -> list of aliases
	HostAliases map[string][]string
	// search domains to install prior to the session's domain
	ExtraSearchDomains []string

	RedirectStdinPath  string
	RedirectStdoutPath string
	RedirectStderrPath string

	SecretEnvNames  []string
	SecretFilePaths []string

	SystemEnvNames []string

	EnabledGPUs []string

	// If true, skip injecting dagger-init into the container.
	NoInit bool
}

type FileOp

type FileOp struct {
	*OpDAG
	*pb.FileOp
}

type GitOp

type GitOp struct {
	*OpDAG
	*pb.SourceOp
}

type GlobalNamespaceWorkerPool

type GlobalNamespaceWorkerPool struct {
	// contains filtered or unexported fields
}

GlobalNamespaceWorkerPool manages a global pool of workers that can enter different namespace contexts based on PID and namespace type

func GetGlobalNamespaceWorkerPool

func GetGlobalNamespaceWorkerPool() *GlobalNamespaceWorkerPool

GetGlobalNamespaceWorkerPool returns the singleton global namespace worker pool

func (*GlobalNamespaceWorkerPool) RunInNamespaces

func (gwp *GlobalNamespaceWorkerPool) RunInNamespaces(ctx context.Context, containerID string, namespaces []specs.LinuxNamespace, fn func() error) error

RunInNamespaces executes a function in the context of specific namespaces for a given PID

func (*GlobalNamespaceWorkerPool) Start

func (gwp *GlobalNamespaceWorkerPool) Start()

Start initializes and starts the global worker pool

func (*GlobalNamespaceWorkerPool) Stop

func (gwp *GlobalNamespaceWorkerPool) Stop()

Stop gracefully shuts down the global worker pool

func (*GlobalNamespaceWorkerPool) SubmitJob

func (gwp *GlobalNamespaceWorkerPool) SubmitJob(ctx context.Context, job *NamespaceJob) error

SubmitJob submits a job to be executed in the specified namespace context

type HTTPOp

type HTTPOp struct {
	*OpDAG
	*pb.SourceOp
}

type ImageOp

type ImageOp struct {
	*OpDAG
	*pb.SourceOp
}

type ImageReader

type ImageReader struct {
	Tarball io.ReadCloser

	ContentStore content.Store
	ImagesStore  images.Store
	LeaseManager leases.Manager
}

type ImageWriter

type ImageWriter struct {
	Tarball io.WriteCloser

	ContentStore content.Store
	ImagesStore  images.Store
	LeaseManager leases.Manager
}

type LocalOp

type LocalOp struct {
	*OpDAG
	*pb.SourceOp
}

type MergeOp

type MergeOp struct {
	*OpDAG
	*pb.MergeOp
}

type NamespaceJob

type NamespaceJob struct {
	Container  string                 // Container whose namespaces to enter
	Namespaces []specs.LinuxNamespace // Namespaces to enter (e.g., network, mount, etc.)
	Fn         func() error           // Function to execute
	ResultCh   chan error             // Channel to send result back
}

NamespaceJob represents a job to be executed in a specific namespace context

type Namespaced

type Namespaced interface {
	NamespaceID() string
	Release(context.Context) error
}

Namespaced is something that has Linux namespaces set up. Currently this is either a full-blown container or just a raw network namespace that's setns'd into to support service tunneling and similar.

func NewDirectNS

func NewDirectNS(id string) Namespaced

NewDirectNS creates a namespace, that's externally managed.

type OCIOp

type OCIOp struct {
	*OpDAG
	*pb.SourceOp
}

type OpDAG

type OpDAG struct {
	*pb.Op                  // the root of the DAG
	OpDigest *digest.Digest // the digest of this root, common across all outputIndexes for this root
	Metadata *pb.OpMetadata // metadata for the root
	Inputs   []*OpDAG       // the inputs to the root
	// contains filtered or unexported fields
}

func DefToDAG

func DefToDAG(def *pb.Definition) (*OpDAG, error)

func (*OpDAG) AsBlob

func (dag *OpDAG) AsBlob() (*BlobOp, bool)

func (*OpDAG) AsDiff

func (dag *OpDAG) AsDiff() (*DiffOp, bool)

func (*OpDAG) AsExec

func (dag *OpDAG) AsExec() (*ExecOp, bool)

func (*OpDAG) AsFile

func (dag *OpDAG) AsFile() (*FileOp, bool)

func (*OpDAG) AsGit

func (dag *OpDAG) AsGit() (*GitOp, bool)

func (*OpDAG) AsHTTP

func (dag *OpDAG) AsHTTP() (*HTTPOp, bool)

func (*OpDAG) AsImage

func (dag *OpDAG) AsImage() (*ImageOp, bool)

func (*OpDAG) AsLocal

func (dag *OpDAG) AsLocal() (*LocalOp, bool)

func (*OpDAG) AsMerge

func (dag *OpDAG) AsMerge() (*MergeOp, bool)

func (*OpDAG) AsOCI

func (dag *OpDAG) AsOCI() (*OCIOp, bool)

func (*OpDAG) EffectID

func (dag *OpDAG) EffectID() string

func (*OpDAG) Marshal

func (dag *OpDAG) Marshal() (*pb.Definition, error)

Marshal will convert the dag back to a flat pb.Definition, updating all digests based on any modifications made to the dag.

func (*OpDAG) OutputIndex

func (dag *OpDAG) OutputIndex() pb.OutputIndex

OutputIndex returns the specific output of this op represented by this OpDAG instance.

func (*OpDAG) String

func (dag *OpDAG) String() string

func (*OpDAG) Walk

func (dag *OpDAG) Walk(f func(*OpDAG) error) error

type Opts

type Opts struct {
	ID               string
	Labels           map[string]string
	Platforms        []ocispecs.Platform
	NetworkProviders map[pb.NetMode]network.Provider
	Snapshotter      bkcache.Snapshotter
	ContentStore     *containerdsnapshot.Store
	Applier          diff.Applier
	Differ           diff.Comparer
	IdentityMapping  *idtools.IdentityMapping

	ExecutorRoot    string
	TelemetryPubSub http.Handler
	SessionHandler  sessionHandler

	Runc                *runc.Runc
	DefaultCgroupParent string
	ProcessMode         oci.ProcessMode
	DNSConfig           *oci.DNSConfig
	ApparmorProfile     string
	SELinux             bool
	Entitlements        entitlements.Set

	HostMntNS  *os.File
	CleanMntNS *os.File

	Dialer               *net.Dialer
	GetClientCaller      func(context.Context, string) (SessionCaller, error)
	GetHostServiceCaller func(context.Context, string) (SessionCaller, error)
	GetMainClientCaller  func(context.Context) (SessionCaller, error)
	GetRegistryResolver  func(context.Context) (*serverresolver.Resolver, error)

	Interactive        bool
	InteractiveCommand []string
	// contains filtered or unexported fields
}

Opts combines server-scoped runtime dependencies with per-client session plumbing. Server-scoped fields are initialized once with NewOpts and shallow-copied for each client.

func NewOpts

func NewOpts(opts Opts) (*Opts, error)

func (*Opts) Close

func (opts *Opts) Close() error

type SessionCaller

type SessionCaller interface {
	Conn() *grpc.ClientConn
	Supports(method string) bool
}

type TerminalClient

type TerminalClient struct {
	Stdin    io.ReadCloser
	Stdout   io.WriteCloser
	Stderr   io.WriteCloser
	ResizeCh chan bkgw.WinSize
	ErrCh    chan error
	Close    func(exitCode int) error
}

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

Trie is a simple implementation of a compressed trie (or radix tree). In essence, it's a key-value store that allows easily selecting all entries that have a given prefix.

Why not an off-the-shelf implementation? Well, most of those don't allow navigating character-by-character through the tree, like we do with Step.

func (*Trie) Insert

func (t *Trie) Insert(key []byte, value []byte)

func (*Trie) Iter

func (t *Trie) Iter() *TrieIter

func (*Trie) Step

func (t *Trie) Step(ch byte) *TrieIter

func (Trie) String

func (t Trie) String() string

String prints a debuggable representation of the trie.

type TrieIter

type TrieIter struct {
	*Trie
	// contains filtered or unexported fields
}

TrieIter is an iterator that allows navigating through a Trie.

This is used so that we can navigate through the compressed Trie structure easily - not every node "exists", but the TrieIter handles this case. For example, a node might have a direct of `foo`, so the node `fo` is virtual.

func (*TrieIter) Step

func (t *TrieIter) Step(ch byte) *TrieIter

Step selects a node that was previously inserted.

func (*TrieIter) Value

func (t *TrieIter) Value() []byte

Value gets the value previously inserted at this node.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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