Dockerode: buildImage wrongfully resolves

Created on 16 May 2018  路  2Comments  路  Source: apocas/dockerode

I'm not sure if this is intended behaviour or not, but the Promise returned from buildImage resolves when the build process fails.

The README doesn't example the Promise, and the callback variant is very minimal. It states that the callback is invoked with a response (what type of object this is is anyone's guess since there are NO docblocks in the source), so I presume the Promise should also resolve with a response. In my mind, a response would contain a header and body.

After many attempts, I figured out it is actually a stream and not fully resolved until the stream is closed. Really, this response is only the header (and possible a few chunks of the body).

Perhaps this could be better documented.

Also, I don't mean to nitpik, but please start documenting your methods. Most users will jump into the source to figure out what's going on. I had to follow variable names across two packages. A simple comment above the method would have saved me a headache. :smile:

Most helpful comment

I mentioned in the OP that I already figured out what it returns. My point is, I shouldn't have to figure it out. It should be documented, either in the README, a dedicated docs page or in the method's docblock.

Here's another example, swarmInit. I wrongly guessed this would also resolve with a stream, when in it actually resolves with a string. I find myself having to console.log the resolved value each time, before I can start coding the implementation. This really slows down the workflow.

All 2 comments

buildImage() possibly returns a Promise of NodeJS stream, like the push or pull operation on Image.

Dockerode relies on docker-modem to do the heavy lifting, like doing actual requests to Docker daemon.

The modem instance (accessible through modem property of Dockerode instance) has a utility method called followProgress, which accepts two callbacks, for completion and progress respectively. Completion callback is called in NodeJS callback style and can be wrapped into a Promise on it's own accordingly.

let dockerode = new Dockerode();
let stream = await dockerode.buildImage(...);
await new Promise((resolve, reject) => {
  dockerode.modem.followProgress(stream, (err, res) => err ? reject(err) : resolve(res));
});

I mentioned in the OP that I already figured out what it returns. My point is, I shouldn't have to figure it out. It should be documented, either in the README, a dedicated docs page or in the method's docblock.

Here's another example, swarmInit. I wrongly guessed this would also resolve with a stream, when in it actually resolves with a string. I find myself having to console.log the resolved value each time, before I can start coding the implementation. This really slows down the workflow.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lgomez picture lgomez  路  3Comments

mhemrg picture mhemrg  路  4Comments

peterpetre picture peterpetre  路  6Comments

nuest picture nuest  路  3Comments

knight42 picture knight42  路  7Comments