1e6b0e5684
使用专用 BuildKit builder 持久复用 Cargo 与 npm 下载缓存,并支持从可信镜像导入 按当前依赖物化镜像下载快照,配置独立缓存回收策略 补齐 AGC vendor 本地依赖清单并缩小构建上下文 增加缓存维护阶段、耗时和失败日志路径 补充下载缓存与构建上下文测试,同步部署说明和共享记忆
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// 持久下载缓存可以保留旧版本;交付给 CI 镜像的快照只带当前 lock 已下载的包。
|
|
import fs from 'node:fs/promises';
|
|
import { createRequire } from 'node:module';
|
|
import path from 'node:path';
|
|
import { pipeline } from 'node:stream/promises';
|
|
|
|
const [npmRoot, lockPath, source, destination] = process.argv.slice(2);
|
|
if (!npmRoot || !lockPath || !source || !destination) {
|
|
throw new Error(
|
|
'usage: export-ci-npm-download-cache.mjs <npm-root> <lock> <source> <destination>',
|
|
);
|
|
}
|
|
const require = createRequire(path.resolve(npmRoot, 'package.json'));
|
|
const cacache = require('cacache');
|
|
const lock = JSON.parse(await fs.readFile(lockPath, 'utf8'));
|
|
const integrities = new Set(
|
|
Object.values(lock.packages).flatMap((entry) =>
|
|
typeof entry.integrity === 'string' ? [entry.integrity] : [],
|
|
),
|
|
);
|
|
let count = 0;
|
|
for await (const entry of cacache.ls.stream(source)) {
|
|
if (!integrities.has(entry.integrity)) continue;
|
|
await pipeline(
|
|
cacache.get.stream(source, entry.key, { integrity: entry.integrity }),
|
|
cacache.put.stream(destination, entry.key, {
|
|
integrity: entry.integrity,
|
|
metadata: entry.metadata,
|
|
}),
|
|
);
|
|
count += 1;
|
|
}
|
|
console.log(
|
|
`[ci-image] exported ${count} npm cache entries for the current lock`,
|
|
);
|