Compare commits
6 commits
9082835262
...
e349bc7cad
Author | SHA1 | Date | |
---|---|---|---|
e349bc7cad | |||
8cd396335a | |||
35376269b3 | |||
0b265c5bc3 | |||
879a5f1433 | |||
1f410fc847 |
4 changed files with 10 additions and 27 deletions
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"name": "fcnet",
|
|
||||||
"cniVersion": "0.4.0",
|
|
||||||
"plugins": [
|
|
||||||
{
|
|
||||||
"type": "ptp",
|
|
||||||
"ipMasq": true,
|
|
||||||
"ipam": {
|
|
||||||
"type": "host-local",
|
|
||||||
"subnet": "192.168.127.0/24",
|
|
||||||
"resolvConf": "/etc/resolv.conf"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "tc-redirect-tap"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { execFile as _execFile } from "node:child_process";
|
import { execFile as _execFile } from "node:child_process";
|
||||||
import { access, mkdir, open, writeFile } from "node:fs/promises";
|
import { access, mkdir, open, rename, writeFile } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { tar2squashfs } from "./tar2squashfs.js";
|
import { tar2squashfs } from "./tar2squashfs.js";
|
||||||
import { subtle } from "node:crypto";
|
import { subtle } from "node:crypto";
|
||||||
|
@ -10,7 +10,7 @@ type RegistrySecret = string;
|
||||||
const getToken = memoizeDownloader(_getToken);
|
const getToken = memoizeDownloader(_getToken);
|
||||||
let squashfsDownloads = new Map<string, Promise<string>>();
|
let squashfsDownloads = new Map<string, Promise<string>>();
|
||||||
|
|
||||||
const tmpDir = "cache/";
|
const cacheDir = "cache/";
|
||||||
// {
|
// {
|
||||||
// const image = "gitea.nulo.in/nulo/zulip-checkin-cyborg";
|
// const image = "gitea.nulo.in/nulo/zulip-checkin-cyborg";
|
||||||
// const tag = "latest";
|
// const tag = "latest";
|
||||||
|
@ -27,7 +27,7 @@ export function parseImageRef(ref: string): { image: string; tag: string } {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadImage(image: string, tag: string) {
|
export async function downloadImage(image: string, tag: string) {
|
||||||
await mkdir(tmpDir, { recursive: true });
|
await mkdir(cacheDir, { recursive: true });
|
||||||
const manifest = await getManifest(image, tag);
|
const manifest = await getManifest(image, tag);
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
|
@ -75,7 +75,8 @@ async function saveSquashfs(
|
||||||
let p = squashfsDownloads.get(key);
|
let p = squashfsDownloads.get(key);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
p = (async () => {
|
p = (async () => {
|
||||||
const output = join(tmpDir, key);
|
const output = join(cacheDir, key);
|
||||||
|
const progressFile = output + ".downloading";
|
||||||
try {
|
try {
|
||||||
await access(output);
|
await access(output);
|
||||||
// ya está cacheado
|
// ya está cacheado
|
||||||
|
@ -92,7 +93,7 @@ async function saveSquashfs(
|
||||||
const res = await getBlob(image, layer.digest);
|
const res = await getBlob(image, layer.digest);
|
||||||
return res.body!;
|
return res.body!;
|
||||||
});
|
});
|
||||||
await tar2squashfs(layerStreams, output, [
|
await tar2squashfs(layerStreams, progressFile, [
|
||||||
{
|
{
|
||||||
content: configJson,
|
content: configJson,
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -103,6 +104,7 @@ async function saveSquashfs(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
await rename(progressFile, output);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -48,7 +48,9 @@ export async function tar2squashfs(streams, output, extraFiles) {
|
||||||
p.pipe(child.stdin);
|
p.pipe(child.stdin);
|
||||||
p.on("error", console.error);
|
p.on("error", console.error);
|
||||||
|
|
||||||
for (const streamP of streams) {
|
// We reverse the arrays because mksquashfs ignores files if they already exist,
|
||||||
|
// so we leave the last layers first so they are the ones used instead of the last ones
|
||||||
|
for (const streamP of [...streams].reverse()) {
|
||||||
const stream = await streamP;
|
const stream = await streamP;
|
||||||
const ex = extract();
|
const ex = extract();
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"checkJs": true,
|
"checkJs": true,
|
||||||
"lib": ["es2023"],
|
|
||||||
"module": "Node16",
|
|
||||||
"target": "es2022",
|
|
||||||
"noEmit": true
|
"noEmit": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue