better interoperability with docker-compose on version label

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-06-16 10:55:44 +02:00
parent 9ea051f64e
commit df9fa2d2d8
No known key found for this signature in database
GPG key ID: 9858809D6F8F6E7E
5 changed files with 28 additions and 6 deletions

View file

@ -16,6 +16,14 @@
package api
import (
"fmt"
"github.com/hashicorp/go-version"
"github.com/docker/compose-cli/internal"
)
const (
// ProjectLabel allow to track resource related to a compose project
ProjectLabel = "com.docker.compose.project"
@ -42,3 +50,15 @@ const (
// VersionLabel stores the compose tool version used to run application
VersionLabel = "com.docker.compose.version"
)
var ComposeVersion string
func init() {
v, err := version.NewVersion(internal.Version)
if err == nil {
segments := v.Segments()
if len(segments) > 2 {
ComposeVersion = fmt.Sprintf("%d.%d.%d", segments[0], segments[1], segments[2])
}
}
}