(ctx context.Context, dockerCLI command.Cli, options *scaleOptions, args []string)
| 55 | } |
| 56 | |
| 57 | func 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 | |
| 95 | func runServiceScale(ctx context.Context, apiClient client.ServiceAPIClient, serviceID string, scale uint64) (warnings []string, _ error) { |
| 96 | res, err := apiClient.ServiceInspect(ctx, serviceID, client.ServiceInspectOptions{}) |
no test coverage detected
searching dependent graphs…