MCPcopy Create free account
hub / github.com/containerd/nerdctl / startAction

Function startAction

cmd/nerdctl/compose/compose_start.go:51–99  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

49}
50
51func 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
101func startContainers(ctx context.Context, client *containerd.Client, containers []containerd.Container, globalOptions *types.GlobalCommandOptions, nerdctlCmd string, nerdctlArgs []string) error {
102 eg, ctx := errgroup.WithContext(ctx)

Callers

nothing calls this directly

Calls 8

ProcessRootCmdFlagsFunction · 0.92
GlobalFlagsFunction · 0.92
NewClientFunction · 0.92
NewFunction · 0.92
getComposeOptionsFunction · 0.85
startContainersFunction · 0.85
ServicesMethod · 0.80
ContainersMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…