- Add new gRPC endpoint for Heartbeat in the Yao service, enabling communication with the sandbox. - Update Makefile to include a dedicated unit test target for Sandbox V2, ensuring proper testing of new features. - Enhance CI workflows to incorporate Sandbox V2 tests, allowing for dual-mode testing (local and remote) with Docker. - Modify .gitignore to exclude specific Docker files while allowing shell scripts for Sandbox V2. - Update documentation in DESIGN.md to reflect the new architecture and capabilities of the Sandbox V2. These changes enhance the Yao SDK's functionality, providing improved support for sandbox operations and testing.
157 lines
2.7 KiB
Go
157 lines
2.7 KiB
Go
package sandbox
|
|
|
|
import (
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/yaoapp/yao/tai"
|
|
)
|
|
|
|
type LifecyclePolicy string
|
|
|
|
const (
|
|
OneShot LifecyclePolicy = "oneshot"
|
|
Session LifecyclePolicy = "session"
|
|
LongRunning LifecyclePolicy = "longrunning"
|
|
Persistent LifecyclePolicy = "persistent"
|
|
)
|
|
|
|
type Pool struct {
|
|
Name string
|
|
Addr string
|
|
Options []tai.Option
|
|
MaxPerUser int
|
|
MaxTotal int
|
|
IdleTimeout time.Duration
|
|
MaxLifetime time.Duration
|
|
}
|
|
|
|
type PoolInfo struct {
|
|
Name string
|
|
Addr string
|
|
Connected bool
|
|
Boxes int
|
|
MaxPerUser int
|
|
MaxTotal int
|
|
IdleTimeout time.Duration
|
|
MaxLifetime time.Duration
|
|
}
|
|
|
|
type PortMapping struct {
|
|
ContainerPort int
|
|
HostPort int
|
|
HostIP string
|
|
Protocol string
|
|
}
|
|
|
|
type CreateOptions struct {
|
|
ID string
|
|
Owner string
|
|
Labels map[string]string
|
|
Pool string
|
|
Image string
|
|
WorkDir string
|
|
User string
|
|
Env map[string]string
|
|
Memory int64
|
|
CPUs float64
|
|
VNC bool
|
|
Ports []PortMapping
|
|
Policy LifecyclePolicy
|
|
IdleTimeout time.Duration
|
|
}
|
|
|
|
type ListOptions struct {
|
|
Owner string
|
|
Pool string
|
|
Labels map[string]string
|
|
}
|
|
|
|
type execConfig struct {
|
|
WorkDir string
|
|
Env map[string]string
|
|
Timeout time.Duration
|
|
}
|
|
|
|
type ExecOption func(*execConfig)
|
|
|
|
func WithWorkDir(dir string) ExecOption {
|
|
return func(c *execConfig) {
|
|
c.WorkDir = dir
|
|
}
|
|
}
|
|
|
|
func WithEnv(env map[string]string) ExecOption {
|
|
return func(c *execConfig) {
|
|
c.Env = env
|
|
}
|
|
}
|
|
|
|
func WithTimeout(timeout time.Duration) ExecOption {
|
|
return func(c *execConfig) {
|
|
c.Timeout = timeout
|
|
}
|
|
}
|
|
|
|
type ExecResult struct {
|
|
ExitCode int
|
|
Stdout string
|
|
Stderr string
|
|
}
|
|
|
|
type ExecStream struct {
|
|
Stdout io.ReadCloser
|
|
Stderr io.ReadCloser
|
|
Stdin io.WriteCloser
|
|
Wait func() (int, error)
|
|
Cancel func()
|
|
}
|
|
|
|
type attachConfig struct {
|
|
Protocol string
|
|
Path string
|
|
Headers map[string]string
|
|
}
|
|
|
|
type AttachOption func(*attachConfig)
|
|
|
|
func WithProtocol(protocol string) AttachOption {
|
|
return func(c *attachConfig) {
|
|
c.Protocol = protocol
|
|
}
|
|
}
|
|
|
|
func WithPath(path string) AttachOption {
|
|
return func(c *attachConfig) {
|
|
c.Path = path
|
|
}
|
|
}
|
|
|
|
func WithHeaders(headers map[string]string) AttachOption {
|
|
return func(c *attachConfig) {
|
|
c.Headers = headers
|
|
}
|
|
}
|
|
|
|
type ServiceConn struct {
|
|
Read func() ([]byte, error)
|
|
Write func(data []byte) error
|
|
Events <-chan []byte
|
|
URL string
|
|
Close func() error
|
|
}
|
|
|
|
type BoxInfo struct {
|
|
ID string
|
|
ContainerID string
|
|
Pool string
|
|
Owner string
|
|
Status string
|
|
Policy LifecyclePolicy
|
|
Labels map[string]string
|
|
Image string
|
|
CreatedAt time.Time
|
|
LastActive time.Time
|
|
ProcessCount int
|
|
VNC bool
|
|
}
|