MCPcopy Index your code
hub / github.com/docker/cli / runScale

Function runScale

cli/command/service/scale.go:57–93  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, options *scaleOptions, args []string)

Source from the content-addressed store, hash-verified

55}
56
57func runScale(ctx context.Context, dockerCLI command.Cli, options *scaleOptions, args []string) error {
58 apiClient := dockerCLI.Client()
59 var (
60 errs []error
61 serviceIDs = make([]string, 0, len(args))
62 )
63 for _, arg := range args {
64 serviceID, scaleStr, _ := strings.Cut(arg, "=")
65
66 // validate input arg scale number
67 scale, err := strconv.ParseUint(scaleStr, 10, 64)
68 if err != nil {
69 errs = append(errs, fmt.Errorf("%s: invalid replicas value %s: %v", serviceID, scaleStr, err))
70 continue
71 }
72
73 warnings, err := runServiceScale(ctx, apiClient, serviceID, scale)
74 if err != nil {
75 errs = append(errs, fmt.Errorf("%s: %v", serviceID, err))
76 continue
77 }
78 for _, warning := range warnings {
79 _, _ = fmt.Fprintln(dockerCLI.Err(), warning)
80 }
81 _, _ = fmt.Fprintf(dockerCLI.Out(), "%s scaled to %d\n", serviceID, scale)
82 serviceIDs = append(serviceIDs, serviceID)
83 }
84
85 if len(serviceIDs) > 0 && !options.detach {
86 for _, serviceID := range serviceIDs {
87 if err := WaitOnService(ctx, dockerCLI, serviceID, false); err != nil {
88 errs = append(errs, fmt.Errorf("%s: %v", serviceID, err))
89 }
90 }
91 }
92 return errors.Join(errs...)
93}
94
95func runServiceScale(ctx context.Context, apiClient client.ServiceAPIClient, serviceID string, scale uint64) (warnings []string, _ error) {
96 res, err := apiClient.ServiceInspect(ctx, serviceID, client.ServiceInspectOptions{})

Callers 1

newScaleCommandFunction · 0.85

Calls 5

runServiceScaleFunction · 0.85
WaitOnServiceFunction · 0.85
ClientMethod · 0.65
ErrMethod · 0.65
OutMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…