(args []string, id string, ensured *imgutil.EnsuredImage, options types.ContainerCreateOptions)
| 448 | } |
| 449 | |
| 450 | func 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 | } |
no test coverage detected
searching dependent graphs…