Skip to content

Commit

Permalink
Merge pull request #695 from kb2ma/build_image_stuck
Browse files Browse the repository at this point in the history
Remove promise nesting in buildImage() when no callback
  • Loading branch information
apocas committed Mar 15, 2023
2 parents 9e49cc7 + db00bd0 commit 5078006
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
10 changes: 3 additions & 7 deletions lib/docker.js
Expand Up @@ -287,12 +287,8 @@ Docker.prototype.buildImage = function(file, opts, callback) {
}

if (callback === undefined) {
const prepareCtxPromise = new self.modem.Promise(function(resolve, _) {
util.prepareBuildContext(file, resolve)
});

return prepareCtxPromise.then((ctx)=> {
return new self.modem.Promise(function(resolve, reject) {
return new self.modem.Promise(function(resolve, reject) {
util.prepareBuildContext(file, (ctx) => {
optsf.file = ctx;
self.modem.dial(optsf, function(err, data) {
if (err) {
Expand All @@ -301,7 +297,7 @@ Docker.prototype.buildImage = function(file, opts, callback) {
resolve(data);
});
});
})
});
} else {
util.prepareBuildContext(file, (ctx) => {
optsf.file = ctx;
Expand Down
39 changes: 38 additions & 1 deletion test/docker.js
Expand Up @@ -90,6 +90,23 @@ describe("#docker", function() {
docker.buildImage('./test/test.tar', {}, handler);
});

it("should build image from file using Promise", function(done) {
this.timeout(60000);

docker.buildImage('./test/test.tar', {}).then((stream) => {
expect(stream).to.be.ok;

stream.pipe(process.stdout, {
end: true
});

stream.on('end', function() {
done();
});
})
.catch(error => done(error))
});

it("should build image from readable stream", function(done) {
this.timeout(60000);

Expand Down Expand Up @@ -175,7 +192,27 @@ describe("#docker", function() {
src: ['Dockerfile', '.dockerignore', 'test.tar']
}, {}, handler);
});


it("should build image from multiple files while respecting the dockerignore file via Promise", function(done) {
this.timeout(60000);

docker.buildImage({
context: __dirname,
src: ['Dockerfile', '.dockerignore', 'test.tar']
}, {}).then((stream) => {
expect(stream).to.be.ok;

stream.pipe(process.stdout, {
end: true
});

stream.on('end', function() {
done();
});
})
.catch(error => done(error))
});

it("should not mutate src array", function(done) {
this.timeout(60000);

Expand Down

0 comments on commit 5078006

Please sign in to comment.