Skip to content

Commit 009c879

Browse files
authored
Improve log output of docker pull errors (#880)
Recently a customer ran into _some_ issue but we weren't able to tell WHAT the issue was. This adds additional log output. *Before* ``` ✅ Parsing batch spec ✅ Resolving namespace ⠸ Preparing container images 0% ❌ Error: pulling image "ubunootu:18.04": pulling image: exit status 1 💡 The troubleshooting documentation can help to narrow down the cause of the errors: https://docs.sourcegraph.com/batch_changes/references/troubleshooting ``` *After* ``` ✅ Parsing batch spec ✅ Resolving namespace ⠏ Preparing container images 0% ❌ Error: pulling image "ubunootu:18.04": failed to pull image: Error response from daemon: failed to resolve reference "docker.io/library/ubunootu:18.04": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed docker pull exited with code 1 💡 The troubleshooting documentation can help to narrow down the cause of the errors: https://docs.sourcegraph.com/batch_changes/references/troubleshooting ```
1 parent 51113d0 commit 009c879

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/batches/docker/image.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
goexec "os/exec"
78
"strings"
89
"sync"
910

@@ -87,7 +88,7 @@ func (image *image) Ensure(ctx context.Context) error {
8788
defer cancel()
8889

8990
args := []string{"image", "inspect", "--format", "{{ .Id }}", image.name}
90-
out, err := exec.CommandContext(dctx, "docker", args...).CombinedOutput()
91+
out, err := exec.CommandContext(dctx, "docker", args...).Output()
9192
id := string(bytes.TrimSpace(out))
9293

9394
if errors.IsDeadlineExceeded(err) || errors.IsDeadlineExceeded(dctx.Err()) {
@@ -108,7 +109,14 @@ func (image *image) Ensure(ctx context.Context) error {
108109
return err
109110
} else if err != nil {
110111
// Let's try pulling the image.
111-
if err := exec.CommandContext(ctx, "docker", "image", "pull", image.name).Run(); err != nil {
112+
pullCmd := exec.CommandContext(ctx, "docker", "image", "pull", image.name)
113+
var stderr bytes.Buffer
114+
pullCmd.Stderr = &stderr
115+
if err := pullCmd.Run(); err != nil {
116+
exitErr := &goexec.ExitError{}
117+
if errors.As(err, &exitErr) {
118+
return errors.Newf("failed to pull image: %s\ndocker pull exited with code %d", stderr.String(), exitErr.ExitCode())
119+
}
112120
return errors.Wrap(err, "pulling image")
113121
}
114122
// And try again to get the image digest.

0 commit comments

Comments
 (0)