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

Function generateRootfsOpts

pkg/cmd/container/create.go:450–571  ·  view source on GitHub ↗
(args []string, id string, ensured *imgutil.EnsuredImage, options types.ContainerCreateOptions)

Source from the content-addressed store, hash-verified

448}
449
450func generateRootfsOpts(args []string, id string, ensured *imgutil.EnsuredImage, options types.ContainerCreateOptions) (opts []oci.SpecOpts, cOpts []containerd.NewContainerOpts, err error) {
451 if !options.Rootfs {
452 cOpts = append(cOpts,
453 containerd.WithImage(ensured.Image),
454 containerd.WithSnapshotter(ensured.Snapshotter),
455 containerd.WithImageStopSignal(ensured.Image, "SIGTERM"),
456 )
457
458 if len(ensured.ImageConfig.Env) == 0 {
459 opts = append(opts, oci.WithDefaultPathEnv)
460 }
461 for ind, env := range ensured.ImageConfig.Env {
462 if strings.HasPrefix(env, "PATH=") {
463 break
464 }
465 if ind == len(ensured.ImageConfig.Env)-1 {
466 opts = append(opts, oci.WithDefaultPathEnv)
467 }
468 }
469 } else {
470 absRootfs, err := filepath.Abs(args[0])
471 if err != nil {
472 return nil, nil, err
473 }
474 opts = append(opts, oci.WithRootFSPath(absRootfs), oci.WithDefaultPathEnv)
475 }
476
477 entrypointPath := ""
478 if ensured != nil {
479 if len(ensured.ImageConfig.Entrypoint) > 0 {
480 entrypointPath = ensured.ImageConfig.Entrypoint[0]
481 } else if len(ensured.ImageConfig.Cmd) > 0 {
482 entrypointPath = ensured.ImageConfig.Cmd[0]
483 }
484 }
485
486 if !options.Rootfs && !options.EntrypointChanged {
487 opts = append(opts, oci.WithImageConfigArgs(ensured.Image, args[1:]))
488 } else {
489 if !options.Rootfs {
490 opts = append(opts, oci.WithImageConfig(ensured.Image))
491 }
492 var processArgs []string
493 if len(options.Entrypoint) != 0 {
494 processArgs = append(processArgs, options.Entrypoint...)
495 }
496 if len(args) > 1 {
497 processArgs = append(processArgs, args[1:]...)
498 }
499 if len(processArgs) == 0 {
500 // error message is from Podman
501 return nil, nil, errors.New("no command or entrypoint provided, and no CMD or ENTRYPOINT from image")
502 }
503
504 entrypointPath = processArgs[0]
505
506 opts = append(opts, oci.WithProcessArgs(processArgs...))
507 }

Callers 1

CreateFunction · 0.85

Calls 4

ConvertKVStringsToMapFunction · 0.92
DedupeStrSliceFunction · 0.92
MapBoolValueAsOptFunction · 0.92
withStopFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…