Skip to content

Commit 08d6c72

Browse files
committed
1.0.3 replaced dockermachineconfig with dockermachine-cli-js
1 parent d20804f commit 08d6c72

3 files changed

Lines changed: 49 additions & 68 deletions

File tree

lib/index.js

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var Promise = require("bluebird");
1919
var exec = Promise.promisify(require('child_process').exec);
2020
var os = require("os");
2121
var _ = require('lodash');
22-
var dockermachine = require('dockermachineconfig');
2322
var cliTable2Json = require('cli-table-2-json');
23+
var DockerMachine = require('dockermachine-cli-js');
2424

2525
var Docker = function (opts) {
2626
if (!(this instanceof Docker)) {
@@ -36,22 +36,32 @@ Docker.prototype.command = function(command, callback) {
3636

3737
return Promise.resolve().then(function () {
3838
if (self.machinename) {
39-
return dockermachine.config(self.machinename).then(function (data) {
40-
self.machineconfig = data;
39+
var dockerMachine = new DockerMachine({});
40+
41+
return dockerMachine.command('config ' + self.machinename).then(function (data) {
42+
console.log('data = ', data);
43+
self.machineconfig = data.machine.config;
4144
});
45+
4246
}
4347
}).then(function (data) {
4448

4549
if (self.machineconfig) {
46-
exec_command += self.machineconfig.raw + ' ';
50+
exec_command += self.machineconfig + ' ';
4751
}
4852
exec_command += command + ' ';
4953

50-
var exec_options = {};
54+
var exec_options = {
55+
env: {
56+
HOME: process.env.HOME,
57+
PATH: process.env.PATH,
58+
DEBUG: ''
59+
}
60+
};
5161
if (self.cwd) {
5262
exec_options.cwd = self.cwd;
5363
}
54-
//console.log('exec options =', exec_options);
64+
console.log('exec options =', exec_options);
5565

5666
return exec(exec_command, exec_options);
5767

@@ -116,37 +126,8 @@ var extractResult = function (result) {
116126
run: function (resultp) {
117127
var obj = JSON.parse(resultp.raw);
118128
var lines = obj[0].split(os.EOL);
119-
var i, line, columns, container, lineObj;
120-
resultp.containerList = [];
121-
122-
for (i = 1; i < lines.length; i++) {
123-
line = lines[i].trim();
124-
if (line.length === 0) {
125-
continue;
126-
}
127-
columns = line.split(/ [ ]+/);
128-
lineObj = {};
129-
resultp.containerList.push(lineObj);
130-
lineObj.containerId = columns[0];
131-
lineObj.image = columns[1];
132-
lineObj.command = columns[2];
133-
lineObj.created = columns[3];
134-
lineObj.status = columns[4];
135-
lineObj.ports = columns[5];
136-
lineObj.name = columns[6];
137-
}
138-
139-
//data = { command: 'docker ps ',
140-
// raw: '["CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
141-
// NAMES\\nc0df7ad37763 nginximg1 \\"nginx -g \'daemon off\\" 33 minutes ago Up 33 minutes 0.0.0.0:80->80/tcp, 443/tcp nginxcont\\n",""]',
142-
//containerList:
143-
//[ { containerId: 'c0df7ad37763',
144-
// image: 'nginximg1',
145-
// command: '"nginx -g \'daemon off"',
146-
// created: '33 minutes ago',
147-
// status: 'Up 33 minutes',
148-
// ports: '0.0.0.0:80->80/tcp, 443/tcp',
149-
// name: 'nginxcont' } ] }
129+
130+
resultp.containerList = cliTable2Json(lines);
150131

151132
return resultp;
152133
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docker-cli-js",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A wrapper for the docker CLI",
55
"main": "lib/index.js",
66
"scripts": {
@@ -30,10 +30,10 @@
3030
"dockermachine": "0.0.5"
3131
},
3232
"dependencies": {
33-
"dockermachineconfig": "~1.0.4",
3433
"lodash": "~3.10.1",
3534
"bluebird": "~2.10.1",
3635
"debug": "~2.2.0",
37-
"cli-table-2-json": "~1.0.0"
36+
"cli-table-2-json": "~1.0.0",
37+
"dockermachine-cli-js": "1.0.1"
3838
}
3939
}

test/index.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,33 @@ describe('docker', function () {
135135
// });
136136
//});
137137

138-
//it('command ps', function (done) {
138+
it('command ps', function (done) {
139+
this.timeout(15000);
140+
var docker = new Docker({
141+
machinename: config.DockerMachineName,
142+
});
143+
console.log('docker', docker);
144+
assert.isNotNull(docker);
145+
var failed = false;
146+
var err = null;
147+
docker.command('ps').then(function (data) {
148+
console.log('data = ', data);
149+
assert.isNotNull(data);
150+
}).catch(function (error) {
151+
assert.isNotNull(error);
152+
err = error;
153+
failed = true;
154+
console.log('error = ', error);
155+
}).finally(function () {
156+
console.log('finally ');
157+
assert.isFalse(failed);
158+
assert.isNull(err);
159+
done();
160+
});
161+
});
162+
163+
164+
//it('command images', function (done) {
139165
// this.timeout(15000);
140166
// var docker = new Docker({
141167
// //machinename: config.DockerMachineName,
@@ -144,7 +170,7 @@ describe('docker', function () {
144170
// assert.isNotNull(docker);
145171
// var failed = false;
146172
// var err = null;
147-
// docker.command('ps').then(function (data) {
173+
// docker.command('images').then(function (data) {
148174
// console.log('data = ', data);
149175
// assert.isNotNull(data);
150176
// }).catch(function (error) {
@@ -160,32 +186,6 @@ describe('docker', function () {
160186
// });
161187
//});
162188

163-
164-
it('command images', function (done) {
165-
this.timeout(15000);
166-
var docker = new Docker({
167-
//machinename: config.DockerMachineName,
168-
});
169-
//console.log('docker', docker);
170-
assert.isNotNull(docker);
171-
var failed = false;
172-
var err = null;
173-
docker.command('images').then(function (data) {
174-
console.log('data = ', data);
175-
assert.isNotNull(data);
176-
}).catch(function (error) {
177-
assert.isNotNull(error);
178-
err = error;
179-
failed = true;
180-
console.log('error = ', error);
181-
}).finally(function () {
182-
console.log('finally ');
183-
assert.isFalse(failed);
184-
assert.isNull(err);
185-
done();
186-
});
187-
});
188-
189189
});
190190

191191

0 commit comments

Comments
 (0)