feat: refactor to ymsctl & yms-daemon

This commit is contained in:
2026-08-17 02:10:10 +08:00
parent 7755da72e7
commit 79f18fcdea
23 changed files with 394 additions and 47 deletions
+1
View File
@@ -79,6 +79,7 @@ type Engine interface {
InspectImage(context.Context, string) (Image, error)
CreateContainer(context.Context, ContainerSpec) (Container, error)
StartContainer(context.Context, string) error
ContainerLogs(context.Context, string) (io.ReadCloser, error)
StopContainer(context.Context, string) error
InspectContainer(context.Context, string) (Container, error)
RemoveContainer(context.Context, string, bool) error
+15
View File
@@ -1,6 +1,7 @@
package containerengine
import (
"bytes"
"context"
"encoding/json"
"errors"
@@ -8,6 +9,7 @@ import (
"io"
cerrdefs "github.com/containerd/errdefs"
"github.com/moby/moby/api/pkg/stdcopy"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/jsonstream"
"github.com/moby/moby/api/types/mount"
@@ -148,6 +150,19 @@ func (e *MobyEngine) StartContainer(ctx context.Context, idOrName string) error
return nil
}
func (e *MobyEngine) ContainerLogs(ctx context.Context, idOrName string) (io.ReadCloser, error) {
stream, err := e.client.ContainerLogs(ctx, idOrName, client.ContainerLogsOptions{ShowStdout: true, ShowStderr: true, Tail: "all"})
if err != nil {
return nil, engineError("read container logs", err)
}
defer stream.Close()
var output bytes.Buffer
if _, err := stdcopy.StdCopy(&output, &output, stream); err != nil {
return nil, fmt.Errorf("decode container logs: %w", err)
}
return io.NopCloser(bytes.NewReader(output.Bytes())), nil
}
func (e *MobyEngine) StopContainer(ctx context.Context, idOrName string) error {
if _, err := e.client.ContainerStop(ctx, idOrName, client.ContainerStopOptions{}); err != nil {
return engineError("stop container", err)