Skip to content

Commit 0938cf4

Browse files
committed
Fix docker status for Ubuntu 17
1 parent c314690 commit 0938cf4

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

src/plugins/docker/command-handlers.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
updateLabels
1515
} from './swarm';
1616
import chalk from 'chalk';
17+
import { checkVersion } from './utils';
1718
import debug from 'debug';
1819
import {
1920
each
@@ -206,42 +207,36 @@ export async function status(api) {
206207

207208
const results = await map(
208209
Object.values(config.servers),
209-
server => api.runSSHCommand(server, 'sudo service docker status && sudo docker version --format "{{.Server.Version}}"'),
210+
server => api.runSSHCommand(server, 'sudo docker version --format "{{.Server.Version}}"'),
210211
{ concurrency: 2 }
211212
);
212213

213-
const minMajor = 1;
214-
const minMinor = 13;
215214
const lines = [];
216215
let overallColor = chalk.green;
217-
results.forEach(result => {
218-
const outputLines = result.output.split('\n');
219-
let dockerStatus = outputLines.length === 1 ? 'Not installed' : 'stopped';
220-
const version = outputLines.length > 1 ? outputLines[outputLines.length - 2] : '';
221-
const versionParts = version.split('.');
222-
let versionColor = chalk.green;
223-
let statusColor = chalk.green;
224216

225-
if (/\/(.*),/.test(result.output)) {
226-
dockerStatus = result.output.match(/\/(.*),/).pop();
227-
}
217+
results.forEach(result => {
218+
let dockerStatus = 'Running';
219+
let color = 'green';
228220

229-
if (parseInt(versionParts[0], 10) < minMajor) {
230-
versionColor = chalk.red;
221+
if (result.code === 1) {
222+
dockerStatus = 'Stopped';
223+
color = 'red';
231224
overallColor = chalk.red;
232-
} else if (
233-
parseInt(versionParts[0], 10) === minMajor &&
234-
parseInt(versionParts[1], 10) < minMinor
235-
) {
236-
versionColor = chalk.red;
225+
} else if (result.code === 127) {
226+
dockerStatus = 'Not installed';
227+
color = 'red';
237228
overallColor = chalk.red;
238229
}
239230

240-
if (dockerStatus !== 'running') {
241-
statusColor = chalk.red;
231+
const version = result.output.trim().length > 1 ? result.output.trim() : '';
232+
let versionColor = chalk.green;
233+
234+
if (!checkVersion(version)) {
235+
overallColor = chalk.red;
236+
versionColor = chalk.red;
242237
}
243238

244-
lines.push(` - ${result.host}: ${versionColor(version)} ${statusColor(dockerStatus)}`);
239+
lines.push(` - ${result.host}: ${versionColor(version)} ${chalk[color](dockerStatus)}`);
245240
});
246241

247242
console.log(overallColor('\n=> Docker Status'));

src/plugins/docker/utils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const minMajor = 1;
2+
const minMinor = 13;
3+
4+
export function checkVersion(version = '') {
5+
const parts = version.trim().split('.');
6+
let valid = true;
7+
8+
if (parseInt(parts[0], 10) < minMajor) {
9+
valid = false;
10+
} else if (
11+
parseInt(parts[0], 10) === minMajor &&
12+
parseInt(parts[1], 10) < minMinor
13+
) {
14+
valid = false;
15+
}
16+
17+
return valid;
18+
}

0 commit comments

Comments
 (0)