mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 05:27:07 +08:00
monitor: Move commands to a separated package
This commit moves monitor commands to `monior/commands` package. Commands still need access to the `monitor` object and buildx controller so this commit enables this via `Monitor` interface stored in `monitor/types`. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
43
monitor/commands/rollback.go
Normal file
43
monitor/commands/rollback.go
Normal file
@ -0,0 +1,43 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
controllerapi "github.com/docker/buildx/controller/pb"
|
||||
"github.com/docker/buildx/monitor/types"
|
||||
)
|
||||
|
||||
type RollbackCmd struct {
|
||||
m types.Monitor
|
||||
|
||||
invokeConfig controllerapi.InvokeConfig
|
||||
stdout io.WriteCloser
|
||||
}
|
||||
|
||||
func NewRollbackCmd(m types.Monitor, invokeConfig controllerapi.InvokeConfig, stdout io.WriteCloser) types.Command {
|
||||
return &RollbackCmd{m, invokeConfig, stdout}
|
||||
}
|
||||
|
||||
func (cm *RollbackCmd) Info() types.CommandInfo {
|
||||
return types.CommandInfo{HelpMessage: "re-runs the interactive container with initial rootfs contents"}
|
||||
}
|
||||
|
||||
func (cm *RollbackCmd) Exec(ctx context.Context, args []string) error {
|
||||
cfg := cm.invokeConfig
|
||||
if len(args) >= 2 {
|
||||
cmds := args[1:]
|
||||
if cmds[0] == "--init" {
|
||||
cfg.Initial = true
|
||||
cmds = cmds[1:]
|
||||
}
|
||||
if len(cmds) > 0 {
|
||||
cfg.Entrypoint = []string{cmds[0]}
|
||||
cfg.Cmd = cmds[1:]
|
||||
}
|
||||
}
|
||||
id := cm.m.Rollback(ctx, cfg)
|
||||
fmt.Fprintf(cm.stdout, "Interactive container was restarted with process %q. Press Ctrl-a-c to switch to the new container\n", id)
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user