Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildx(history): check docker daemon is running before exporting #416

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions src/buildx/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class History {
if (!(await Docker.isAvailable())) {
throw new Error('Docker is required to export a build record');
}
if (!(await Docker.isDaemonRunning())) {
throw new Error('Docker daemon is not running, skipping build record export');
}
if (!(await this.buildx.versionSatisfies('>=0.13.0'))) {
throw new Error('Buildx >= 0.13.0 is required to export a build record');
}
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
Loading