MCPcopy Create free account
hub / github.com/ddev/ddev / GetLiveDockerComposeVersion

Function GetLiveDockerComposeVersion

pkg/dockerutil/docker_compose.go:208–235  ·  view source on GitHub ↗

GetLiveDockerComposeVersion runs `docker-compose --version` and caches result

()

Source from the content-addressed store, hash-verified

206
207// GetLiveDockerComposeVersion runs `docker-compose --version` and caches result
208func 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.

Callers 3

GetDockerComposeVersionFunction · 0.85

Calls 4

GetDockerComposePathFunction · 0.92
FileExistsFunction · 0.92
ErrorfMethod · 0.80
CommandMethod · 0.80

Tested by 1