Documentation
¶
Index ¶
- Constants
- Variables
- func AptCacheDir(pid, w string) string
- func CacheDir(pid, w string) string
- func DataDir(pid, w string) string
- func FakeDefaultDevices(f func(pid, w string) ([]Mount, []ProxyEntry)) func()
- func Filepath(project, name string) string
- func IsImplicitSdk(name string) bool
- func IsProjectSdk(name string) bool
- func LocalSdkDir(userDataDir, pid, w, name string) string
- func LockPath(path string) string
- func ProjectCacheDir(pid string) string
- func ProjectDataDir(pid string) string
- func ProjectSdkPath(project, name string) string
- func ProjectUserData(userDataDir, pid string) string
- func ReplaceBackend(state *state.State, backend Backend)
- func SdkDeviceName(sk string) string
- func SdkMountDir(userDataDir, pid, w, sdk string) string
- func SdkMountHostSource(userDataDir, pid, w, sdk, plug string) string
- func SdkSourcePath(userDataDir string, project Project, w, sk string, source sdk.Source) string
- func SketchSdkCurrent(userDataDir, pid, w string) string
- func SketchSdkDir(userDataDir, pid, w string) string
- func SketchSdkStash(userDataDir, pid, w string) string
- func StateStorageDir(pid, w string) string
- func TrySdkDir(userDataDir, sdk string) string
- func UserData(userDataDir, pid, w string) string
- func UserDataRootDir(homedir string, env map[string]string) string
- func ValidateFile(file *File) error
- func ValidateProjectId(projectId string) error
- func ValidateSdkInfo(pid, w, base, sk, sdkYaml string) error
- type Action
- type Backend
- type BaseImage
- type BaseImageManager
- type Camera
- type Connection
- type ContextKeyProjectId
- type ContextKeyUser
- type CustomDevice
- type Desktop
- type ErrExec
- type ExecArgs
- type ExecContext
- type ExecControls
- type Execution
- type File
- type Gpu
- type Hostname
- type Mount
- type MountType
- type NetworkManager
- type PlugOrBind
- type PlugRef
- type Project
- type ProjectTracker
- type ProxyDirection
- type ProxyEntry
- type ProxyTarget
- type SdkInstallation
- type SdkManager
- type SdkProfile
- type SdkRecord
- type SdkVolume
- type SlotRef
- type Snapshot
- type SnapshotInfo
- type SshAgent
- type Stash
- type TrackResult
- type Tunnel
- type Workshop
- func (w *Workshop) Mounts(sdks []*sdk.Info) map[string][]Mount
- func (w *Workshop) SdkInfo(ctx context.Context, sdkName string) (*sdk.Info, error)
- func (w *Workshop) SdkInfosByInstallOrder(ctx context.Context) ([]*sdk.Info, error)
- func (w *Workshop) SdksByInstallOrder() []SdkInstallation
- func (w *Workshop) Tunnels(sdks []*sdk.Info) map[string][]Tunnel
Constants ¶
const ( ContextProjectId = ContextKeyProjectId("project-id") ContextUser = ContextKeyUser("user") Uid = 1000 Gid = 1000 RootUmask = os.FileMode(0022) NormalUmask = os.FileMode(0002) )
const ( ProjectLock = ".workshop.lock" // path used in workshop to mount the project directory WorkshopProjectPath = "/project" )
const MAX_WORKSHOP_NAME_LENGTH = 40
Variables ¶
var ( ErrWorkshopNotLaunched = errors.New("workshop not launched") ErrVolumeNotFound = errors.New("volume not found") ErrVolumeAlreadyExists = errors.New("volume already exists") ErrVolumeInUse = errors.New("volume is in use") ErrSnapshotNotFound = errors.New("snapshot not found") ErrSnapshotAlreadyExists = errors.New("snapshot already exists") ErrSdkProfileNotFound = errors.New("sdk profile not found") ErrIncompatibleBackend = errors.New("incompatible backend") User = user.User{ Uid: "1000", Gid: "1000", Username: "workshop", HomeDir: "/home/workshop", } )
var ( ErrProjectLockNotFound = errors.New("project lock file not found") ErrProjectAlreadyExists = errors.New("project already exists") ErrNotProject = errors.New("not a project (no workshop files found)") ErrNoRelativePathsAllowed = errors.New("absolute project path must be used") NewProjectId = allocateProjectId )
var ( ConfigProjectId = "user.workshop.project-id" ConfigWorkshopName = "user.workshop.name" ConfigWorkshopFile = "user.workshop.file" ConfigWorkshopBase = "user.workshop.base" ConfigWorkshopBaseFingerprint = "user.workshop.base-fingerprint" ConfigWorkshopSnapshotType = "user.workshop.snapshot-type" ConfigWorkshopSnapshotFormat = "user.workshop.format-revision" ConfigWorkshopSha3_384 = "user.workshop.sha3-384" ConfigProjectPathDevice = "workshop.project" ConfigStateStorageDevice = "workshop.state-storage" )
var ( SupportedBases = sdk.AllowedBases Directory = ".workshop" Filenames = []string{"workshop.yaml", ".workshop.yaml"} )
var DefaultDevices = defaultDevices
var InstallTimeNow = time.Now
Functions ¶
func AptCacheDir ¶
func FakeDefaultDevices ¶
func FakeDefaultDevices(f func(pid, w string) ([]Mount, []ProxyEntry)) func()
func IsImplicitSdk ¶
IsImplicitSdk checks whether the given SDK is installed regardless of whether it appears in the workshop file.
func IsProjectSdk ¶
IsProjectSdk checks whether the given SDK is defined in the project directory.
func LocalSdkDir ¶
func ProjectCacheDir ¶
func ProjectDataDir ¶
func ProjectSdkPath ¶
func ProjectUserData ¶
func ReplaceBackend ¶
ReplaceBackend replaces the store used by the manager.
func SdkDeviceName ¶
func SdkMountDir ¶
func SdkMountHostSource ¶
func SdkSourcePath ¶
func SketchSdkCurrent ¶
func SketchSdkDir ¶
func SketchSdkStash ¶
func StateStorageDir ¶
func ValidateFile ¶
ValidateFile validates a workshop File struct.
func ValidateProjectId ¶ added in v0.9.2
func ValidateSdkInfo ¶
Types ¶
type Backend ¶
type Backend interface {
Stash
BaseImageManager
SdkManager
// The backend will attempt to load a project for the given path
// using its mapping between the path and a project id. If the project
// is not found, e.g. .lock file was removed by the user, but there is still
// an existing record for the path, it will first attempt to restore .lock.
// If unsuccessful, a new project will be created for the path provided.
CreateOrLoadProject(ctx context.Context, path string) (*Project, bool, error)
// Returns a list of projects known to the backend. The returned map
// has a username key that the corresponding projects belong to.
Projects(ctx context.Context) (map[string][]Project, error)
// Loads a workshop instance.
Workshop(ctx context.Context, name string) (*Workshop, error)
// Returns a workshop's file system interface.
WorkshopFs(ctx context.Context, name string) (fsutil.Fs, error)
// Returns a list of workshops for the project in context.
ProjectWorkshops(ctx context.Context) ([]*Workshop, error)
// Number representing workshop and snapshot compatibility level.
FormatRevision() sdk.Revision
// Look up the given snapshot. On success, returns the given snapshot and
// the workshops that are based on it. On failure, returns an error. In the
// unlikely event the error is caused by a snapshot conflict (i.e. a name
// collision), also returns the conflicting snapshot.
Snapshot(ctx context.Context, snapshot Snapshot) (*SnapshotInfo, error)
// Launch a clean workshop instance. If the workshop exists, wipe out
// its rootfs and rebuild it from the given snapshot (which may be just
// a base image). Configuration and devices of the rebuilt workshop
// will be reset to the default one.
LaunchOrRebuildWorkshop(ctx context.Context, file *File, snapshot Snapshot) error
// Create a snapshot of the workshop's rootfs. The snapshot can be used
// by passing an identical Snapshot to LaunchOrRebuildWorkshop.
TakeSnapshot(ctx context.Context, name string, snapshot Snapshot) error
// Remove the given snapshot.
RemoveSnapshot(ctx context.Context, snapshot Snapshot) error
// Delete workshop. Stop the workshop forcefully if not in Stopped before deleting
RemoveWorkshop(ctx context.Context, name string) error
// Starts a workshop and waits until it is ready
// to accept commands
StartWorkshop(ctx context.Context, name string) error
// Stops workshop gracefully (i.e. waits for the graceful instance and all
// its running services termination) unless force is used.
StopWorkshop(ctx context.Context, name string, force bool) error
// Adds a workshop mount described by the properties.
AddWorkshopMount(ctx context.Context, name string, mount Mount) error
// Removes a workshop mount.
RemoveWorkshopMount(ctx context.Context, name, mount string) error
// Mount an SDK volume and add the SDK to the Sdks field.
InstallSdk(ctx context.Context, name string, setup sdk.Setup) error
// Remove an SDK from the Sdks field and unmount the SDK volume.
UninstallSdk(ctx context.Context, name, sk string) error
// Execute a command in a given workshop. The client should differentiate
// between the errors that occurred during the execution but not related to
// the command (i.e. the workshop does not exist) and the errors that were
// produced by the command itself (i.e. return code != 0). If the latter, an
// instance of ErrExec with the status code will be returned.
// The callback ExecContext.WaitExecution will initite the command execution
// and redirect its IO using args.ExecControls. ExecContext.Environment will
// contain full (actual)
Exec(ctx context.Context, name string, args *Execution) (ExecContext, error)
}
func WorkshopBackend ¶
Store returns the store service provided by the optional device context or the one used by the snapstate package if the former has no override.
type BaseImageManager ¶
type Connection ¶
type ContextKeyProjectId ¶
type ContextKeyProjectId string
type ContextKeyUser ¶
type ContextKeyUser string
type CustomDevice ¶ added in v0.9.1
type Desktop ¶
type Desktop struct {
Wayland *ProxyEntry
X11 *ProxyEntry
}
type ExecArgs ¶
type ExecArgs struct {
// Command is the user-requested command. It is used for user-facing
// summaries and diagnostics.
Command []string
// CommandPrefix is a Workshop-managed wrapper prepended to [Command] at the
// execution boundary. It is not part of the user-requested command.
CommandPrefix []string
UserId int
GroupId int
WorkDir string
Timeout time.Duration
Environment map[string]string
Interactive bool
Terminal bool
SplitStderr bool
Width int
Height int
}
func (ExecArgs) EffectiveCommand ¶ added in v0.9.1
EffectiveCommand returns the command that should be sent to the execution backend, including any Workshop-managed command prefix.
type ExecContext ¶
type ExecControls ¶
type Execution ¶
type Execution struct {
ExecArgs
ExecControls
}
type Mount ¶
type Mount struct {
Name string `json:"name"`
Type MountType `json:"type"`
What string `json:"what"`
MakeWhat bool `json:"make-what,omitempty"`
Where string `json:"where"`
MakeWhere bool `json:"make-where,omitempty"`
Mode os.FileMode `json:"mode,omitempty"`
Owner sys.UserID `json:"owner,omitempty"`
Group sys.GroupID `json:"group,omitempty"`
ReadOnly bool `json:"readonly"`
}
type NetworkManager ¶ added in v0.9.2
type PlugOrBind ¶
func (PlugOrBind) MarshalYAML ¶
func (p PlugOrBind) MarshalYAML() (any, error)
func (*PlugOrBind) UnmarshalYAML ¶
func (p *PlugOrBind) UnmarshalYAML(value *yaml.Node) error
type PlugRef ¶
func (PlugRef) MarshalYAML ¶
type ProjectTracker ¶
type ProjectTracker struct {
Projects []Project
}
func (*ProjectTracker) Track ¶
func (t *ProjectTracker) Track(path string) (*Project, TrackResult, error)
Track attempts to locate a known project that contains the given path. If unsuccessful, it creates a new project and begins tracking it. Moved projects will be updated with the new path, whereas copied projects will receive a new project ID.
type ProxyDirection ¶
type ProxyDirection int
const ( HostToWorkshop ProxyDirection = iota WorkshopToHost )
type ProxyEntry ¶
type ProxyEntry struct {
Name string
Connect ProxyTarget
Listen ProxyTarget
Direction ProxyDirection
}
func (*ProxyEntry) Equal ¶
func (p *ProxyEntry) Equal(other *ProxyEntry) bool
type ProxyTarget ¶
type SdkInstallation ¶
type SdkManager ¶
type SdkManager interface {
// Import an SDK tarball as a new volume.
ImportSdk(ctx context.Context, meta sdk.Meta, tarball *os.File) error
// Delete an SDK volume. It does not unmount the volume from workshops
// where it is mounted. No error is returned if the SDK does not exist.
DeleteSdk(ctx context.Context, setup sdk.Setup) error
// List available SDK volumes.
Sdks(ctx context.Context) ([]SdkVolume, error)
// Get the SDK volume information.
Sdk(ctx context.Context, setup sdk.Setup) (SdkVolume, error)
}
type SdkProfile ¶
type SdkProfile struct {
Sdk string
Camera *Camera
CustomDevices []CustomDevice
Mounts map[string]Mount
Tunnels []Tunnel
Agent *SshAgent
Gpu *Gpu
Desktop *Desktop
}
func NewSdkProfile ¶
func NewSdkProfile(sdkName string) SdkProfile
type SdkRecord ¶
type SdkRecord struct {
Name string `yaml:"name"`
Channel string `yaml:"channel,omitempty"`
Source sdk.Source `yaml:"source,omitempty"`
Plugs map[string]PlugOrBind `yaml:"plugs,omitempty"`
Slots map[string]any `yaml:"slots,omitempty"`
}
func (SdkRecord) MarshalYAML ¶
type Snapshot ¶
Snapshot identifies a workshop snapshot without depending on backend-specific details. For example snapshot names in LXD are subject to length limits and a restricted character set.
func SdkSnapshot ¶
SdkSnapshot identifies a snapshot consisting of a base image and a sequence of installed SDKs.
type SnapshotInfo ¶
type SshAgent ¶
type SshAgent struct {
ProxyEntry
}
type Stash ¶
type Stash interface {
// Make a stash of the workshop. The workshop will be stopped and will not
// be available to other workshop operations, e.g. list, stop, start and so
// on. A new workshop with the same name can be launched for the same
// project-id.
StashWorkshop(ctx context.Context, name string) error
// Restore the workshop from the stash (if exists, see StashWorkshop). The
// workshop will be restored and become visible to the backend operations.
// Fails if a workshop with the same name exists.
UnstashWorkshop(ctx context.Context, name string) error
// Delete the workshop from stash (if exists).
RemoveWorkshopStash(ctx context.Context, name string) error
}
type TrackResult ¶
type TrackResult int
const ( ProjectError TrackResult = iota ProjectFound ProjectMoved ProjectAdded )
type Tunnel ¶
type Tunnel struct {
ProxyEntry
}
type Workshop ¶
type Workshop struct {
Backend Backend
Project Project
// Workshop file that was used to launch it; it may be out of sync with the
// file in the project directory due to user's edits, etc.
File *File
Name string
Format sdk.Revision
Image BaseImage
Running bool
// Installed SDKs.
Sdks map[string]SdkInstallation
// Workshop devices installed.
Profiles map[string]SdkProfile
Hostname Hostname
}
func (*Workshop) SdkInfosByInstallOrder ¶
Returns a map of SDK info for installed SDKs. The info includes SDK details parsed from its sdk.yaml, such as base, plugs, slots, etc.
func (*Workshop) SdksByInstallOrder ¶
func (w *Workshop) SdksByInstallOrder() []SdkInstallation
Returns the list of SDKs of the workshop sorted by installation order.