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

add an option to use a custom progress printer for the build progress output #11625

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rarguelloF
Copy link

What I did

Adds a new optional field OutPrinter to the BuildOptions struct to allow customizing where the build progress goes. If this field is not specified, output will go to os.Stdout, which is the current behavior.

The motivation for this change is when building tooling around this project, you might want to capture these logs and use them accordingly, example:

type cacheMessagesPrinter struct {
	msgs []string
}

func (c *cacheMessagesPrinter) Write(p []byte) (n int, err error) {
	c.msgs = append(c.msgs, string(p))
	return len(p), nil
}

func TestMyStuff(t *testing.T) {
	myPrinter: = &cacheMessagesPrinter{}
	
	buildOpts := &api.BuildOptions{
		Pull:     true,
		Progress: "auto",
		Args:     nil,
		NoCache:  false,
		Quiet:    false,
		Memory:   0,
		OutPrinter: myPrinter,
	}
	err := startMyDockerComposeProject(buildOpts)
	if err != nil {
        // this is particularly useful if using t.Parallel(), so you can associate logs to the proper test instead of everything
        // being mixed in stdout.
		t.Log("docker compose project build failed - see build logs below")
		buildLogs := strings.Join(myPrinter.msgs, "\n")
		t.Log(buildLogs)
   }
}

Hope you find this feature useful, please let me know what you think!

Related issue

(not mandatory) A picture of a cute animal, if possible in relation to what you did

… output

Signed-off-by: Rodrigo Arguello <rarguellof91@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant