From a14ead6486b59ab6f9f237e75c60ec172070844d Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Fri, 19 Jul 2024 13:25:38 +0200 Subject: [PATCH] docker: isDaemonRunning func Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/docker/docker.test.itg.ts | 6 ++++++ src/docker/docker.ts | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/__tests__/docker/docker.test.itg.ts b/__tests__/docker/docker.test.itg.ts index 5996d3df..5c7db47a 100644 --- a/__tests__/docker/docker.test.itg.ts +++ b/__tests__/docker/docker.test.itg.ts @@ -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; +maybe('isDaemonRunning', () => { + it('checks if daemon is running', async () => { + expect(await Docker.isDaemonRunning()).toBe(true); + }); +}); + maybe('pull', () => { // prettier-ignore test.each([ diff --git a/src/docker/docker.ts b/src/docker/docker.ts index 2584b060..517b0d8c 100644 --- a/src/docker/docker.ts +++ b/src/docker/docker.ts @@ -54,6 +54,17 @@ export class Docker { }); } + public static async isDaemonRunning(): Promise { + try { + await Docker.getExecOutput([`version`], { + silent: true + }); + return true; + } catch (e) { + return false; + } + } + public static async exec(args?: string[], options?: ExecOptions): Promise { return Exec.exec('docker', args, Docker.execOptions(options)); }