diff --git a/lib/docker.js b/lib/docker.js index 4aae877..5337960 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -301,7 +301,26 @@ Docker.prototype.buildImage = function(file, opts, callback) { pack = tar.pack(file.context, { entries: file.src }); - return build(pack.pipe(zlib.createGzip())); + + if (callback === undefined) { + return new self.modem.Promise(function(resolve, reject) { + pack.on('error', function(error) { + return reject(error); + }); + pack.on('end', function() { + return resolve(build(stream)); + }); + var stream = pack.pipe(zlib.createGzip()); + }); + } else { + pack.on('error', function(error) { + return callback(error); + }); + pack.on('end', function() { + return build(stream); + }); + var stream = pack.pipe(zlib.createGzip()); + } } else { return build(file); }