未验证 提交 c8bcdf9d 编写于 作者: M Medya Ghazizadeh 提交者: GitHub

Merge pull request #8355 from afbjorklund/image-ref2

Add digest to image in daemon after pulling it
......@@ -104,6 +104,7 @@ replace (
git.apache.org/thrift.git => github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999
github.com/docker/docker => github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7
github.com/docker/machine => github.com/machine-drivers/machine v0.7.1-0.20200323212942-41eb826190d8
github.com/google/go-containerregistry => github.com/afbjorklund/go-containerregistry v0.0.0-20200329163843-4f5ebd05922c
github.com/hashicorp/go-getter => github.com/afbjorklund/go-getter v1.4.1-0.20190910175809-eb9f6c26742c
github.com/samalba/dockerclient => github.com/sayboras/dockerclient v0.0.0-20191231050035-015626177a97
k8s.io/api => k8s.io/api v0.17.3
......
......@@ -121,11 +121,7 @@ func saveToTarFile(iname, rawDest string) error {
return errors.Wrapf(err, "nil image for %s", iname)
}
tag, err := name.NewTag(iname, name.WeakValidation)
if err != nil {
return errors.Wrap(err, "newtag")
}
err = writeImage(img, dst, tag)
err = writeImage(img, dst, ref)
if err != nil {
return err
}
......@@ -134,7 +130,7 @@ func saveToTarFile(iname, rawDest string) error {
return nil
}
func writeImage(img v1.Image, dst string, tag name.Tag) error {
func writeImage(img v1.Image, dst string, ref name.Reference) error {
glog.Infoln("opening: ", dst)
f, err := ioutil.TempFile(filepath.Dir(dst), filepath.Base(dst)+".*.tmp")
if err != nil {
......@@ -151,7 +147,7 @@ func writeImage(img v1.Image, dst string, tag name.Tag) error {
}
}()
err = tarball.Write(tag, img, f)
err = tarball.Write(ref, img, f)
if err != nil {
return errors.Wrap(err, "write")
}
......
......@@ -113,27 +113,10 @@ func WriteImageToDaemon(img string) error {
return errors.Wrap(err, "getting remote image")
}
tag, err := name.NewTag(strings.Split(img, "@")[0])
glog.V(3).Infof("Writing image %v", ref)
_, err = daemon.Write(ref, i)
if err != nil {
return errors.Wrap(err, "getting tag")
}
glog.V(3).Infof("Writing image %v", tag)
_, err = daemon.Write(tag, i)
if err != nil {
return errors.Wrap(err, "writing image")
}
//TODO: Make pkg/v1/daemon accept Ref too
// Only added it to pkg/v1/tarball
//
// https://github.com/google/go-containerregistry/pull/702
glog.V(3).Infof("Pulling image %v", ref)
// Pull digest
cmd := exec.Command("docker", "pull", "--quiet", img)
if _, err := cmd.Output(); err != nil {
return errors.Wrap(err, "pulling remote image")
return errors.Wrap(err, "writing daemon image")
}
return nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册