yao/tai/sandbox/docker.go
Max 2bd2a37c4b Implement VNC support in Sandbox V2 tests and enhance Docker test image
- Add new test cases for VNC URL generation and connection in `box_attach_test.go`, ensuring proper functionality of VNC features.
- Update the Docker test image to include VNC desktop components, enhancing the testing environment for graphical applications.
- Modify the entrypoint script to start a virtual framebuffer and VNC server, allowing for remote desktop access during tests.
- Increase the test timeout in the Makefile to accommodate longer-running VNC tests.

These changes improve the testing framework for Sandbox V2 by integrating VNC capabilities, facilitating better testing of graphical applications.
2026-03-05 15:07:53 +08:00

68 lines
1.9 KiB
Go

package sandbox
import (
"context"
"fmt"
"time"
"github.com/docker/docker/client"
)
type dockerSandbox struct {
core dockerCore
}
// NewDocker creates a Sandbox backed by Docker SDK through Tai's Docker API proxy.
// addr should be "tcp://tai-host:2375".
func NewDocker(addr string) (Sandbox, error) {
cli, err := client.NewClientWithOpts(
client.WithHost(addr),
client.WithAPIVersionNegotiation(),
)
if err != nil {
return nil, fmt.Errorf("docker client: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if _, err := cli.Ping(ctx); err != nil {
cli.Close()
return nil, fmt.Errorf("docker via tai: %w", err)
}
return &dockerSandbox{core: dockerCore{cli: cli}}, nil
}
func (d *dockerSandbox) Create(ctx context.Context, opts CreateOptions) (string, error) {
return d.core.create(ctx, opts, true)
}
func (d *dockerSandbox) Start(ctx context.Context, id string) error {
return d.core.start(ctx, id)
}
func (d *dockerSandbox) Stop(ctx context.Context, id string, timeout time.Duration) error {
return d.core.stop(ctx, id, int(timeout.Seconds()))
}
func (d *dockerSandbox) Remove(ctx context.Context, id string, force bool) error {
return d.core.remove(ctx, id, force)
}
func (d *dockerSandbox) Exec(ctx context.Context, id string, cmd []string, opts ExecOptions) (*ExecResult, error) {
return d.core.exec(ctx, id, cmd, opts)
}
func (d *dockerSandbox) ExecStream(ctx context.Context, id string, cmd []string, opts ExecOptions) (*StreamHandle, error) {
return d.core.execStream(ctx, id, cmd, opts)
}
func (d *dockerSandbox) Inspect(ctx context.Context, id string) (*ContainerInfo, error) {
return d.core.inspect(ctx, id)
}
func (d *dockerSandbox) List(ctx context.Context, opts ListOptions) ([]ContainerInfo, error) {
return d.core.list(ctx, opts)
}
func (d *dockerSandbox) Close() error {
return d.core.cli.Close()
}