- Introduce new Tai SDK tests in the GitHub workflows, requiring a Tai container with Docker socket mount for execution. - Update the Makefile to include a dedicated target for running Tai SDK tests, enhancing test coverage for the Tai integration. - Modify the Go module dependencies to include the pierrec/lz4 package, ensuring compatibility with the new tests. - Adjust test folder selection logic in the Makefile to exclude additional directories, streamlining the testing process.
95 lines
2.2 KiB
Go
95 lines
2.2 KiB
Go
package sandbox
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Sandbox manages container lifecycle.
|
|
// Local connects directly to a Docker daemon; Docker/Containerd/K8s connect via Tai proxy.
|
|
type Sandbox interface {
|
|
Create(ctx context.Context, opts CreateOptions) (string, error)
|
|
Start(ctx context.Context, id string) error
|
|
Stop(ctx context.Context, id string, timeout time.Duration) error
|
|
Remove(ctx context.Context, id string, force bool) error
|
|
Exec(ctx context.Context, id string, cmd []string, opts ExecOptions) (*ExecResult, error)
|
|
Inspect(ctx context.Context, id string) (*ContainerInfo, error)
|
|
List(ctx context.Context, opts ListOptions) ([]ContainerInfo, error)
|
|
Close() error
|
|
}
|
|
|
|
// CreateOptions configures a new container.
|
|
type CreateOptions struct {
|
|
Name string
|
|
Image string
|
|
Cmd []string
|
|
Env map[string]string
|
|
Binds []string
|
|
WorkingDir string
|
|
Memory int64 // bytes, 0 = no limit
|
|
CPUs float64 // 0 = no limit
|
|
VNC bool
|
|
Ports []PortMapping
|
|
}
|
|
|
|
// PortMapping maps a container port to a host port.
|
|
type PortMapping struct {
|
|
ContainerPort int
|
|
HostPort int // 0 = random
|
|
HostIP string // default "127.0.0.1"
|
|
Protocol string // "tcp" (default) or "udp"
|
|
}
|
|
|
|
// ContainerInfo describes a running or stopped container.
|
|
type ContainerInfo struct {
|
|
ID string
|
|
Name string
|
|
Image string
|
|
Status string // "created", "running", "exited", "removing"
|
|
IP string
|
|
Ports []PortMapping
|
|
}
|
|
|
|
// ExecOptions configures a command execution inside a container.
|
|
type ExecOptions struct {
|
|
WorkDir string
|
|
Env map[string]string
|
|
}
|
|
|
|
// ExecResult holds output from an exec command.
|
|
type ExecResult struct {
|
|
ExitCode int
|
|
Stdout string
|
|
Stderr string
|
|
}
|
|
|
|
// ListOptions filters container listing.
|
|
type ListOptions struct {
|
|
All bool // include stopped containers
|
|
Labels map[string]string // filter by labels
|
|
}
|
|
|
|
func envSlice(m map[string]string) []string {
|
|
if len(m) == 0 {
|
|
return nil
|
|
}
|
|
s := make([]string, 0, len(m))
|
|
for k, v := range m {
|
|
s = append(s, k+"="+v)
|
|
}
|
|
return s
|
|
}
|
|
|
|
func proto(p string) string {
|
|
if p == "" {
|
|
return "tcp"
|
|
}
|
|
return p
|
|
}
|
|
|
|
func hostIP(ip string) string {
|
|
if ip == "" {
|
|
return "127.0.0.1"
|
|
}
|
|
return ip
|
|
}
|