workspace

package
v0.19.1133 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultTmpRootDir is the root used when no root is passed in. This allows a user of this workspace to create
	// workspaces in a different directory
	DefaultTmpRootDir string = "/tmp"

	// HostActionRootDir is the root the mng process uses for image-backed action
	// workspaces. mng runs natively on the VM host, where /tmp is tmpfs sized at
	// a fraction of RAM, so an action writing multi-GiB content there would
	// consume memory rather than disk. This path is on the root volume.
	HostActionRootDir string = "/opt/nuon/action-workspaces"

	// HostActionFallbackRootDir is used when the process can't create
	// HostActionRootDir, which happens when the mng unit's sandboxing leaves /opt
	// read-only. /var/tmp is on the root volume on a default VM image, unlike
	// /tmp, so it keeps action content on disk.
	HostActionFallbackRootDir string = "/var/tmp/nuon-action-workspaces"
)

Variables

This section is empty.

Functions

func CleanupByID

func CleanupByID(workspaceID string) error

CleanupByID removes a single workspace directory by its ID. This is safe to call with parallel runner jobs since it only targets the specific workspace, not all workspace-prefixed dirs.

It sweeps every root a workspace can be created under, since the caller is a generic per-job backstop that doesn't know which root the handler chose. A missing directory is not an error.

func FilesystemType added in v0.19.1126

func FilesystemType(path string) string

FilesystemType returns the filesystem backing path, resolved from the longest mount point that prefixes it. It returns an empty string where /proc/mounts isn't available (a macOS dev machine), so callers treat unknown as fine.

func HostActionRoots added in v0.19.1126

func HostActionRoots() []string

HostActionRoots are the roots an image-backed action workspace can land in, most preferred first. Cleanup has to sweep all of them, since which one a job used depends on what the process could write at the time.

func IsCommitHash

func IsCommitHash(s string) bool

IsCommitHash checks if a string matches the pattern of a git commit hash (5-40 hexadecimal characters).

func New

func New(v *validator.Validate, opts ...workspaceOption) (*workspace, error)

func ResolveHostActionRoot added in v0.19.1126

func ResolveHostActionRoot(l *zap.Logger) string

ResolveHostActionRoot returns the first root the process can create that is not memory-backed, so a multi-GiB action writes to disk rather than RAM. Landing on a memory-backed root is the failure this exists to prevent, so it is reported rather than silently accepted.

func SweepStale added in v0.19.1126

func SweepStale(root string) ([]string, error)

SweepStale removes workspace directories left under root by a previous process, and returns the names it removed. A workspace is created per job execution and removed when that execution ends, so anything present before any job starts is the residue of a crash or a hard restart. Callers must only run this at startup, before the job loop claims work.

func WithGitSource

func WithGitSource(src *plantypes.GitSource) workspaceOption

WithGitSource sets a git source

func WithLogger

func WithLogger(l *zap.Logger) workspaceOption

func WithTmpRoot

func WithTmpRoot(root string) workspaceOption

WithTmpRoot sets a root temp directory for the workspace

func WithWorkspaceID

func WithWorkspaceID(workspaceID string) workspaceOption

WithWorkspaceID sets an ID on the workspace, prefixed for identification.

Types

type CloneErr

type CloneErr struct {
	Url string
	Ref string
	Err error
}

func (CloneErr) Error

func (c CloneErr) Error() string

func (CloneErr) Unwrap

func (c CloneErr) Unwrap() error

type PathExistsErr

type PathExistsErr struct {
	Path string
}

func (PathExistsErr) Error

func (p PathExistsErr) Error() string

type Source

type Source struct {
	// the user provided directory
	Path string

	// the root of the workspace
	Root string

	// whether this is a git source
	IsGit bool
}

func (Source) AbsPath

func (s Source) AbsPath() string

type Workspace

type Workspace interface {
	Init(context.Context) error
	Source() *Source
	Cleanup(context.Context) error

	// helpers
	Root() string
	AbsPath(string) string
	IsFile(string) bool
	IsDir(string) bool
	RmDir(string) error
	IsExecutable(string) bool
}

Jump to

Keyboard shortcuts

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