MCPcopy
hub / github.com/containers/toolbox / ResolveContainerAndImageNames

Function ResolveContainerAndImageNames

src/pkg/utils/utils.go:777–894  ·  view source on GitHub ↗

ResolveContainerAndImageNames takes care of standardizing names of containers and images. If no image name is specified then the base image will reflect the platform of the host (even the version). If no container name is specified then the name of the image will be used. If the host system is unk

(container, distroCLI, imageCLI, releaseCLI string)

Source from the content-addressed store, hash-verified

775//
776// If the host system is unknown then the base image will be 'fedora-toolbox' with a default version
777func ResolveContainerAndImageNames(container, distroCLI, imageCLI, releaseCLI string) (string, string, string, error) {
778 logrus.Debug("Resolving container and image names")
779 logrus.Debugf("Container: '%s'", container)
780 logrus.Debugf("Distribution (CLI): '%s'", distroCLI)
781 logrus.Debugf("Image (CLI): '%s'", imageCLI)
782 logrus.Debugf("Release (CLI): '%s'", releaseCLI)
783
784 distro, distroSource := distroCLI, optionValueCLI
785 image, release := imageCLI, releaseCLI
786
787 if distroCLI == "" {
788 distro, distroSource = distroDefault, optionValueDefault
789 if viper.IsSet("general.distro") {
790 distro, distroSource = viper.GetString("general.distro"), optionValueConfigFile
791 }
792 }
793
794 distroObj, supportedDistro := supportedDistros[distro]
795 if !supportedDistro {
796 return "", "", "", &DistroError{distro, ErrDistroUnsupported}
797 }
798
799 if distro == distroDefault {
800 if releaseCLI == "" {
801 release = releaseDefault
802 if viper.IsSet("general.release") {
803 release = viper.GetString("general.release")
804 }
805 }
806 } else {
807 if distroObj.ReleaseRequired {
808 if releaseCLI == "" && !viper.IsSet("general.release") {
809 return "", "", "", &DistroError{distro, ErrDistroWithoutRelease}
810 }
811
812 if releaseCLI == "" {
813 release = viper.GetString("general.release")
814 }
815
816 if release == "" {
817 panicMsg := fmt.Sprintf("cannot find release for non-default distribution %s", distro)
818 panic(panicMsg)
819 }
820 } else {
821 switch distroSource {
822 case optionValueCLI:
823 // 'release' already set to 'releaseCLI'
824 case optionValueConfigFile:
825 if releaseCLI == "" {
826 if viper.IsSet("general.release") {
827 release = viper.GetString("general.release")
828 }
829 }
830 case optionValueDefault:
831 panic("distro must be non-default")
832 default:
833 panic("cannot handle new OptionValueSource")
834 }

Callers 1

SetUpConfigurationFunction · 0.85

Calls 5

parseReleaseFunction · 0.85
getDefaultImageForDistroFunction · 0.85
ImageReferenceGetTagFunction · 0.85
IsContainerNameValidFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…