Conditional ignore `force` flag for `docker-tag`
`docker tag -f` will now become an error, since it was removed after upgrading docker daemon to 1.12.0 (or later) this PR is to bypass `force` flag if docker >= 1.12.0 was detected reference: - https://docs.docker.com/engine/deprecated/#/f-flag-on-docker-tag Signed-off-by: guessi <guessi@gmail.com>
This commit is contained in:
parent
99ffcfc269
commit
c5e01da3c6
|
@ -275,8 +275,35 @@ func (d *DockerDriver) StopContainer(id string) error {
|
||||||
|
|
||||||
func (d *DockerDriver) TagImage(id string, repo string, force bool) error {
|
func (d *DockerDriver) TagImage(id string, repo string, force bool) error {
|
||||||
args := []string{"tag"}
|
args := []string{"tag"}
|
||||||
if force {
|
|
||||||
args = append(args, "-f")
|
// detect running docker version before tagging
|
||||||
|
// flag `force` for docker tagging was removed after Docker 1.12.0
|
||||||
|
// to keep its backward compatibility, we are not going to remove `force`
|
||||||
|
// option, but to ignore it when Docker version >= 1.12.0
|
||||||
|
//
|
||||||
|
// 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()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
match := regexp.MustCompile(version.VersionRegexpRaw).FindSubmatch(output)
|
||||||
|
if match == nil {
|
||||||
|
return fmt.Errorf("Unknown Docker version: %s", output)
|
||||||
|
}
|
||||||
|
|
||||||
|
version_running, _ := version.NewVersion(string(match[0]))
|
||||||
|
version_deprecated, _ := version.NewVersion("1.12.0")
|
||||||
|
|
||||||
|
if version_running.LessThan(version_deprecated) {
|
||||||
|
if force {
|
||||||
|
args = append(args, "-f")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// do nothing if Docker version >= 1.12.0
|
||||||
|
log.Printf("[WARN] force is removed since Docker 1.12.0")
|
||||||
}
|
}
|
||||||
args = append(args, id, repo)
|
args = append(args, id, repo)
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ repository is required.
|
||||||
|
|
||||||
- `force` (boolean) - If true, this post-processor forcibly tag the image even
|
- `force` (boolean) - If true, this post-processor forcibly tag the image even
|
||||||
if tag name is collided. Default to `false`.
|
if tag name is collided. Default to `false`.
|
||||||
|
But it will be ignore if Docker version greater or equal than 1.12.0,
|
||||||
|
since the `force` option was removed after 1.12.0. [reference](https://docs.docker.com/engine/deprecated/#/f-flag-on-docker-tag)
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue