studio

package
v1.1.12 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package studio provides one-click AI development environment management across various container and VM platforms (WSL, Colima, AppleContainer, K8S, Docker).

Index

Constants

View Source
const (
	// CDN base URL for TensorFusion libraries
	DefaultCDNURL = "https://cdn.tensor-fusion.ai"

	// Library version - this would normally come from config
	DefaultLibVersion = "v1.0.0"
)
View Source
const (
	OSDarwin  = "darwin"
	OSLinux   = "linux"
	OSWindows = "windows"
)

Platform constants for runtime.GOOS comparisons

View Source
const (
	DefaultProtocolTCP      = "tcp"
	MountOptionReadOnly     = ":ro"
	DefaultImageStudioTorch = "tensorfusion/studio-torch:latest"
	DockerStateRunning      = "running"
	DockerStateExited       = "exited"
	DockerStateCreated      = "created"
	DefaultHostLocalhost    = "localhost"
)

Docker-related constants

Variables

This section is empty.

Functions

func GenerateBatchScript added in v1.1.7

func GenerateBatchScript(config *GPUEnvConfig, paths *platform.Paths) (string, error)

GenerateBatchScript generates a CMD batch script to set up the GPU environment

func GenerateEnvScript added in v1.1.7

func GenerateEnvScript(config *GPUEnvConfig, paths *platform.Paths) (string, error)

GenerateEnvScript generates a shell script to set up the GPU environment

func GeneratePowerShellScript added in v1.1.7

func GeneratePowerShellScript(config *GPUEnvConfig, paths *platform.Paths) (string, error)

GeneratePowerShellScript generates a PowerShell script to set up the GPU environment

func GetLibraryNames added in v1.1.7

func GetLibraryNames(vendor GPUVendor) []string

GetLibraryNames returns the library names to preload for a vendor (Linux/macOS)

func GetWindowsLibraryNames added in v1.1.7

func GetWindowsLibraryNames(vendor GPUVendor) []string

GetWindowsLibraryNames returns the DLL names for a vendor (Windows)

func IsDarwin added in v1.1.7

func IsDarwin() bool

IsDarwin returns true if running on macOS

func IsLinux added in v1.1.7

func IsLinux() bool

IsLinux returns true if running on Linux

Types

type AppleContainerBackend

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

AppleContainerBackend implements the Backend interface using Apple native containers This uses Docker CLI with the assumption that Docker Desktop or similar is running on macOS using Apple Virtualization Framework

func NewAppleContainerBackend

func NewAppleContainerBackend() *AppleContainerBackend

NewAppleContainerBackend creates a new Apple container backend

func (*AppleContainerBackend) Create

func (*AppleContainerBackend) Exec

func (b *AppleContainerBackend) Exec(ctx context.Context, envID string, cmd []string) ([]byte, error)

func (*AppleContainerBackend) Get

func (b *AppleContainerBackend) Get(ctx context.Context, idOrName string) (*Environment, error)

func (*AppleContainerBackend) IsAvailable

func (b *AppleContainerBackend) IsAvailable(ctx context.Context) bool

func (*AppleContainerBackend) List

func (*AppleContainerBackend) Logs

func (b *AppleContainerBackend) Logs(ctx context.Context, envID string, follow bool) (<-chan string, error)

func (*AppleContainerBackend) Mode

func (b *AppleContainerBackend) Mode() Mode

func (*AppleContainerBackend) Name

func (b *AppleContainerBackend) Name() string

func (*AppleContainerBackend) Remove

func (b *AppleContainerBackend) Remove(ctx context.Context, envID string) error

func (*AppleContainerBackend) Start

func (b *AppleContainerBackend) Start(ctx context.Context, envID string) error

func (*AppleContainerBackend) Stop

func (b *AppleContainerBackend) Stop(ctx context.Context, envID string) error

type Architecture

type Architecture struct {
	OS   string // darwin, linux, windows
	Arch string // arm64, amd64, 386
}

Architecture detection

func DetectArchitecture

func DetectArchitecture() Architecture

DetectArchitecture detects the current system architecture

func (Architecture) String

func (a Architecture) String() string

String returns the architecture string for CDN lookup

type AutoStartableBackend added in v1.1.10

type AutoStartableBackend interface {
	Backend
	// IsInstalled checks if the backend software is installed (but not necessarily running)
	IsInstalled(ctx context.Context) bool
	// EnsureRunning ensures the backend is running, starting it if necessary
	EnsureRunning(ctx context.Context) error
}

AutoStartableBackend is an optional interface for backends that can be auto-started. Backends implementing this interface can be selected even if not currently running, as long as they are installed and can be started automatically.

type Backend

type Backend interface {
	// Name returns the backend name
	Name() string

	// Mode returns the mode this backend handles
	Mode() Mode

	// IsAvailable checks if this backend is available on the system
	IsAvailable(ctx context.Context) bool

	// Create creates a new environment
	Create(ctx context.Context, opts *CreateOptions) (*Environment, error)

	// Start starts a stopped environment
	Start(ctx context.Context, envID string) error

	// Stop stops a running environment
	Stop(ctx context.Context, envID string) error

	// Remove removes an environment
	Remove(ctx context.Context, envID string) error

	// List lists all environments
	List(ctx context.Context) ([]*Environment, error)

	// Get gets an environment by ID or name
	Get(ctx context.Context, idOrName string) (*Environment, error)

	// Exec executes a command in an environment
	Exec(ctx context.Context, envID string, cmd []string) ([]byte, error)

	// Logs returns logs from an environment
	Logs(ctx context.Context, envID string, follow bool) (<-chan string, error)
}

Backend is the interface for container/VM runtime backends

type ColimaBackend

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

ColimaBackend implements the Backend interface using Colima (macOS/Linux)

func NewColimaBackend

func NewColimaBackend() *ColimaBackend

NewColimaBackend creates a new Colima backend

func NewColimaBackendWithProfile

func NewColimaBackendWithProfile(profile string) *ColimaBackend

NewColimaBackendWithProfile creates a new Colima backend with specific profile

func (*ColimaBackend) Create

func (b *ColimaBackend) Create(ctx context.Context, opts *CreateOptions) (*Environment, error)

func (*ColimaBackend) EnsureRunning

func (b *ColimaBackend) EnsureRunning(ctx context.Context) error

EnsureRunning ensures Colima is running

func (*ColimaBackend) Exec

func (b *ColimaBackend) Exec(ctx context.Context, envID string, cmd []string) ([]byte, error)

func (*ColimaBackend) Get

func (b *ColimaBackend) Get(ctx context.Context, idOrName string) (*Environment, error)

func (*ColimaBackend) GetColimaIP

func (b *ColimaBackend) GetColimaIP(ctx context.Context) (string, error)

GetColimaIP returns the IP address of the Colima VM

func (*ColimaBackend) GetProfile

func (b *ColimaBackend) GetProfile() string

GetProfile returns the Colima profile name

func (*ColimaBackend) IsAvailable

func (b *ColimaBackend) IsAvailable(ctx context.Context) bool

func (*ColimaBackend) IsInstalled added in v1.1.10

func (b *ColimaBackend) IsInstalled(ctx context.Context) bool

IsInstalled checks if colima is installed (but not necessarily running)

func (*ColimaBackend) List

func (b *ColimaBackend) List(ctx context.Context) ([]*Environment, error)

func (*ColimaBackend) Logs

func (b *ColimaBackend) Logs(ctx context.Context, envID string, follow bool) (<-chan string, error)

func (*ColimaBackend) Mode

func (b *ColimaBackend) Mode() Mode

func (*ColimaBackend) Name

func (b *ColimaBackend) Name() string

func (*ColimaBackend) Remove

func (b *ColimaBackend) Remove(ctx context.Context, envID string) error

func (*ColimaBackend) SetDockerHost

func (b *ColimaBackend) SetDockerHost(dockerHost string)

SetDockerHost sets a custom Docker socket path

func (*ColimaBackend) Start

func (b *ColimaBackend) Start(ctx context.Context, envID string) error

func (*ColimaBackend) Stop

func (b *ColimaBackend) Stop(ctx context.Context, envID string) error

type CreateOptions

type CreateOptions struct {
	Name           string            `json:"name"`
	Mode           Mode              `json:"mode"`
	Image          string            `json:"image"`
	GPUWorkerURL   string            `json:"gpu_worker_url,omitempty"`  // TENSOR_FUSION_OPERATOR_CONNECTION_INFO
	HardwareVendor string            `json:"hardware_vendor,omitempty"` // nvidia, amd, hygon
	SSHPublicKey   string            `json:"ssh_public_key,omitempty"`
	WorkDir        string            `json:"work_dir,omitempty"`
	Ports          []PortMapping     `json:"ports,omitempty"`
	Envs           map[string]string `json:"envs,omitempty"`
	Volumes        []VolumeMount     `json:"volumes,omitempty"`
	Resources      ResourceSpec      `json:"resources,omitempty"`
	Labels         map[string]string `json:"labels,omitempty"`
}

CreateOptions contains options for creating an environment

type DockerBackend

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

DockerBackend implements the Backend interface using Docker

func NewDockerBackend

func NewDockerBackend() *DockerBackend

NewDockerBackend creates a new Docker backend

func NewDockerBackendWithHost

func NewDockerBackendWithHost(dockerHost string) *DockerBackend

NewDockerBackendWithHost creates a new Docker backend with custom host

func NewPodmanBackend

func NewPodmanBackend() *DockerBackend

NewPodmanBackend creates a new Podman backend (uses Docker interface)

func (*DockerBackend) Create

func (b *DockerBackend) Create(ctx context.Context, opts *CreateOptions) (*Environment, error)

func (*DockerBackend) Exec

func (b *DockerBackend) Exec(ctx context.Context, envID string, cmd []string) ([]byte, error)

func (*DockerBackend) Get

func (b *DockerBackend) Get(ctx context.Context, idOrName string) (*Environment, error)

func (*DockerBackend) IsAvailable

func (b *DockerBackend) IsAvailable(ctx context.Context) bool

func (*DockerBackend) List

func (b *DockerBackend) List(ctx context.Context) ([]*Environment, error)

func (*DockerBackend) Logs

func (b *DockerBackend) Logs(ctx context.Context, envID string, follow bool) (<-chan string, error)

func (*DockerBackend) Mode

func (b *DockerBackend) Mode() Mode

func (*DockerBackend) Name

func (b *DockerBackend) Name() string

func (*DockerBackend) Remove

func (b *DockerBackend) Remove(ctx context.Context, envID string) error

func (*DockerBackend) Start

func (b *DockerBackend) Start(ctx context.Context, envID string) error

func (*DockerBackend) Stop

func (b *DockerBackend) Stop(ctx context.Context, envID string) error

type Environment

type Environment struct {
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	Mode          Mode              `json:"mode"`
	Image         string            `json:"image"`
	Status        EnvironmentStatus `json:"status"`
	ConnectionURL string            `json:"connection_url,omitempty"`
	SSHHost       string            `json:"ssh_host,omitempty"`
	SSHPort       int               `json:"ssh_port,omitempty"`
	SSHUser       string            `json:"ssh_user,omitempty"`
	WorkDir       string            `json:"work_dir,omitempty"`
	GPUWorkerURL  string            `json:"gpu_worker_url,omitempty"`
	CreatedAt     time.Time         `json:"created_at"`
	Labels        map[string]string `json:"labels,omitempty"`
}

Environment represents a running studio environment

type EnvironmentStatus

type EnvironmentStatus string

EnvironmentStatus represents the status of an environment

const (
	StatusPending    EnvironmentStatus = "pending"
	StatusPulling    EnvironmentStatus = "pulling"
	StatusStarting   EnvironmentStatus = "starting"
	StatusRunning    EnvironmentStatus = "running"
	StatusStopped    EnvironmentStatus = "stopped"
	StatusError      EnvironmentStatus = "error"
	StatusTerminated EnvironmentStatus = "terminated"
)

type GPUEnvConfig added in v1.1.7

type GPUEnvConfig struct {
	Vendor        GPUVendor
	ConnectionURL string // TENSOR_FUSION_OPERATOR_CONNECTION_INFO value
	CachePath     string // Path to gpugo cache directory
	LogPath       string // Path to logs directory
	StudioName    string // Name of the studio (for creating config files)
	IsContainer   bool   // Whether this is for a container (affects paths)
}

GPUEnvConfig holds configuration for GPU environment setup

type GPUEnvResult added in v1.1.7

type GPUEnvResult struct {
	EnvVars         map[string]string
	LDSoConfPath    string        // Host path to ld.so.conf file
	LDSoPreloadPath string        // Host path to ld.so.preload file
	VolumeMounts    []VolumeMount // Additional volume mounts needed
}

GPUEnvResult holds the result of GPU environment setup

func SetupGPUEnv added in v1.1.7

func SetupGPUEnv(paths *platform.Paths, config *GPUEnvConfig) (*GPUEnvResult, error)

SetupGPUEnv creates and configures GPU environment files

type GPUVendor added in v1.1.7

type GPUVendor string

GPUVendor represents supported GPU vendors

const (
	VendorNvidia  GPUVendor = "nvidia"
	VendorAMD     GPUVendor = "amd"
	VendorHygon   GPUVendor = "hygon"
	VendorUnknown GPUVendor = "unknown"
)

func ParseVendor added in v1.1.7

func ParseVendor(vendor string) GPUVendor

ParseVendor parses a vendor string to GPUVendor

type LibraryDownloader

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

LibraryDownloader handles downloading versioned GPU libraries from CDN

func NewLibraryDownloader

func NewLibraryDownloader(cdnURL, version string) *LibraryDownloader

NewLibraryDownloader creates a new library downloader

func (*LibraryDownloader) Download

func (d *LibraryDownloader) Download(lib LibraryInfo) (string, error)

Download downloads a library from the CDN

func (*LibraryDownloader) DownloadDefaultLibraries

func (d *LibraryDownloader) DownloadDefaultLibraries() ([]string, error)

DownloadDefaultLibraries downloads the default set of GPU libraries

func (*LibraryDownloader) DownloadURL

func (d *LibraryDownloader) DownloadURL(lib LibraryInfo) string

DownloadURL constructs the CDN download URL for a library

func (*LibraryDownloader) GetCacheDir

func (d *LibraryDownloader) GetCacheDir() string

GetCacheDir returns the cache directory path

func (*LibraryDownloader) SetCacheDir

func (d *LibraryDownloader) SetCacheDir(dir string)

SetCacheDir sets a custom cache directory

type LibraryInfo

type LibraryInfo struct {
	Name     string
	Version  string
	Arch     Architecture
	Checksum string // SHA256 checksum
}

LibraryInfo contains information about a library to download

type Manager

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

Manager manages AI studio environments across different backends

func NewManager

func NewManager() *Manager

NewManager creates a new studio manager

func (*Manager) AddSSHConfig

func (m *Manager) AddSSHConfig(env *Environment) error

AddSSHConfig adds an SSH config entry for an environment

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, opts *CreateOptions) (*Environment, error)

Create creates a new environment

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, idOrName string) (*Environment, error)

Get gets an environment by ID or name

func (*Manager) GetBackend

func (m *Manager) GetBackend(mode Mode) (Backend, error)

GetBackend returns a backend by mode

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]*Environment, error)

List lists all environments across all backends

func (*Manager) ListAvailableBackends

func (m *Manager) ListAvailableBackends(ctx context.Context) []Backend

ListAvailableBackends returns all available backends

func (*Manager) RegisterBackend

func (m *Manager) RegisterBackend(backend Backend)

RegisterBackend registers a backend

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, idOrName string) error

Remove removes an environment

func (*Manager) RemoveSSHConfig

func (m *Manager) RemoveSSHConfig(envName string) error

RemoveSSHConfig removes an SSH config entry for an environment

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, idOrName string) error

Start starts an environment

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context, idOrName string) error

Stop stops an environment

type Mode

type Mode string

Mode represents the container/VM runtime mode

const (
	ModeWSL            Mode = "wsl"    // Windows Subsystem for Linux
	ModeColima         Mode = "colima" // Colima (macOS/Linux)
	ModeAppleContainer Mode = "apple"  // Apple Virtualization Framework
	ModeDocker         Mode = "docker" // Native Docker
	ModeKubernetes     Mode = "k8s"    // Kubernetes (kind, minikube, etc.)
	ModeAuto           Mode = "auto"   // Auto-detect best option
)

type PortMapping

type PortMapping struct {
	HostPort      int    `json:"host_port"`
	ContainerPort int    `json:"container_port"`
	Protocol      string `json:"protocol,omitempty"` // tcp, udp
}

PortMapping represents a port mapping

type ResourceSpec

type ResourceSpec struct {
	CPUs   float64 `json:"cpus,omitempty"`
	Memory string  `json:"memory,omitempty"` // e.g., "8Gi"
}

ResourceSpec represents resource limits

type SSHConfig

type SSHConfig struct {
	Host         string
	HostName     string
	User         string
	Port         int
	IdentityFile string
	ExtraOptions map[string]string
}

SSHConfig represents an SSH configuration entry

func (*SSHConfig) GenerateSSHConfigEntry

func (c *SSHConfig) GenerateSSHConfigEntry() string

GenerateSSHConfigEntry generates an SSH config entry string

type StudioImage

type StudioImage struct {
	Name        string            `json:"name"`
	Tag         string            `json:"tag"`
	Description string            `json:"description"`
	Features    []string          `json:"features"` // torch, cuda, ssh, jupyter, etc.
	Size        string            `json:"size"`
	Registry    string            `json:"registry"`
	Labels      map[string]string `json:"labels,omitempty"`
}

StudioImage represents a pre-configured AI development image

func DefaultImages

func DefaultImages() []StudioImage

DefaultImages returns the list of available studio images

type VolumeMount

type VolumeMount struct {
	HostPath      string `json:"host_path"`
	ContainerPath string `json:"container_path"`
	ReadOnly      bool   `json:"read_only,omitempty"`
}

VolumeMount represents a volume mount

type WSLBackend

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

WSLBackend implements the Backend interface using Windows Subsystem for Linux

func NewWSLBackend

func NewWSLBackend() *WSLBackend

NewWSLBackend creates a new WSL backend

func NewWSLBackendWithDistro

func NewWSLBackendWithDistro(distro string) *WSLBackend

NewWSLBackendWithDistro creates a new WSL backend with specific distro

func (*WSLBackend) Create

func (b *WSLBackend) Create(ctx context.Context, opts *CreateOptions) (*Environment, error)

func (*WSLBackend) EnsureSSHServer

func (b *WSLBackend) EnsureSSHServer(ctx context.Context, envID string) error

EnsureSSHServer ensures SSH server is running in the container

func (*WSLBackend) Exec

func (b *WSLBackend) Exec(ctx context.Context, envID string, cmd []string) ([]byte, error)

func (*WSLBackend) Get

func (b *WSLBackend) Get(ctx context.Context, idOrName string) (*Environment, error)

func (*WSLBackend) GetDistro

func (b *WSLBackend) GetDistro(ctx context.Context) (string, error)

GetDistro returns the configured or default WSL distribution

func (*WSLBackend) GetWSLIP

func (b *WSLBackend) GetWSLIP(ctx context.Context) (string, error)

GetWSLIP returns the IP address of the WSL instance

func (*WSLBackend) GetWSLStatus added in v1.1.7

func (b *WSLBackend) GetWSLStatus(ctx context.Context) *WSLStatus

GetWSLStatus checks the detailed status of WSL

func (*WSLBackend) IsAvailable

func (b *WSLBackend) IsAvailable(ctx context.Context) bool

func (*WSLBackend) List

func (b *WSLBackend) List(ctx context.Context) ([]*Environment, error)

func (*WSLBackend) Logs

func (b *WSLBackend) Logs(ctx context.Context, envID string, follow bool) (<-chan string, error)

func (*WSLBackend) Mode

func (b *WSLBackend) Mode() Mode

func (*WSLBackend) Name

func (b *WSLBackend) Name() string

func (*WSLBackend) Remove

func (b *WSLBackend) Remove(ctx context.Context, envID string) error

func (*WSLBackend) SetDistro

func (b *WSLBackend) SetDistro(distro string)

SetDistro sets the WSL distribution name

func (*WSLBackend) Start

func (b *WSLBackend) Start(ctx context.Context, envID string) error

func (*WSLBackend) Stop

func (b *WSLBackend) Stop(ctx context.Context, envID string) error

type WSLStatus added in v1.1.7

type WSLStatus struct {
	WSLInstalled     bool
	HasDistribution  bool
	DistributionName string
	DockerInstalled  bool
	DockerRunning    bool
	ErrorMessage     string
}

WSLStatus represents the detailed status of WSL

func (*WSLStatus) GetInstallGuidance added in v1.1.7

func (s *WSLStatus) GetInstallGuidance() string

GetInstallGuidance returns installation guidance based on the current status

func (*WSLStatus) IsReady added in v1.1.7

func (s *WSLStatus) IsReady() bool

IsReady returns true if WSL is ready to run containers

Jump to

Keyboard shortcuts

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