Skip to content

Commit

Permalink
Merge pull request #2981 from jonnystoten/better-push-error
Browse files Browse the repository at this point in the history
Add context to registry push errors
  • Loading branch information
tonistiigi authored Jul 27, 2022
2 parents f8a60e2 + df0c9b6 commit 2973bb9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
63 changes: 34 additions & 29 deletions exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,35 +299,9 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source,
}
}
if e.push {
annotations := map[digest.Digest]map[string]string{}
mprovider := contentutil.NewMultiProvider(e.opt.ImageWriter.ContentStore())
if src.Ref != nil {
remotes, err := src.Ref.GetRemotes(ctx, false, e.opts.RefCfg, false, session.NewGroup(sessionID))
if err != nil {
return nil, err
}
remote := remotes[0]
for _, desc := range remote.Descriptors {
mprovider.Add(desc.Digest, remote.Provider)
addAnnotations(annotations, desc)
}
}
if len(src.Refs) > 0 {
for _, r := range src.Refs {
remotes, err := r.GetRemotes(ctx, false, e.opts.RefCfg, false, session.NewGroup(sessionID))
if err != nil {
return nil, err
}
remote := remotes[0]
for _, desc := range remote.Descriptors {
mprovider.Add(desc.Digest, remote.Provider)
addAnnotations(annotations, desc)
}
}
}

if err := push.Push(ctx, e.opt.SessionManager, sessionID, mprovider, e.opt.ImageWriter.ContentStore(), desc.Digest, targetName, e.insecure, e.opt.RegistryHosts, e.pushByDigest, annotations); err != nil {
return nil, err
err := e.pushImage(ctx, src, sessionID, targetName, desc.Digest)
if err != nil {
return nil, errors.Wrapf(err, "failed to push %v", targetName)
}
}
}
Expand All @@ -349,6 +323,37 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source,
return resp, nil
}

func (e *imageExporterInstance) pushImage(ctx context.Context, src exporter.Source, sessionID string, targetName string, dgst digest.Digest) error {
annotations := map[digest.Digest]map[string]string{}
mprovider := contentutil.NewMultiProvider(e.opt.ImageWriter.ContentStore())
if src.Ref != nil {
remotes, err := src.Ref.GetRemotes(ctx, false, e.opts.RefCfg, false, session.NewGroup(sessionID))
if err != nil {
return err
}
remote := remotes[0]
for _, desc := range remote.Descriptors {
mprovider.Add(desc.Digest, remote.Provider)
addAnnotations(annotations, desc)
}
}
if len(src.Refs) > 0 {
for _, r := range src.Refs {
remotes, err := r.GetRemotes(ctx, false, e.opts.RefCfg, false, session.NewGroup(sessionID))
if err != nil {
return err
}
remote := remotes[0]
for _, desc := range remote.Descriptors {
mprovider.Add(desc.Digest, remote.Provider)
addAnnotations(annotations, desc)
}
}
}

return push.Push(ctx, e.opt.SessionManager, sessionID, mprovider, e.opt.ImageWriter.ContentStore(), dgst, targetName, e.insecure, e.opt.RegistryHosts, e.pushByDigest, annotations)
}

func (e *imageExporterInstance) unpackImage(ctx context.Context, img images.Image, src exporter.Source, s session.Group) (err0 error) {
unpackDone := oneOffProgress(ctx, "unpacking to "+img.Name)
defer func() {
Expand Down
8 changes: 8 additions & 0 deletions util/grpcerrors/grpcerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ func ToGRPC(err error) error {
st = status.FromProto(pb)
}

// If the original error was wrapped with more context than the GRPCStatus error,
// copy the original message to the GRPCStatus error
if err.Error() != st.Message() {
pb := st.Proto()
pb.Message = err.Error()
st = status.FromProto(pb)
}

var details []proto.Message

for _, st := range stack.Traces(err) {
Expand Down

0 comments on commit 2973bb9

Please sign in to comment.