(cli *client.Client, containerID string, command []string)
| 1554 | } |
| 1555 | |
| 1556 | func runContainerCommandStream(cli *client.Client, containerID string, command []string) (io.ReadCloser, error) { |
| 1557 | ctx := context.Background() |
| 1558 | resp, err := cli.ContainerExecCreate(ctx, containerID, container.ExecOptions{ |
| 1559 | Cmd: command, |
| 1560 | AttachStdout: true, |
| 1561 | AttachStderr: true, |
| 1562 | }) |
| 1563 | if err != nil { |
| 1564 | return nil, err |
| 1565 | } |
| 1566 | hijack, err := cli.ContainerExecAttach(ctx, resp.ID, container.ExecAttachOptions{}) |
| 1567 | if err != nil { |
| 1568 | return nil, err |
| 1569 | } |
| 1570 | |
| 1571 | pipeReader, pipeWriter := io.Pipe() |
| 1572 | go func() { |
| 1573 | defer hijack.Close() |
| 1574 | var stderr bytes.Buffer |
| 1575 | _, copyErr := stdcopy.StdCopy(pipeWriter, &stderr, hijack.Reader) |
| 1576 | if copyErr != nil { |
| 1577 | _ = pipeWriter.CloseWithError(copyErr) |
| 1578 | return |
| 1579 | } |
| 1580 | info, inspectErr := cli.ContainerExecInspect(ctx, resp.ID) |
| 1581 | if inspectErr != nil { |
| 1582 | _ = pipeWriter.CloseWithError(inspectErr) |
| 1583 | return |
| 1584 | } |
| 1585 | if info.ExitCode != 0 { |
| 1586 | msg := strings.TrimSpace(stderr.String()) |
| 1587 | if len(msg) == 0 { |
| 1588 | msg = fmt.Sprintf("container command failed with exit code %d", info.ExitCode) |
| 1589 | } |
| 1590 | _ = pipeWriter.CloseWithError(fmt.Errorf("%s", msg)) |
| 1591 | return |
| 1592 | } |
| 1593 | _ = pipeWriter.Close() |
| 1594 | }() |
| 1595 | return pipeReader, nil |
| 1596 | } |
| 1597 | |
| 1598 | func toContainerFileInfo(filePath string, stat container.PathStat, isDir bool) dto.ContainerFileInfo { |
| 1599 | name := stat.Name |
no test coverage detected