diff --git a/builder/exector/import_app.go b/builder/exector/import_app.go index 43fefca4c..2fd551b72 100644 --- a/builder/exector/import_app.go +++ b/builder/exector/import_app.go @@ -29,6 +29,8 @@ import ( "strings" "time" + "bytes" + "github.com/Sirupsen/logrus" "github.com/bitly/go-simplejson" "github.com/docker/engine-api/client" @@ -38,7 +40,6 @@ import ( "github.com/goodrain/rainbond/event" "github.com/goodrain/rainbond/util" "github.com/tidwall/gjson" - "bytes" ) func init() { @@ -367,7 +368,7 @@ func (i *ImportApp) loadApps() error { image = fmt.Sprintf("%s/%s/%s:%s", huAddress, namespace, oldImageName.Name, oldImageName.Tag) } if err := sources.ImageTag(i.DockerClient, fmt.Sprintf("goodrain.me/%s:%s", oldImageName.Name, oldImageName.Tag), image, i.Logger, 15); err != nil { - return fmt.Errorf("change image tag(%s => %s) error %s", fmt.Sprintf("goodrain.me/%s", oldImageName.Name), image, err.Error()) + return fmt.Errorf("change image tag(%s => %s) error %s", fmt.Sprintf("goodrain.me/%s:%s", oldImageName.Name, oldImageName.Tag), image, err.Error()) } // 开始上传 if err := sources.ImagePush(i.DockerClient, image, user, pass, i.Logger, 15); err != nil { diff --git a/builder/sources/image.go b/builder/sources/image.go index fdc51f457..db31b8849 100644 --- a/builder/sources/image.go +++ b/builder/sources/image.go @@ -397,7 +397,7 @@ func ImageSave(dockerCli *client.Client, image, destination string, logger event return CopyToFile(destination, rc) } -//ImageSave save image to tar file +//ImageLoad load image from tar file // destination destination file name eg. /tmp/xxx.tar func ImageLoad(dockerCli *client.Client, tarFile string, logger event.Logger) error { ctx, cancel := context.WithCancel(context.Background()) @@ -409,10 +409,32 @@ func ImageLoad(dockerCli *client.Client, tarFile string, logger event.Logger) er } defer reader.Close() - _, err = dockerCli.ImageLoad(ctx, reader, false) + rc, err := dockerCli.ImageLoad(ctx, reader, false) if err != nil { return err } + if rc.Body != nil { + defer rc.Body.Close() + dec := json.NewDecoder(rc.Body) + for { + select { + case <-ctx.Done(): + return ctx.Err() + default: + } + var jm JSONMessage + if err := dec.Decode(&jm); err != nil { + if err == io.EOF { + break + } + return err + } + if jm.Error != nil { + return jm.Error + } + logger.Info(jm.JSONString(), map[string]string{"step": "build-progress"}) + } + } return nil }