workspace

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileMapper

type FileMapper struct {
	WorkDir    string
	ScratchDir string
	Inputs     []*tes.Input
	Outputs    []*tes.Output
	Volumes    []Volume
}

FileMapper is responsible for mapping paths into a working directory on the worker's host file system.

Every task needs it's own directory to work in. When a file is downloaded for a task, it needs to be stored in the task's working directory. Similar for task outputs, uploads, stdin/out/err, etc. FileMapper helps the worker engine manage all these paths.

func NewFileMapper

func NewFileMapper(dir string) *FileMapper

NewFileMapper returns a new FileMapper, which maps files into the given base directory.

func (*FileMapper) AddTmpVolume

func (mapper *FileMapper) AddTmpVolume(mountPoint string) error

AddTmpVolume creates a directory on the host based on the declared path in the container and adds it to mapper.Volumes.

If the path can't be mapped, an error is returned.

func (*FileMapper) AddVolume

func (mapper *FileMapper) AddVolume(hostPath string, mountPoint string, readonly bool) (bool, error)

AddVolume adds a mapped volume to the mapper. A corresponding Volume record is added to mapper.Volumes.

Returns (true, nil) when the volume was added or replaced an existing one. Returns (false, nil) when the volume was skipped because it is already covered by an existing mount (duplicate or subpath of an existing RW volume). Returns (false, err) when the paths are invalid.

func (*FileMapper) Cleanup

func (mapper *FileMapper) Cleanup() error

Cleanup deletes the working directory.

func (*FileMapper) ContainerPath

func (mapper *FileMapper) ContainerPath(src string) string

ContainerPath returns an unmapped path.

The mapper's base dir is stripped from the path. e.g. If the mapper is configured with a base dir of "/tmp/mapped_files", then mapper.ContainerPath("/tmp/mapped_files/home/ubuntu/myfile") will return "/home/ubuntu/myfile".

func (*FileMapper) CopyInputsToScratch

func (mapper *FileMapper) CopyInputsToScratch(scratchDir string) error

func (*FileMapper) CopyOutputsToWorkDir

func (mapper *FileMapper) CopyOutputsToWorkDir(scratchDir string) error

func (*FileMapper) CreateHostFile

func (mapper *FileMapper) CreateHostFile(src string) (*os.File, error)

CreateHostFile creates a file on the host file system at a mapped path. "src" is an unmapped path. This function will handle mapping the path.

If the path can't be mapped or the file can't be created, an error is returned.

func (*FileMapper) HostPath

func (mapper *FileMapper) HostPath(src string) (string, error)

HostPath returns a mapped path.

The path is concatenated to the mapper's base dir. e.g. If the mapper is configured with a base dir of "/tmp/mapped_files", then mapper.HostPath("/home/ubuntu/myfile") will return "/tmp/mapped_files/home/ubuntu/myfile".

The mapped path is required to be a subpath of the mapper's base directory. e.g. mapper.HostPath("../../foo") should fail with an error.

func (*FileMapper) HostScratchPath

func (mapper *FileMapper) HostScratchPath(src string) (string, error)

func (*FileMapper) IsSubpath

func (mapper *FileMapper) IsSubpath(p string, base string) bool

IsSubpath returns true if the given path "p" is "base" or below it. Paths are compared by whole components: "/data2" is not below "/data".

func (*FileMapper) MapTask

func (mapper *FileMapper) MapTask(task *tes.Task, executorBackend string) error

MapTask adds all the volumes, inputs, and outputs in the given Task to the FileMapper.

func (*FileMapper) OpenHostFile

func (mapper *FileMapper) OpenHostFile(src string) (*os.File, error)

OpenHostFile opens a mapped executor input read-only within its working root.

type Volume

type Volume struct {
	// The path in tes worker.
	HostPath string
	// The path in Docker.
	ContainerPath string
	Readonly      bool
}

Volume represents a volume mounted into a docker container. This includes a HostPath, the path on the host file system, and a ContainerPath, the path on the container file system, and whether the volume is read-only.

Jump to

Keyboard shortcuts

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