Skip to content

Commit 606a72d

Browse files
added check to find docker on podman
Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent e6ea0bf commit 606a72d

File tree

1 file changed

+62
-11
lines changed

1 file changed

+62
-11
lines changed

src/serverlessFunction/functions.ts

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ import { isKnativeServingAware } from './knative';
1717
import { multiStep } from './multiStepInput';
1818
import { FunctionContent, FunctionObject, FunctionSession } from './types';
1919
import Dockerode = require('dockerode');
20+
import { CliExitData, ChildProcessUtil } from '../util/childProcessUtil';
21+
22+
interface DockerStatus {
23+
error: boolean;
24+
message: string;
25+
}
2026

2127
export class Functions {
2228

@@ -142,9 +148,20 @@ export class Functions {
142148
}
143149
}
144150

151+
private async checkDocker(): Promise<boolean> {
152+
let dockerStatus: DockerStatus = await this.isDockerRunning();
153+
if (dockerStatus.error) {
154+
dockerStatus = await this.isDockerOnPodman();
155+
if (dockerStatus.error) {
156+
void window.showErrorMessage(dockerStatus.message)
157+
return false;
158+
}
159+
}
160+
return true;
161+
}
162+
145163
public async build(context: FunctionObject, s2iBuild: boolean): Promise<void> {
146-
const isDockerRunning = await this.isDockerRunning();
147-
if (!isDockerRunning) {
164+
if (! await this.checkDocker()) {
148165
return;
149166
}
150167
const existingTerminal: OpenShiftTerminalApi = this.buildTerminalMap.get(`build-${context.folderURI.fsPath}`);
@@ -200,8 +217,7 @@ export class Functions {
200217
}
201218

202219
public async run(context: FunctionObject, runBuild = false) {
203-
const isDockerRunning = await this.isDockerRunning();
204-
if (!isDockerRunning) {
220+
if (! await this.checkDocker()) {
205221
return;
206222
}
207223
const terminal = await OpenShiftTerminalManager.getInstance().createTerminal(
@@ -374,21 +390,56 @@ export class Functions {
374390
return null;
375391
}
376392

377-
private async isDockerRunning(): Promise<boolean> {
378-
return new Promise<boolean>((resolve) => {
393+
private async isDockerRunning(): Promise<DockerStatus> {
394+
return new Promise<DockerStatus>((resolve) => {
379395
try {
380396
const docker = new Dockerode();
381397
docker.ping((err) => {
382398
if (err) {
383-
void window.showErrorMessage('Docker is not running, Please start the docker process');
384-
resolve(false);
399+
resolve({
400+
error: true,
401+
message: 'Docker is not running, Please start the docker process'
402+
});
385403
}
386-
resolve(true);
404+
resolve({
405+
error: false,
406+
message: ''
407+
});
387408
});
388409
} catch (e) {
389-
void window.showErrorMessage('Docker is not installed, Please install and start the docker process');
390-
resolve(false);
410+
resolve({
411+
error: true,
412+
message: 'Docker not installed, Please install and start the docker process'
413+
});
391414
}
392415
});
393416
}
417+
418+
private async isDockerOnPodman(): Promise<DockerStatus> {
419+
try {
420+
const resultRaw: CliExitData = await ChildProcessUtil.Instance.execute('podman info -f=json');
421+
if (resultRaw.stderr.toLowerCase().indexOf('cannot connect') !== -1) {
422+
return ({
423+
error: true,
424+
message: 'Docker is not running, Please start the docker process'
425+
});
426+
}
427+
const resultObj: { registries: { search: string[] } } = JSON.parse(resultRaw.stdout);
428+
if (resultObj.registries && !resultObj.registries.search?.includes('docker.io')) {
429+
return ({
430+
error: true,
431+
message: 'Docker is not running, Please start the docker process'
432+
});
433+
}
434+
return ({
435+
error: false,
436+
message: ''
437+
})
438+
} catch (e) {
439+
return ({
440+
error: true,
441+
message: 'Docker not installed, Please install and start the docker process'
442+
});
443+
}
444+
}
394445
}

0 commit comments

Comments
 (0)