Repository navigation
refactor(agent): share docker CLI command and error helpers - #1508
Conversation
Route LocalDockerDelivery and RemoteDockerDelivery command construction through dockerCLI, and replace the repeated captured-output error wrap with runDockerCLI at plain-wrap sites. Error strings and dockerCommand resolution are unchanged.
✅ Deploy Preview for devsydev canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
✅ Deploy Preview for images-devsy-sh canceled.
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
Why
LocalDockerDeliveryandRemoteDockerDeliveryeach carry a byte-identicalcmdbuilder (exec.CommandContextplus environment append) and adockerCommandresolver, andpkg/agent/deliveryrepeats the same captured-output error wrap (fmt.Errorf("%s: %w", capturedOutput(result), err)) at seven plain call sites. This PR moves the builder and the wrap intocapture.goso the docker CLI invocation rules live in one place. It is the best next target in this package because it removes real duplication without touching any logic that differs between the two delivery types.What changed
capture.go: addeddockerCLI(ctx, command, env, args...), which holds the single copy of the builder body, andrunDockerCLI(ctx, cmd), which runsrunCapturedand wraps the error with captured output.local_docker.goandremote_docker.go:cmdis now a one-line call todockerCLI. The methods stay, so call sites and tests are unchanged.dockerCommandis untouched.createVolume,populateVolumeWithHelper,removeVolume,copyBinaryFromSource,chmodBinary,ensureDir,copyDirIntoVolume) nowreturn runDockerCLI(...).Left unchanged on purpose:
volumeMountpointandlistManagedVolumesreadresult.Stdoutafter the error check, so they keeprunCaptured.detect*helpers inlocal_docker.goeither return the raw error or log it, so they do not use the wrap.podman unshare write failed:site (populateVolumeViaUnshare) and theworkspace_seed.goinspect site use different message prefixes and must stay byte-identical.Behaviour
No behaviour change. Error strings are unchanged,
runCapturedsemantics are unchanged, anddockerCommandresolution is unchanged. A nilEnvironmentstill leavescmd.Envnil, and a non-nil one is still appended toos.Environ(). No exported API changed.Validation
mkdir -p dist && task cli:format: pass (format touched only the four files in this PR).task cli:lint:ci: pass (0 issues.).go test ./pkg/agent/...: pass (pkg/agent,pkg/agent/delivery,pkg/agent/snapshot,pkg/agent/tunnelserverall ok).go test, deleted before commit): default docker command resolves todocker;DockerCommandoverride is used asArgs[0];Environmentis appended for local and remote deliveries; nil env leavescmd.Envnil;runDockerCLIerror contains captured stderr and exit status; success returns nil.coderabbit review --agent --committed --base-commit <merge-base>): completed, 0 findings across the four reviewed files.CodeRabbit CLI
Completed with 0 findings.
Auto-merge
Eligible: yes. Behaviour-preserving, 4 files, +31/-47, no tests touched, no lint disables, no go.mod, workflow, or secret-handling changes.
Summary by CodeRabbit