From c107ed4ddd7cfc39253a95f25d87f6d947ca6281 Mon Sep 17 00:00:00 2001 From: holyfei Date: Tue, 28 Jul 2020 19:44:16 +0800 Subject: [PATCH] load: set name:tag after the image is loaded Fix #I1P0YU Reason: set name:tag after the image is loaded Signed-off-by: yangfeiyu --- daemon/load.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/daemon/load.go b/daemon/load.go index d4ece0c..0fba807 100644 --- a/daemon/load.go +++ b/daemon/load.go @@ -18,6 +18,8 @@ package daemon import ( "context" + "github.com/containers/image/v5/docker/tarfile" + "github.com/pkg/errors" "github.com/sirupsen/logrus" constant "isula.org/isula-build" @@ -34,6 +36,16 @@ func (b *Backend) Load(ctx context.Context, req *pb.LoadRequest) (*pb.LoadRespon return &pb.LoadResponse{}, err } + tarfileSource, err := tarfile.NewSourceFromFile(req.Path) + if err != nil { + return &pb.LoadResponse{}, errors.Wrapf(err, "failed to get the source of loading tar file") + } + + topLevelImageManifest, err := tarfileSource.LoadTarManifest() + if err != nil || len(topLevelImageManifest) == 0 { + return &pb.LoadResponse{}, errors.Wrapf(err, "failed to get the top level image manifest") + } + _, si, err := image.ResolveFromImage(&image.PrepareImageOptions{ Ctx: ctx, FromImage: "docker-archive:" + req.Path, @@ -45,7 +57,7 @@ func (b *Backend) Load(ctx context.Context, req *pb.LoadRequest) (*pb.LoadRespon return nil, err } - if err := b.daemon.localStore.SetNames(si.ID, []string{":"}); err != nil { + if err := b.daemon.localStore.SetNames(si.ID, topLevelImageManifest[0].RepoTags); err != nil { return nil, err } -- GitLab