buildx/monitor/commands/rollback.go
Jonathan A. Sternberg b35a0f4718
protobuf: remove gogoproto
Removes gogo/protobuf from buildx and updates to a version of
moby/buildkit where gogo is removed.

This also changes how the proto files are generated. This is because
newer versions of protobuf are more strict about name conflicts. If two
files have the same name (even if they are relative paths) and are used
in different protoc commands, they'll conflict in the registry.

Since protobuf file generation doesn't work very well with
`paths=source_relative`, this removes the `go:generate` expression and
just relies on the dockerfile to perform the generation.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-10-02 15:51:59 -05:00

61 lines
1.4 KiB
Go

package commands
import (
"context"
"fmt"
"io"
controllerapi "github.com/docker/buildx/controller/pb"
"github.com/docker/buildx/monitor/types"
"github.com/pkg/errors"
)
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{
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 {
if ref := cm.m.AttachedSessionID(); ref == "" {
return errors.Errorf("no attaching session")
}
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
}