Skip to content

Commit 09d94ff

Browse files
committed
minor refactor
1 parent ca89b89 commit 09d94ff

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

compose.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const yaml = require('js-yaml');
22
const fs = require('fs');
3+
const stream = require('stream');
34

45
const secrets = require('./lib/secrets');
56
const volumes = require('./lib/volumes');
@@ -42,20 +43,26 @@ class Compose {
4243
}
4344

4445
async pull(serviceN, options) {
46+
options = options || {};
4547
var streams = [];
4648
var serviceNames = (serviceN === undefined || serviceN === null) ? tools.sortServices(this.recipe) : [serviceN];
4749
for (var serviceName of serviceNames) {
4850
var service = this.recipe.services[serviceName];
4951
try {
50-
var stream = await this.docker.pull(service.image);
51-
streams.push(stream);
52-
if (options && options.verbose) {
53-
stream.pipe(process.stdout);
54-
} else {
55-
stream.pipe(new require('stream').PassThrough());
52+
var streami = await this.docker.pull(service.image);
53+
streams.push(streami);
54+
55+
if (options.verbose === true) {
56+
streami.pipe(process.stdout);
5657
}
57-
if (options === undefined || (options && options.streams !== true)) {
58-
await new Promise(fulfill => stream.once('end', fulfill));
58+
59+
if (options.streams !== true) {
60+
if (options.verbose === true) {
61+
streami.pipe(process.stdout);
62+
} else {
63+
streami.pipe(stream.PassThrough());
64+
}
65+
await new Promise(fulfill => streami.once('end', fulfill));
5966
}
6067
} catch (e) {
6168
throw e;

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dockerode-compose",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "docker-compose in nodejs using dockerode",
55
"main": "./compose.js",
66
"scripts": {

test/compose.js

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ describe('compose', function () {
2424
done();
2525
})();
2626
});
27+
28+
it("should pull all needed images returning streams", function (done) {
29+
this.timeout(600000);
30+
(async () => {
31+
var streams = await compose.pull(null, { 'streams': true });
32+
expect(streams).to.be.ok;
33+
done();
34+
})();
35+
});
2736
});
2837

2938
describe('#up', function () {

0 commit comments

Comments
 (0)