buildImage() issues with readable stream in v3.3.4
v3.3.4 changes the implementation of buildImage() to include nested Promises in the no-callback case. This change breaks our use of a ReadableStream as the file source for the build. I have created a simple test case to demonstrate the problem.
The key to our use is a Duplex stream where its Writable stream itself is an event-stream through stream. We push tar file data into the through stream, and it in turn is pushed to docker-modem dial().
// As data is written to inputStream, it will become readable synchronously
// in the same stream for buildImage().
// https://github.com/dominictarr/event-stream#through-write-end
const inputStream = es.through();
const dup = duplexify();
dup.setWritable(inputStream);
First the test case sets up the Duplex stream in createBuildStream(), including asynchronously executing buildImage(). So we expect the pipe in dial() is waiting for data. Then the test case pipes the tar data into that stream with pack.pipe(stream). This approach worked fine in v3.3.3, but hangs with v3.3.4 because dial() is not yet waiting for data, due to the nested Promises in buildImage()
// Create stream to pipe tar data to Docker to build image and print output
const stream = createBuildStream();
// Let's go!
pack.pipe(stream);
// Display docker stream output
stream.pipe(process.stdout);
I have tried some workarounds on our end with Promises on the stream we push, or converting use of buildImage() to include a callback. Unfortunately the results from those attempts were pretty brittle.
I have an idea to simplify buildImage() down to a single Promise while maintaining the asynchronous approach you incorporated in #676. See #695, which works perfectly for us since it recreates the single Promise approach in buildImage() for v3.3.3.