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

Allows buildpack output to stream commands #787

Closed
wants to merge 6 commits into from

Conversation

schneems
Copy link
Contributor

The start_stream interface only returns a single writer. The Command expects two writers: stdout and stderr. There's currently no good way for a buildpack author to stream a running Command, to the point that there are no examples of it in the documentation.

This PR introduces a mechanism to do this and adds a doc that executes a command streaming to the build output.

@@ -35,6 +35,8 @@ use crate::buildpack_output::util::{prefix_first_rest_lines, prefix_lines, Parag
use crate::write::line_mapped;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ready for feedback on if this is a viable path forward or what else might be needed.

Exploring our options for solving this problem

  • Give the end user a struct like LockedWriter that allows them to clone and manage their own IO faux duplication
    • Technically possible and quite explicit, but is gross for the buildpack maintainer. I feel we should take on this complexity, not our end users.
  • Introduce a Command output function variant that only takes a single writer
    • I tried this, the function would then have to return the writer and any Result object, likely via a tuple, which is ergonomically weird.
  • Introduce a non-consuming function that yields two Write structs that are then proxied to the actual Write output (This PR).
    • This PR: Solves the problem. The downside is that it's complex, but it's hidden from the user. There may be an easier way to implement this logic. I feel this closure type of build output streaming is the correct interface as it allows natively interfacing with the result and not having to juggle returning a build output struct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, i've been pretty happy with the closure variant for streaming command outputs.

@edmorley edmorley added enhancement New feature or request libherokubuildpack labels Feb 16, 2024
@schneems schneems marked this pull request as ready for review February 19, 2024 19:22
@schneems schneems requested a review from a team as a code owner February 19, 2024 19:22
Copy link
Contributor

@colincasey colincasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schneems I noticed you added the "Skip Changelog" label here. Why no changelog entry?

@edmorley
Copy link
Member

edmorley commented Feb 28, 2024

Why no changelog entry?

Good spot. I suspect it's because when this PR was opened, the build_output module had not been released, so this PR would have been covered by the existing "add a new build_output module" changelog entry, and that Richard forgot to account for the release of libcnb 0.19.0.

I've removed the skip changelog label now.

@schneems schneems force-pushed the schneems/output-multi-stream branch from 278fec7 to 47b51b4 Compare February 28, 2024 17:54
@schneems
Copy link
Contributor Author

Integration tests are failing. They're also failing for me on main locally #802

@edmorley
Copy link
Member

edmorley commented Feb 28, 2024

Ah the Unexpected Docker volumes left behind! is an intermittent failure that happens occasionally - I don't know why (since image cleanup works most of the time). I'd like to track it down, but I probably won't have time to do so for a few months.

I've retriggered the CI job now.

@schneems
Copy link
Contributor Author

schneems commented Mar 5, 2024

Thankfully a restart fixed the issue. Changelog is added. Tests are passing.

@schneems
Copy link
Contributor Author

schneems commented Apr 3, 2024

I'm going to rebase this and then I want to merge it in. If there's a refactor needed or some changes needed, then I'll own it. If it's not up to standards or quality, then we need to figure out additional ways to scale out standard and quality measures.

@schneems schneems force-pushed the schneems/output-multi-stream branch from 47b51b4 to cf721cc Compare May 16, 2024 17:37
@schneems
Copy link
Contributor Author

Think we can close in favor of using https://crates.io/crates/bullet_stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request libherokubuildpack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants