[REV] update handle image load code

This commit is contained in:
barnettZQG 2018-09-10 18:42:03 +08:00
parent d80da1ae63
commit 4d384fd906
2 changed files with 27 additions and 4 deletions

View File

@ -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 {

View File

@ -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
}