mirror of
https://github.com/linka-cloud/d2vm.git
synced 2025-06-27 23:52:27 +00:00
refactoring: explicit docker commands
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
@ -39,15 +39,9 @@ var (
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if debug {
|
||||
exec.Run = exec.RunStdout
|
||||
}
|
||||
exec.SetDebug(debug)
|
||||
logrus.Infof("building docker image from %s", file)
|
||||
dargs := []string{"build", "-t", tag, "-f", file, args[0]}
|
||||
for _, v := range buildArgs {
|
||||
dargs = append(dargs, "--build-arg", v)
|
||||
}
|
||||
if err := docker.Cmd(cmd.Context(), dargs...); err != nil {
|
||||
if err := docker.Build(cmd.Context(), tag, file, args[0], buildArgs...); err != nil {
|
||||
return err
|
||||
}
|
||||
return d2vm.Convert(cmd.Context(), tag, size, password, output, format)
|
||||
|
@ -51,9 +51,7 @@ var (
|
||||
return fmt.Errorf("%s already exists", output)
|
||||
}
|
||||
}
|
||||
if debug {
|
||||
exec.Run = exec.RunStdout
|
||||
}
|
||||
exec.SetDebug(debug)
|
||||
if _, err := os.Stat(output); err == nil || !os.IsNotExist(err) {
|
||||
if !force {
|
||||
return fmt.Errorf("%s already exists", output)
|
||||
@ -61,18 +59,18 @@ var (
|
||||
}
|
||||
found := false
|
||||
if !pull {
|
||||
o, _, err := docker.CmdOut(cmd.Context(), "image", "ls", "--format={{ .Repository }}:{{ .Tag }}", img)
|
||||
imgs, err := docker.ImageList(cmd.Context(), img)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
found = strings.TrimSuffix(o, "\n") == fmt.Sprintf("%s:%s", img, tag)
|
||||
found = len(imgs) == 1 && imgs[0] == fmt.Sprintf("%s:%s", img, tag)
|
||||
if found {
|
||||
logrus.Infof("using local image %s:%s", img, tag)
|
||||
}
|
||||
}
|
||||
if pull || !found {
|
||||
logrus.Infof("pulling image %s", img)
|
||||
if err := docker.Cmd(cmd.Context(), "image", "pull", img); err != nil {
|
||||
if err := docker.Pull(cmd.Context(), img); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user