von-network icon indicating copy to clipboard operation
von-network copied to clipboard

Improve detection of docker compose version and syntax

Open bjoern-arnold opened this issue 3 years ago • 7 comments

#171 introduced a function to detect the version of docker compose and -depending on the determined version- sets the correct command syntax. However, the version detection assumes that the command is still available as "docker-compose" dockerComposeVersion=$(docker-compose version --short | sed 's~v~~;s~-.*~~') This is not the case with my installation (Ubuntu 20.04, Docker version 20.10.16, build aa7e414 with docker-compose plugin v2.5.0). Since Compose V2 went GA in April I suggest to make the new syntax the default for both the dockerCompose variable and the version detection. As a fallback, the old syntax could still be supported by introducing something like:

dockerComposeVersion=$(docker compose version --short | sed 's~v~~;s~-.*~~')
if [ -z $dockerComposeVersion ]; then
  dockerComposeVersion=$(docker-compose version --short | sed 's~v~~;s~-.*~~')
fi

bjoern-arnold avatar Jul 25 '22 11:07 bjoern-arnold

The reason it was not done that way is because the new docker compose command will always return the newer docker compose version even if you are not using it and have it disabled in docker-desktop.

Example:

$ docker compose version --short
2.6.1

$ docker-compose version --short
1.29.2

image


When you select Use Docker Compose V2 docker-compose will return the new version:

image

$ docker-compose version --short
2.6.1

$ docker compose version --short
2.6.1

$ docker version
Client:
 Cloud integration: v1.0.24
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:09:02 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.10.1 (82475)
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:23 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

WadeBarnes avatar Jul 25 '22 12:07 WadeBarnes

@bjoern-arnold, are you able to switch back and forth between the old and new docker-compose versions in your environment, and if so how does it report the version being used?

WadeBarnes avatar Jul 25 '22 12:07 WadeBarnes

@WadeBarnes no, I'm not abel to switch versions. I assume it's because I've installed Docker Engine only and the new "docker compose" command does not allow switching versions any more (as described e.g. here). My issue is that there is no "docker-compose" command available any more and thus the manage script fails at line 22

bjoern-arnold avatar Jul 27 '22 10:07 bjoern-arnold

In that case it is more appropriate to detect whether the docker-compose command is available on the system first before detecting the version being used.

WadeBarnes avatar Jul 27 '22 12:07 WadeBarnes

Would you like to give that a try and submit a PR?

WadeBarnes avatar Jul 27 '22 12:07 WadeBarnes

@WadeBarnes I'm contributing as a Bosch associate and thus I have to get the project approved by our open source officer. This includes an evaluation of the project repo. He found that your policy requires a CONTRIBUTING.md to be present which is not true for this project (see here). Could you please add this file?

bjoern-arnold avatar Aug 10 '22 05:08 bjoern-arnold

Done

WadeBarnes avatar Aug 12 '22 11:08 WadeBarnes

Already handled by #239

bjoern-arnold avatar Jan 23 '23 12:01 bjoern-arnold