Skip to content

Commit 56f4d96

Browse files
push: Fix stuck extraction tar jobs. (#68)
* Add some debug logging to investigate stuck jobs. * Use extract from tar package instead of tar-fs.
1 parent 3b67d13 commit 56f4d96

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

push/bun.lockb

9.57 KB
Binary file not shown.

push/index.ts

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { $, CryptoHasher, file, write } from "bun";
2-
import tar from "tar-fs";
2+
import { extract } from "tar";
33

44
import stream from "node:stream";
5+
import { mkdir } from "node:fs/promises";
56

67
const username = process.env["USERNAME_REGISTRY"];
78
async function read(stream: stream.Readable): Promise<string> {
@@ -54,6 +55,8 @@ if (imageID === "") {
5455
process.exit(1);
5556
}
5657

58+
console.log(`Image ${image} found locally, saving to disk...`);
59+
5760
const tarFile = imageID.trim() + ".tar";
5861
const imagePath = ".output-image";
5962
if (!(await file(tarFile).exists())) {
@@ -64,31 +67,17 @@ if (!(await file(tarFile).exists())) {
6467
process.exit(1);
6568
}
6669

67-
const extract = tar.extract(imagePath);
68-
69-
await Bun.file(tarFile)
70-
.stream()
71-
.pipeTo(
72-
new WritableStream({
73-
write(value) {
74-
return new Promise((res, rej) => {
75-
extract.write(value, (err) => {
76-
if (err) {
77-
rej(err);
78-
return;
79-
}
80-
});
81-
extract.once("drain", () => {
82-
res();
83-
});
84-
});
85-
},
86-
close() {
87-
extract.end();
88-
},
89-
}),
90-
);
91-
}
70+
console.log(`Image saved as ${tarFile}, extracting...`);
71+
72+
await mkdir(imagePath);
73+
74+
const result = await extract({
75+
file: tarFile,
76+
cwd: imagePath,
77+
});
78+
79+
console.log(`Extracted to ${imagePath}`);
80+
}
9281

9382
type DockerSaveConfigManifest = {
9483
Config: string;
@@ -110,7 +99,7 @@ if (manifests.length > 1) {
11099
import plimit from "p-limit";
111100
const pool = plimit(5);
112101
import zlib from "node:zlib";
113-
import { mkdir, rename, rm } from "node:fs/promises";
102+
import { rename, rm } from "node:fs/promises";
114103

115104
const cacheFolder = ".cache";
116105

push/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"dependencies": {
1313
"node-fetch": "^3.3.2",
1414
"p-limit": "^6.1.0",
15-
"tar-fs": "^3.0.6"
15+
"tar": "^7.4.3"
1616
}
1717
}

0 commit comments

Comments
 (0)