Skip to content

Commit

Permalink
discover docker version automatically (fixes #47)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Nov 1, 2018
1 parent 39db078 commit 82014bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions utils/docker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"bytes"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -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()))
}

0 comments on commit 82014bc

Please sign in to comment.