-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathrollback.go
More file actions
63 lines (50 loc) · 1.61 KB
/
rollback.go
File metadata and controls
63 lines (50 loc) · 1.61 KB
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
61
62
63
package service
import (
"context"
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
func newRollbackCommand(dockerCLI command.Cli) *cobra.Command {
options := newServiceOptions()
cmd := &cobra.Command{
Use: "rollback [OPTIONS] SERVICE",
Short: "Revert changes to a service's configuration",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runRollback(cmd.Context(), dockerCLI, options, args[0])
},
Annotations: map[string]string{"version": "1.31"},
ValidArgsFunction: completeServiceNames(dockerCLI),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
flags.BoolVarP(&options.quiet, flagQuiet, "q", false, "Suppress progress output")
addDetachFlag(flags, &options.detach)
return cmd
}
func runRollback(ctx context.Context, dockerCLI command.Cli, options *serviceOptions, serviceID string) error {
apiClient := dockerCLI.Client()
res, err := apiClient.ServiceInspect(ctx, serviceID, client.ServiceInspectOptions{})
if err != nil {
return err
}
response, err := apiClient.ServiceUpdate(ctx, res.Service.ID, client.ServiceUpdateOptions{
Version: res.Service.Version,
Spec: res.Service.Spec,
Rollback: "previous", // TODO(thaJeztah): this should have a const defined
})
if err != nil {
return err
}
for _, warning := range response.Warnings {
_, _ = fmt.Fprintln(dockerCLI.Err(), warning)
}
_, _ = fmt.Fprintln(dockerCLI.Out(), serviceID)
if options.detach {
return nil
}
return WaitOnService(ctx, dockerCLI, serviceID, options.quiet)
}