Skip to content

Commit

Permalink
docker: isDaemonRunning func
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jul 19, 2024
1 parent f9de623 commit a14ead6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions __tests__/docker/docker.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
11 changes: 11 additions & 0 deletions src/docker/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
return Exec.exec('docker', args, Docker.execOptions(options));
}
Expand Down

0 comments on commit a14ead6

Please sign in to comment.