Skip to content

Commit f7a8b21

Browse files
authored
Merge pull request #416 from crazy-max/docker-daemon-up
buildx(history): check docker daemon is running before exporting
2 parents f9de623 + 8177e15 commit f7a8b21

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

__tests__/docker/docker.test.itg.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import {Docker} from '../../src/docker/docker';
2020

2121
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;
2222

23+
maybe('isDaemonRunning', () => {
24+
it('checks if daemon is running', async () => {
25+
expect(await Docker.isDaemonRunning()).toBe(true);
26+
});
27+
});
28+
2329
maybe('pull', () => {
2430
// prettier-ignore
2531
test.each([

src/buildx/history.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export class History {
5050
if (!(await Docker.isAvailable())) {
5151
throw new Error('Docker is required to export a build record');
5252
}
53+
if (!(await Docker.isDaemonRunning())) {
54+
throw new Error('Docker daemon is not running, skipping build record export');
55+
}
5356
if (!(await this.buildx.versionSatisfies('>=0.13.0'))) {
5457
throw new Error('Buildx >= 0.13.0 is required to export a build record');
5558
}

src/docker/docker.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ export class Docker {
5454
});
5555
}
5656

57+
public static async isDaemonRunning(): Promise<boolean> {
58+
try {
59+
await Docker.getExecOutput([`version`], {
60+
silent: true
61+
});
62+
return true;
63+
} catch (e) {
64+
return false;
65+
}
66+
}
67+
5768
public static async exec(args?: string[], options?: ExecOptions): Promise<number> {
5869
return Exec.exec('docker', args, Docker.execOptions(options));
5970
}

0 commit comments

Comments
 (0)