Merge pull request #1927 from crazy-max/fix-load-status

build: read body response to check for erroneous image export to docker
pull/1994/head
Tõnis Tiigi 1 year ago committed by GitHub
commit e5419ef6d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -46,17 +46,24 @@ func (c *Client) LoadImage(ctx context.Context, name string, status progress.Wri
w = &waitingWriter{ w = &waitingWriter{
PipeWriter: pw, PipeWriter: pw,
f: func() { f: func() {
resp, err := dapi.ImageLoad(ctx, pr, false) handleErr := func(err error) {
defer close(done)
if err != nil {
pr.CloseWithError(err) pr.CloseWithError(err)
w.mu.Lock() w.mu.Lock()
w.err = err w.err = err
w.mu.Unlock() w.mu.Unlock()
}
resp, err := dapi.ImageLoad(ctx, pr, false)
defer close(done)
if err != nil {
handleErr(err)
return return
} }
prog := progress.WithPrefix(status, "", false) prog := progress.WithPrefix(status, "", false)
progress.FromReader(prog, "importing to docker", resp.Body) if err := fromReader(prog, "importing to docker", resp.Body); err != nil {
handleErr(err)
}
}, },
done: done, done: done,
cancel: cancel, cancel: cancel,

@ -1,15 +1,19 @@
package progress package dockerutil
import ( import (
"errors"
"io" "io"
"time" "time"
"github.com/docker/buildx/util/progress"
"github.com/docker/cli/cli/streams"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/moby/buildkit/client" "github.com/moby/buildkit/client"
"github.com/moby/buildkit/identity" "github.com/moby/buildkit/identity"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
) )
func FromReader(w Writer, name string, rc io.ReadCloser) { func fromReader(w progress.Writer, name string, rc io.ReadCloser) error {
dgst := digest.FromBytes([]byte(identity.NewID())) dgst := digest.FromBytes([]byte(identity.NewID()))
tm := time.Now() tm := time.Now()
@ -23,7 +27,12 @@ func FromReader(w Writer, name string, rc io.ReadCloser) {
Vertexes: []*client.Vertex{&vtx}, Vertexes: []*client.Vertex{&vtx},
}) })
_, err := io.Copy(io.Discard, rc) err := jsonmessage.DisplayJSONMessagesToStream(rc, streams.NewOut(io.Discard), nil)
if err != nil {
if jerr, ok := err.(*jsonmessage.JSONError); ok {
err = errors.New(jerr.Message)
}
}
tm2 := time.Now() tm2 := time.Now()
vtx2 := vtx vtx2 := vtx
@ -34,4 +43,5 @@ func FromReader(w Writer, name string, rc io.ReadCloser) {
w.Write(&client.SolveStatus{ w.Write(&client.SolveStatus{
Vertexes: []*client.Vertex{&vtx2}, Vertexes: []*client.Vertex{&vtx2},
}) })
return err
} }
Loading…
Cancel
Save