reuse the func DockerDriver.Version()

This commit is contained in:
guessi 2017-02-16 08:26:44 +08:00
parent 5eae809b0c
commit 66615e3f56
1 changed files with 11 additions and 13 deletions

View File

@ -284,27 +284,25 @@ func (d *DockerDriver) TagImage(id string, repo string, force bool) error {
// for more detail, please refer to the following links:
// - https://docs.docker.com/engine/deprecated/#/f-flag-on-docker-tag
// - https://github.com/docker/docker/pull/23090
output, err := exec.Command("docker", "--version").Output()
version_running, err := d.Version()
if err != nil {
return err
}
match := regexp.MustCompile(version.VersionRegexpRaw).FindSubmatch(output)
if match == nil {
return fmt.Errorf("Unknown Docker version: %s", output)
version_deprecated, err := version.NewVersion(string("1.12.0"))
if err != nil {
// should never reach this line
return err
}
version_running, _ := version.NewVersion(string(match[0]))
version_deprecated, _ := version.NewVersion("1.12.0")
if version_running.LessThan(version_deprecated) {
if force {
if force {
if version_running.LessThan(version_deprecated) {
args = append(args, "-f")
} else {
// do nothing if Docker version >= 1.12.0
log.Printf("[WARN] option: \"force\" will be ignored here")
log.Printf("since it was removed after Docker 1.12.0 released")
}
} else {
// do nothing if Docker version >= 1.12.0
log.Printf("[WARN] option: \"force\" will be ignored here")
log.Printf("since it was removed after Docker 1.12.0 released")
}
args = append(args, id, repo)