Skip to content

Commit

Permalink
Improved docker validations
Browse files Browse the repository at this point in the history
  • Loading branch information
davemoore- committed May 17, 2022
1 parent 6aa75ee commit 12fc5bf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microbs.io/cli",
"version": "0.2.8",
"version": "0.2.9",
"description": "microservices observability",
"license": "Apache-2.0",
"url": "https://microbs.io",
Expand Down
30 changes: 29 additions & 1 deletion src/commands/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,23 @@ const validateDockerVersion = () => {
const result = utils.exec('docker version -f json', true)
if (result.stdout) {
try {
const json = JSON.parse(result.stdout.trim())
// The first line(s) may be a warning message. Find the line that is JSON.
const lines = result.stdout.split(/\r?\n/)
var line
for (var i in lines) {
if (lines[i].startsWith('{')) {
line = lines[i]
break
}
}
if (!line)
return logUnknown(`failed to detect docker version [required>=${versionRequired}]`)
var json
try {
json = JSON.parse(line.trim())
} catch (e) {
return logUnknown(`failed to detect docker version [required>=${versionRequired}]`)
}
versionActual = semver.clean(json.Client.Version)
versionRequired = semver.clean('20.10.12')
if (semver.gte(versionActual, versionRequired))
Expand All @@ -99,6 +115,17 @@ const validateDockerVersion = () => {
}
}

/**
* Validate docker running
*/
const validateDockerRunning = () => {
const result = utils.exec('docker ps -q', true)
if(result.code === 0)
logSuccess('docker is running')
else
logFailure(`docker is not running: ${result.stdout || result.stderr}`)
}

/**
* Validate kubectl installation
*/
Expand Down Expand Up @@ -251,6 +278,7 @@ const validateDependencies = () => {
validateNpmVersion()
validateDockerInstallation()
validateDockerVersion()
validateDockerRunning()
validateKubectlInstallation()
validateKubectlVersion()
validateSkaffoldInstallation()
Expand Down

0 comments on commit 12fc5bf

Please sign in to comment.