diff --git a/internal/batches/docker/image.go b/internal/batches/docker/image.go index 90fb7e3d89..ae5897a6ac 100644 --- a/internal/batches/docker/image.go +++ b/internal/batches/docker/image.go @@ -80,19 +80,10 @@ func (image *image) Ensure(ctx context.Context) error { // Desktop VMs running out of memory, whereupon the Linux // kernel's OOM killer sometimes chooses to kill components of // Docker instead of processes within containers. - dctx, cancel, err := withFastCommandContext(ctx) - if err != nil { - return "", err - } - defer cancel() - args := []string{"image", "inspect", "--format", "{{ .Id }}", image.name} - out, err := exec.CommandContext(dctx, "docker", args...).CombinedOutput() + out, err := executeFastCommand(ctx, args...) id := string(bytes.TrimSpace(out)) - - if errors.IsDeadlineExceeded(err) || errors.IsDeadlineExceeded(dctx.Err()) { - return "", newFastCommandTimeoutError(dctx, args...) - } else if err != nil { + if err != nil { return "", err } diff --git a/internal/batches/docker/info.go b/internal/batches/docker/info.go index a96397c943..9fe83c6ae7 100644 --- a/internal/batches/docker/info.go +++ b/internal/batches/docker/info.go @@ -6,24 +6,14 @@ import ( "strconv" "github.com/sourcegraph/sourcegraph/lib/errors" - - "github.com/sourcegraph/src-cli/internal/exec" ) // CurrentContext returns the name of the current Docker context (not to be // confused with a Go context). func CurrentContext(ctx context.Context) (string, error) { - dctx, cancel, err := withFastCommandContext(ctx) - if err != nil { - return "", err - } - defer cancel() - args := []string{"context", "inspect", "--format", "{{ .Name }}"} - out, err := exec.CommandContext(dctx, "docker", args...).CombinedOutput() - if errors.IsDeadlineExceeded(err) || errors.IsDeadlineExceeded(dctx.Err()) { - return "", newFastCommandTimeoutError(dctx, args...) - } else if err != nil { + out, err := executeFastCommand(ctx, args...) + if err != nil { return "", err } @@ -37,17 +27,9 @@ func CurrentContext(ctx context.Context) (string, error) { // NCPU returns the number of CPU cores available to Docker. func NCPU(ctx context.Context) (int, error) { - dctx, cancel, err := withFastCommandContext(ctx) - if err != nil { - return 0, err - } - defer cancel() - args := []string{"info", "--format", "{{ .NCPU }}"} - out, err := exec.CommandContext(dctx, "docker", args...).CombinedOutput() - if errors.IsDeadlineExceeded(err) || errors.IsDeadlineExceeded(dctx.Err()) { - return 0, newFastCommandTimeoutError(dctx, args...) - } else if err != nil { + out, err := executeFastCommand(ctx, args...) + if err != nil { return 0, err }