Documentation ¶
Index ¶
- Constants
- func AddFilesToDestination(destDir string, filesToCopy ...FileToCopy) error
- type Chroot
- func (c *Chroot) AddDirs(dirToCopy DirToCopy) (err error)
- func (c *Chroot) AddFiles(filesToCopy ...FileToCopy) (err error)
- func (c *Chroot) Close(leaveOnDisk bool) (err error)
- func (c *Chroot) CopyOutFile(srcPath string, destPath string) (err error)
- func (c *Chroot) GetMountPoints() []*MountPoint
- func (c *Chroot) Initialize(tarPath string, extraDirectories []string, extraMountPoints []*MountPoint, ...) (err error)
- func (c *Chroot) MoveOutFile(srcPath string, destPath string) (err error)
- func (c *Chroot) RootDir() string
- func (c *Chroot) Run(toRun func() error) (err error)
- func (c *Chroot) UnsafeRun(toRun func() error) (err error)
- func (c *Chroot) WriteFiles() error
- type ChrootInterface
- type DirToCopy
- type DummyChroot
- type FileToCopy
- type MountPoint
- func NewMountPoint(source, target, fstype string, flags uintptr, data string) (mountPoint *MountPoint)
- func NewOverlayMountPoint(chrootDir, source, target, lowerDir, upperDir, workDir string) (mountPoint *MountPoint, extaDirsNeeds []string)
- func NewPreDefaultsMountPoint(source, target, fstype string, flags uintptr, data string) (mountPoint *MountPoint)
Constants ¶
const BindMountPointFlags = unix.MS_BIND | unix.MS_MGC_VAL
BindMountPointFlags is a set of flags to do a bind mount.
Variables ¶
This section is empty.
Functions ¶
func AddFilesToDestination ¶
func AddFilesToDestination(destDir string, filesToCopy ...FileToCopy) error
Types ¶
type Chroot ¶
type Chroot struct {
// contains filtered or unexported fields
}
Chroot represents a Chroot environment with automatic synchronization protections and guaranteed cleanup code even on SIGTERM so long as registerSIGTERMCleanup is invoked.
func (*Chroot) AddDirs ¶
AddDirs copies each directory 'Src' to the relative path chrootRootDir/'Dest' in the chroot.
func (*Chroot) AddFiles ¶
func (c *Chroot) AddFiles(filesToCopy ...FileToCopy) (err error)
AddFiles copies each file 'Src' to the relative path chrootRootDir/'Dest' in the chroot.
func (*Chroot) Close ¶
Close will unmount the chroot and cleanup its files. This call will block until the chroot cleanup runs. Only one Chroot will close at a given time.
func (*Chroot) CopyOutFile ¶
CopyOutFile copies file 'srcPath' in the chroot to the host at 'destPath'
func (*Chroot) GetMountPoints ¶
func (c *Chroot) GetMountPoints() []*MountPoint
GetMountPoints gets a copy of the list of mounts the Chroot was initialized with.
func (*Chroot) Initialize ¶
func (c *Chroot) Initialize(tarPath string, extraDirectories []string, extraMountPoints []*MountPoint, includeDefaultMounts bool, ) (err error)
Initialize initializes a Chroot, creating directories and mount points.
- tarPath is an optional path to a tar file that will be extracted at the root of the chroot.
- extraDirectories is an optional slice of additional directories that should be created before attempting to mount inside the chroot.
- extraMountPoints is an optional slice of additional mount points that should be created inside the chroot, they will automatically be unmounted on a Chroot Close.
This call will block until the chroot initializes successfully. Only one Chroot will initialize at a given time.
func (*Chroot) MoveOutFile ¶
MoveOutFile moves file 'srcPath' in the chroot to the host at 'destPath', deleting the 'srcPath' file.
func (*Chroot) Run ¶
Run runs a given function inside the Chroot. This function will synchronize with all other Chroots to ensure only one Chroot command is executed at a given time.
func (*Chroot) UnsafeRun ¶
UnsafeRun runs a given function inside the Chroot. This function will not synchronize with other Chroots. The invoker is responsible for ensuring safety.
func (*Chroot) WriteFiles ¶
type ChrootInterface ¶
type DirToCopy ¶
type DirToCopy struct { Src string Dest string NewDirPermissions os.FileMode ChildFilePermissions os.FileMode MergedDirPermissions *os.FileMode }
DirToCopy represents a directory to copy into a chroot using AddDirs. Dest is relative to the chroot directory.
type DummyChroot ¶
type DummyChroot struct { }
DummyChroot is a placeholder that implements ChrootInterface.
func (*DummyChroot) AddFiles ¶
func (d *DummyChroot) AddFiles(filesToCopy ...FileToCopy) (err error)
func (*DummyChroot) RootDir ¶
func (d *DummyChroot) RootDir() string
func (*DummyChroot) Run ¶
func (d *DummyChroot) Run(toRun func() error) (err error)
func (*DummyChroot) UnsafeRun ¶
func (d *DummyChroot) UnsafeRun(toRun func() error) (err error)
type FileToCopy ¶
type FileToCopy struct { // The source file path. // Mutually exclusive with 'Content'. Src string // The contents of the file to write. // Mutually exclusive with 'Src'. Content *string // The destination path to write/copy the file to. Dest string Permissions *os.FileMode // Set to true to copy symlinks as symlinks. NoDereference bool }
FileToCopy represents a file to copy into a chroot using AddFiles. Dest is relative to the chroot directory.
type MountPoint ¶
type MountPoint struct {
// contains filtered or unexported fields
}
MountPoint represents a system mount point used by a Chroot. It is guaranteed to be unmounted on application exit even on a SIGTERM so long as registerSIGTERMCleanup is invoked. The fields of MountPoint mirror those of the `mount` syscall.
func NewMountPoint ¶
func NewMountPoint(source, target, fstype string, flags uintptr, data string) (mountPoint *MountPoint)
NewMountPoint creates a new MountPoint struct to be created by a Chroot
func NewOverlayMountPoint ¶
func NewOverlayMountPoint(chrootDir, source, target, lowerDir, upperDir, workDir string) (mountPoint *MountPoint, extaDirsNeeds []string)
NewOverlayMountPoint creates a new MountPoint struct and extra directories slice configured for a given overlay
func NewPreDefaultsMountPoint ¶
func NewPreDefaultsMountPoint(source, target, fstype string, flags uintptr, data string) (mountPoint *MountPoint)
NewPreDefaultsMountPoint creates a new MountPoint struct to be created by a Chroot but before the default mount points.
func (*MountPoint) GetFSType ¶
func (m *MountPoint) GetFSType() string
GetFSType gets the file-system type of the mount.
func (*MountPoint) GetSource ¶
func (m *MountPoint) GetSource() string
GetSource gets the source device of the mount.
func (*MountPoint) GetTarget ¶
func (m *MountPoint) GetTarget() string
GetTarget gets the target directory path of the mount.