docker: isDaemonRunning func

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2024-07-19 13:25:38 +02:00
parent f9de623b1d
commit a14ead6486
No known key found for this signature in database
GPG Key ID: ADE44D8C9D44FBE4
2 changed files with 17 additions and 0 deletions

View File

@ -20,6 +20,12 @@ import {Docker} from '../../src/docker/docker';
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip; const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;
maybe('isDaemonRunning', () => {
it('checks if daemon is running', async () => {
expect(await Docker.isDaemonRunning()).toBe(true);
});
});
maybe('pull', () => { maybe('pull', () => {
// prettier-ignore // prettier-ignore
test.each([ test.each([

View File

@ -54,6 +54,17 @@ export class Docker {
}); });
} }
public static async isDaemonRunning(): Promise<boolean> {
try {
await Docker.getExecOutput([`version`], {
silent: true
});
return true;
} catch (e) {
return false;
}
}
public static async exec(args?: string[], options?: ExecOptions): Promise<number> { public static async exec(args?: string[], options?: ExecOptions): Promise<number> {
return Exec.exec('docker', args, Docker.execOptions(options)); return Exec.exec('docker', args, Docker.execOptions(options));
} }