github.com/containers/podman/v4@v4.9.4/pkg/specgen/generate/oci.go (about)

     1  //go:build !remote
     2  // +build !remote
     3  
     4  package generate
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  
    10  	"github.com/containers/common/libimage"
    11  	"github.com/containers/podman/v4/libpod/define"
    12  	"github.com/containers/podman/v4/pkg/specgen"
    13  	"github.com/opencontainers/runtime-tools/generate"
    14  )
    15  
    16  func addRlimits(s *specgen.SpecGenerator, g *generate.Generator) {
    17  	g.Config.Process.Rlimits = nil
    18  
    19  	for _, u := range s.Rlimits {
    20  		name := "RLIMIT_" + strings.ToUpper(u.Type)
    21  		u = subNegativeOne(u)
    22  		g.AddProcessRlimits(name, u.Hard, u.Soft)
    23  	}
    24  }
    25  
    26  // Produce the final command for the container.
    27  func makeCommand(s *specgen.SpecGenerator, imageData *libimage.ImageData) ([]string, error) {
    28  	finalCommand := []string{}
    29  
    30  	entrypoint := s.Entrypoint
    31  	if entrypoint == nil && imageData != nil {
    32  		entrypoint = imageData.Config.Entrypoint
    33  	}
    34  
    35  	// Don't append the entrypoint if it is [""]
    36  	if len(entrypoint) != 1 || entrypoint[0] != "" {
    37  		finalCommand = append(finalCommand, entrypoint...)
    38  	}
    39  
    40  	// Only use image command if the user did not manually set an
    41  	// entrypoint.
    42  	command := s.Command
    43  	if len(command) == 0 && imageData != nil && len(s.Entrypoint) == 0 {
    44  		command = imageData.Config.Cmd
    45  	}
    46  
    47  	finalCommand = append(finalCommand, command...)
    48  
    49  	if len(finalCommand) == 0 {
    50  		return nil, fmt.Errorf("no command or entrypoint provided, and no CMD or ENTRYPOINT from image")
    51  	}
    52  
    53  	if s.Init {
    54  		// bind mount for this binary is added in addContainerInitBinary()
    55  		finalCommand = append([]string{define.ContainerInitPath, "--"}, finalCommand...)
    56  	}
    57  
    58  	return finalCommand, nil
    59  }