From 17f5ee2ae3e8a65574b86be50f876b7e2b8a4bf9 Mon Sep 17 00:00:00 2001 From: "Luis Gustavo S. Barreto" Date: Wed, 27 Mar 2024 10:07:11 -0300 Subject: [PATCH] docs: add documentation for Exec method Adds documentation for the Exec method in the DockerContainer struct. This method executes a command in the current container and returns the exit status of the executed command, an io.Reader containing the combined stdout and stderr, and any encountered error. The documentation emphasizes that reading directly from the io.Reader may result in unexpected bytes due to custom stream multiplexing headers. It recommends using stdcopy.StdCopy() from the Docker API to properly separate the stdout and stderr. See: https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/503 --- docker.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker.go b/docker.go index ec703ac913d..4ac41fc2d7f 100644 --- a/docker.go +++ b/docker.go @@ -478,6 +478,13 @@ func (c *DockerContainer) NetworkAliases(ctx context.Context) (map[string][]stri return a, nil } +// Exec executes a command in the current container. +// It returns the exit status of the executed command, an `io.Reader` containing the combined +// stdout and stderr, and any encountered error. Note that reading directly from the `io.Reader` +// may result in unexpected bytes due to custom stream multiplexing headers. +// To separate the stdout and stderr from `io.Reader` and interpret these headers properly, +// `stdcopy.StdCopy()` from the Docker API should be used. +// More information about this can be found at: https://godoc.org/github.com/docker/docker/pkg/stdcopy func (c *DockerContainer) Exec(ctx context.Context, cmd []string, options ...tcexec.ProcessOption) (int, io.Reader, error) { cli := c.provider.client