Files
buildx/monitor/commands/rollback.go
T
Jonathan A. Sternberg 1d7cda1232 controller: remove remaining parts of the controller
Removes all references to the controller and moves the remaining
sections of code to other packages.

Processes has been moved to monitor where it is used and the data
structs have been removed so buildflags is used directly. The controller
build function has been moved to the commands package.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-06-05 11:57:03 -05:00

57 lines
1.3 KiB
Go

package commands
import (
"context"
"fmt"
"io"
"github.com/docker/buildx/build"
"github.com/docker/buildx/monitor/types"
)
type RollbackCmd struct {
m types.Monitor
invokeConfig *build.InvokeConfig
stdout io.WriteCloser
}
func NewRollbackCmd(m types.Monitor, invokeConfig *build.InvokeConfig, stdout io.WriteCloser) types.Command {
return &RollbackCmd{m, invokeConfig, stdout}
}
func (cm *RollbackCmd) Info() types.CommandInfo {
return types.CommandInfo{
Name: "rollback",
HelpMessage: "re-runs the interactive container with the step's rootfs contents",
HelpMessageLong: `
Usage:
rollback [FLAGS] [COMMAND] [ARG...]
Flags:
--init Run the container with the initial rootfs of that step.
COMMAND and ARG... will be executed in the container.
`,
}
}
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:]
cfg.NoCmd = false
}
}
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
}