@@ -279,16 +279,16 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
279
279
// will still contain valid JSON. We will just end up missing
280
280
// information about the removed container. We could potentially
281
281
// log this error, but I'm not sure it's worth it.
282
- ins , dockerInspectStderr , err := runDockerInspect (ctx , dcl .execer , ids ... )
282
+ dockerInspectStdout , dockerInspectStderr , err := runDockerInspect (ctx , dcl .execer , ids ... )
283
283
if err != nil {
284
284
return codersdk.WorkspaceAgentListContainersResponse {}, xerrors .Errorf ("run docker inspect: %w" , err )
285
285
}
286
286
287
- if dockerInspectStderr != "" {
288
- res .Warnings = append (res .Warnings , dockerInspectStderr )
287
+ if len ( dockerInspectStderr ) > 0 {
288
+ res .Warnings = append (res .Warnings , string ( dockerInspectStderr ) )
289
289
}
290
290
291
- outs , warns , err := convertDockerInspect (ins )
291
+ outs , warns , err := convertDockerInspect (dockerInspectStdout )
292
292
if err != nil {
293
293
return codersdk.WorkspaceAgentListContainersResponse {}, xerrors .Errorf ("convert docker inspect output: %w" , err )
294
294
}
@@ -301,19 +301,19 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
301
301
// runDockerInspect is a helper function that runs `docker inspect` on the given
302
302
// container IDs and returns the parsed output.
303
303
// The stderr output is also returned for logging purposes.
304
- func runDockerInspect (ctx context.Context , execer agentexec.Execer , ids ... string ) (stdout , stderr string , err error ) {
304
+ func runDockerInspect (ctx context.Context , execer agentexec.Execer , ids ... string ) (stdout , stderr [] byte , err error ) {
305
305
var stdoutBuf , stderrBuf bytes.Buffer
306
306
cmd := execer .CommandContext (ctx , "docker" , append ([]string {"inspect" }, ids ... )... )
307
307
cmd .Stdout = & stdoutBuf
308
308
cmd .Stderr = & stderrBuf
309
309
err = cmd .Run ()
310
- stdout = strings .TrimSpace (stdoutBuf .String ())
311
- stderr = strings .TrimSpace (stderrBuf .String ())
310
+ stdout = bytes .TrimSpace (stdoutBuf .Bytes ())
311
+ stderr = bytes .TrimSpace (stderrBuf .Bytes ())
312
312
if err != nil {
313
313
return stdout , stderr , err
314
314
}
315
315
316
- return stdoutBuf . String () , stderr , nil
316
+ return stdout , stderr , nil
317
317
}
318
318
319
319
// To avoid a direct dependency on the Docker API, we use the docker CLI
@@ -371,10 +371,10 @@ func (dis dockerInspectState) String() string {
371
371
return sb .String ()
372
372
}
373
373
374
- func convertDockerInspect (raw string ) ([]codersdk.WorkspaceAgentDevcontainer , []string , error ) {
374
+ func convertDockerInspect (raw [] byte ) ([]codersdk.WorkspaceAgentDevcontainer , []string , error ) {
375
375
var warns []string
376
376
var ins []dockerInspect
377
- if err := json .NewDecoder (strings .NewReader (raw )).Decode (& ins ); err != nil {
377
+ if err := json .NewDecoder (bytes .NewReader (raw )).Decode (& ins ); err != nil {
378
378
return nil , nil , xerrors .Errorf ("decode docker inspect output: %w" , err )
379
379
}
380
380
outs := make ([]codersdk.WorkspaceAgentDevcontainer , 0 , len (ins ))
0 commit comments