GetLiveDockerComposeVersion runs `docker-compose --version` and caches result
()
| 206 | |
| 207 | // GetLiveDockerComposeVersion runs `docker-compose --version` and caches result |
| 208 | func GetLiveDockerComposeVersion() (string, error) { |
| 209 | if globalconfig.DockerComposeVersion != "" { |
| 210 | return globalconfig.DockerComposeVersion, nil |
| 211 | } |
| 212 | |
| 213 | composePath, err := globalconfig.GetDockerComposePath() |
| 214 | if err != nil { |
| 215 | return "", err |
| 216 | } |
| 217 | |
| 218 | if !fileutil.FileExists(composePath) { |
| 219 | globalconfig.DockerComposeVersion = "" |
| 220 | return globalconfig.DockerComposeVersion, fmt.Errorf("docker-compose does not exist at %s", composePath) |
| 221 | } |
| 222 | out, err := exec.Command(composePath, "version", "--short").Output() |
| 223 | if err != nil { |
| 224 | return "", err |
| 225 | } |
| 226 | v := strings.Trim(string(out), "\r\n") |
| 227 | |
| 228 | // docker-compose v1 and v2.3.3 return a version without the prefix "v", so add it. |
| 229 | if !strings.HasPrefix(v, "v") { |
| 230 | v = "v" + v |
| 231 | } |
| 232 | |
| 233 | globalconfig.DockerComposeVersion = v |
| 234 | return globalconfig.DockerComposeVersion, nil |
| 235 | } |
| 236 | |
| 237 | // DownloadDockerComposeIfNeeded downloads the proper version of docker-compose |
| 238 | // if it's either not yet installed or has the wrong version. |