File: rollback.go

package info (click to toggle)
docker-buildx 0.13.1%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,356 kB
  • sloc: sh: 299; makefile: 87
file content (60 lines) | stat: -rw-r--r-- 1,445 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
}