diff --git a/image/image.go b/image/image.go index 27066921..ce3f7d44 100644 --- a/image/image.go +++ b/image/image.go @@ -22,7 +22,7 @@ import ( ) // TODO: this file should be rethought... but since it's only for preprocessing it'll be tech debt for now. -const dockerVersion = "1.26" +var dockerVersion string func check(e error) { if e != nil { @@ -199,6 +199,8 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree, float64, fi var manifest ImageManifest var layerMap = make(map[string]*filetree.FileTree) var trees = make([]*filetree.FileTree, 0) + dockerVersion = utils.DiscoverDockerVersion() + logrus.Debug("Using docker version:", dockerVersion) // pull the image if it does not exist ctx := context.Background() diff --git a/utils/docker.go b/utils/docker.go index 786a3a48..c7096f56 100644 --- a/utils/docker.go +++ b/utils/docker.go @@ -1,6 +1,7 @@ package utils import ( + "bytes" "os" "os/exec" "strings" @@ -30,3 +31,15 @@ func cleanArgs(s []string) []string { } return r } + +func DiscoverDockerVersion() string { + cmd := exec.Command("docker", "version", "--format", "{{.Server.APIVersion}}") + cmdOutput := &bytes.Buffer{} + cmd.Stdout = cmdOutput + + err := cmd.Run() + if err != nil { + panic(err) + } + return strings.TrimSpace(string(cmdOutput.Bytes())) +}