Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batches: use executeFastCommand for docker commands #846

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 2 additions & 11 deletions internal/batches/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
26 changes: 4 additions & 22 deletions internal/batches/docker/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down