feat: refactor to ymsctl & yms-daemon
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user