feat(techdocs-cli): check Docker status before running mkdocs server

Signed-off-by: hainenber <dotronghai96@gmail.com>
This commit is contained in:
hainenber
2023-11-05 15:55:06 +07:00
parent 03b9c28159
commit 8ea827797d
@@ -24,6 +24,8 @@ import { LogFunc, waitForSignal } from '../../lib/run';
import { createLogger } from '../../lib/utility';
import { getMkdocsYml } from '@backstage/plugin-techdocs-node';
import fs from 'fs-extra';
import { promisify } from 'util';
import { execFile } from 'child_process';
function findPreviewBundlePath(): string {
try {
@@ -73,6 +75,23 @@ export default async function serve(opts: OptionValues) {
mkdocsConfigFileName,
});
// Validate that Docker is up and running
if (opts.docker) {
logger.info('Checking Docker status...');
try {
const runCheck = promisify(execFile);
await runCheck('docker', ['info'], { shell: true });
logger.info(
'Docker is up and running. Proceed to starting up mkdocs server',
);
} catch {
logger.error(
'Docker is not running. Exiting. Please check status of Docker daemon with `docker info` before re-running',
);
return;
}
}
let mkdocsServerHasStarted = false;
const mkdocsLogFunc: LogFunc = data => {
// Sometimes the lines contain an unnecessary extra new line