Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,24 @@ func (w *Worker) pullImage(ctx context.Context, imageName string, authStr string
}
}()

// The image pull doesn't actually happen until you read from this stream, but we don't need the output.
if _, err = io.Copy(io.Discard, reader); err != nil {
return fmt.Errorf("failed to read image pull output: %w", err)
// Docker reports many pull failures (rate limits, auth errors, image-not-found for
// specific platforms) as JSON messages within the progress stream rather than as the
// initial error return. We must decode and inspect each message to detect these.
type pullMessage struct {
Error string `json:"error"`
}
decoder := json.NewDecoder(reader)
for {
var msg pullMessage
if err := decoder.Decode(&msg); err != nil {
if err == io.EOF {
break
}
return fmt.Errorf("failed to read image pull output for %s: %w", imageName, err)
}
if msg.Error != "" {
return fmt.Errorf("failed to pull image %s: %s", imageName, msg.Error)
}
}
log.Infof(ctx, "Successfully pulled image: %s", imageName)
return nil
Expand Down