github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/version/version.go (about) 1 package version 2 3 import ( 4 "context" 5 "fmt" 6 "os/exec" 7 "runtime" 8 "strconv" 9 "strings" 10 11 "github.com/ddev/ddev/pkg/docker" 12 "github.com/ddev/ddev/pkg/dockerutil" 13 "github.com/ddev/ddev/pkg/fileutil" 14 "github.com/ddev/ddev/pkg/globalconfig" 15 "github.com/ddev/ddev/pkg/nodeps" 16 "github.com/ddev/ddev/pkg/versionconstants" 17 dockerClient "github.com/docker/docker/client" 18 ) 19 20 // IMPORTANT: These versions are overridden by version ldflags specifications VERSION_VARIABLES in the Makefile 21 22 // GetVersionInfo returns a map containing the version info defined above. 23 func GetVersionInfo() map[string]string { 24 var err error 25 versionInfo := make(map[string]string) 26 27 versionInfo["DDEV version"] = versionconstants.DdevVersion 28 versionInfo["cgo_enabled"] = strconv.FormatInt(versionconstants.CGOEnabled, 10) 29 versionInfo["web"] = docker.GetWebImage() 30 versionInfo["db"] = docker.GetDBImage(nodeps.MariaDB, "") 31 versionInfo["router"] = docker.GetRouterImage() 32 versionInfo["ddev-ssh-agent"] = docker.GetSSHAuthImage() 33 versionInfo["build info"] = versionconstants.BUILDINFO 34 versionInfo["os"] = runtime.GOOS 35 versionInfo["architecture"] = runtime.GOARCH 36 if versionInfo["docker"], err = dockerutil.GetDockerVersion(); err != nil { 37 versionInfo["docker"] = fmt.Sprintf("Failed to GetDockerVersion(): %v", err) 38 } 39 if versionInfo["docker-api"], err = dockerutil.GetDockerAPIVersion(); err != nil { 40 versionInfo["docker-api"] = fmt.Sprintf("Failed to GetDockerAPIVersion(): %v", err) 41 } 42 if versionInfo["docker-platform"], err = GetDockerPlatform(); err != nil { 43 versionInfo["docker-platform"] = fmt.Sprintf("Failed to GetDockerPlatform(): %v", err) 44 } 45 if versionInfo["docker-compose"], err = dockerutil.GetDockerComposeVersion(); err != nil { 46 versionInfo["docker-compose"] = fmt.Sprintf("Failed to GetDockerComposeVersion(): %v", err) 47 } 48 versionInfo["mutagen"] = versionconstants.RequiredMutagenVersion 49 50 if runtime.GOOS == "windows" { 51 versionInfo["docker type"] = "Docker Desktop For Windows" 52 } 53 54 return versionInfo 55 } 56 57 // GetDockerPlatform gets the platform used for Docker engine 58 func GetDockerPlatform() (string, error) { 59 ctx := context.Background() 60 var client *dockerClient.Client 61 var err error 62 if client, err = dockerClient.NewClientWithOpts(dockerClient.FromEnv, dockerClient.WithAPIVersionNegotiation()); err != nil { 63 return "", err 64 } 65 66 info, err := client.Info(ctx) 67 if err != nil { 68 return "", err 69 } 70 71 platform := info.OperatingSystem 72 switch { 73 case strings.HasPrefix(platform, "Docker Desktop"): 74 platform = "docker-desktop" 75 case strings.HasPrefix(info.Name, "colima"): 76 platform = "colima" 77 case strings.HasPrefix(info.Name, "lima"): 78 platform = "lima" 79 case platform == "OrbStack": 80 platform = "orbstack" 81 case strings.HasPrefix(platform, "Rancher Desktop") || strings.Contains(info.Name, "rancher-desktop"): 82 83 platform = "rancher-desktop" 84 case nodeps.IsWSL2() && info.OSType == "linux": 85 platform = "wsl2-docker-ce" 86 case !nodeps.IsWSL2() && info.OSType == "linux": 87 platform = "linux-docker" 88 default: 89 platform = info.OperatingSystem 90 } 91 92 return platform, nil 93 } 94 95 // GetLiveMutagenVersion runs `mutagen version` and caches result 96 func GetLiveMutagenVersion() (string, error) { 97 if versionconstants.MutagenVersion != "" { 98 return versionconstants.MutagenVersion, nil 99 } 100 101 mutagenPath := globalconfig.GetMutagenPath() 102 103 if !fileutil.FileExists(mutagenPath) { 104 versionconstants.MutagenVersion = "" 105 return versionconstants.MutagenVersion, nil 106 } 107 out, err := exec.Command(mutagenPath, "version").Output() 108 if err != nil { 109 return "", err 110 } 111 112 v := string(out) 113 versionconstants.MutagenVersion = strings.TrimSpace(v) 114 return versionconstants.MutagenVersion, nil 115 }