(cmd *cobra.Command, args []string)
| 49 | } |
| 50 | |
| 51 | func startAction(cmd *cobra.Command, args []string) error { |
| 52 | globalOptions, err := helpers.ProcessRootCmdFlags(cmd) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | |
| 57 | nerdctlCmd, nerdctlArgs := helpers.GlobalFlags(cmd) |
| 58 | |
| 59 | client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), globalOptions.Namespace, globalOptions.Address) |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | defer cancel() |
| 64 | options, err := getComposeOptions(cmd, globalOptions.DebugFull, globalOptions.Experimental) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | c, err := compose.New(client, globalOptions, options, cmd.OutOrStdout(), cmd.ErrOrStderr()) |
| 69 | if err != nil { |
| 70 | return err |
| 71 | } |
| 72 | |
| 73 | // TODO(djdongjin): move to `pkg/composer` and rewrite `c.Services + for-loop` |
| 74 | // with `c.project.WithServices` after refactor (#1639) is done. |
| 75 | services, err := c.Services(ctx, args...) |
| 76 | if err != nil { |
| 77 | return err |
| 78 | } |
| 79 | for _, svc := range services { |
| 80 | svcName := svc.Unparsed.Name |
| 81 | containers, err := c.Containers(ctx, svcName) |
| 82 | if err != nil { |
| 83 | return err |
| 84 | } |
| 85 | // return error if no containers and service replica is not zero |
| 86 | if len(containers) == 0 { |
| 87 | if len(svc.Containers) == 0 { |
| 88 | continue |
| 89 | } |
| 90 | return fmt.Errorf("service %q has no container to start", svcName) |
| 91 | } |
| 92 | |
| 93 | if err := startContainers(ctx, client, containers, &globalOptions, nerdctlCmd, nerdctlArgs); err != nil { |
| 94 | return err |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | func startContainers(ctx context.Context, client *containerd.Client, containers []containerd.Container, globalOptions *types.GlobalCommandOptions, nerdctlCmd string, nerdctlArgs []string) error { |
| 102 | eg, ctx := errgroup.WithContext(ctx) |
nothing calls this directly
no test coverage detected
searching dependent graphs…