mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
* fix(aws-lambda): run chrome-headless-shell 158 in the arm64 video image The arm64 video image now installs Chrome for Testing's linux-arm64 chrome-headless-shell 158.0.8127.36, pinned by sha256 and fetched with curl -f, as the whole shell folder. The Lambda Node 22 base has none of the shared libraries the shell links and no fonts, so the image installs them from the base's repository at the same pinned release. The image sets HYPERFRAMES_LAMBDA_CHROME_SOURCE and HYPERFRAMES_LAMBDA_CHROME_PATH itself, and the nested video function no longer passes ChromeSource, which would override them. stage-arm64-image.ts stops fetching the sparticuz arm64 pack and drops the ZIP's x86 sparticuz Chrome instead. The x86 handler ZIP stays on @sparticuz/chromium, bumped from 148.0.0 to 153.0.0. It builds at 258,502,222 bytes unzipped, under Lambda's 262,144,000-byte limit and the 248 MiB in-house gate. Two fixes for --source=chrome-headless-shell: - build-zip.ts staged only the executable, which exits at launch without its ICU data and .pak files. It now stages the whole shell folder at chrome-headless-shell-linux64/. - Nothing set HYPERFRAMES_LAMBDA_CHROME_PATH, which src/chromium.ts requires for that source. The SAM template and the CDK stack now set it to the bundled shell when ChromeSource asks for it. Drops the unused @types/aws-lambda devDependency, which the dead-code audit reports whenever this package's manifest changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci(publish): build the Lambda arm64 video image on an ARM runner The video stage now installs Chrome's system libraries with microdnf, so it runs code for arm64. The pack job built that image on ubuntu-latest with no emulation, which it could do only while the stage copied files. A new lambda-video-image job builds it natively on ubuntu-24.04-arm, from the handler zip whose sha256 the zip job reported, and reports the OCI tarball's sha256. Pack downloads that tarball, checks the sha256 against the job's, and pins it as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(aws-lambda): fit the comment ratchet and the package size budget chromium.ts loses the two doc lines on BUNDLED_SHELL_DIR and BUNDLED_SHELL_PATH; the names and the SAM template's comment already say what they are. @hyperframes/aws-lambda's unpacked budget goes from 290,508 to 298,000 bytes. The package unpacks to 295,324 bytes, up from the shared chrome-headless-shell staging module the ZIP and image scripts now import and from the README and docs that describe the two Chrome sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2.8 KiB
TypeScript
63 lines
2.8 KiB
TypeScript
import { cpSync, existsSync, readdirSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { BUNDLED_SHELL_DIR } from "../src/chromium.js";
|
|
|
|
/**
|
|
* Stage the newest linux64 chrome-headless-shell from the Puppeteer cache under `home` into
|
|
* `<stagingDir>/<BUNDLED_SHELL_DIR>/`. The whole folder: the executable alone exits at launch
|
|
* ("Invalid file descriptor to ICU data received") without icudtl.dat and its .pak files.
|
|
* Returns the cached version it staged.
|
|
*/
|
|
export function stageChromeHeadlessShell(
|
|
stagingDir: string,
|
|
home = process.env.HOME ?? "/root",
|
|
): string {
|
|
// The fallback path bundles the same chrome-headless-shell build the K8s deploy uses. It is
|
|
// fetched via `@puppeteer/browsers` into the host's `~/.cache/puppeteer/`; the build re-uses that
|
|
// cache rather than redownloading.
|
|
const baseDir = join(home, ".cache", "puppeteer", "chrome-headless-shell");
|
|
if (!existsSync(baseDir)) {
|
|
throw new Error(
|
|
`[build-zip] chrome-headless-shell cache missing at ${baseDir}. Run\n` +
|
|
` npx --yes @puppeteer/browsers install chrome-headless-shell@158.0.8127.36 --path ${home}/.cache/puppeteer\n` +
|
|
`before --source=chrome-headless-shell.`,
|
|
);
|
|
}
|
|
// Sort by numeric semver descending. `sort().reverse()` is lexicographic,
|
|
// which silently picks "99.0.0" over "131.0.0" once Chrome ships
|
|
// three-digit majors that aren't strictly width-aligned. `compareSemver`
|
|
// returns negative/zero/positive on (a, b), so descending = `b - a`.
|
|
const versions = readdirSync(baseDir).sort((a, b) => compareSemver(b, a));
|
|
for (const v of versions) {
|
|
const folder = join(baseDir, v, "chrome-headless-shell-linux64");
|
|
if (existsSync(join(folder, "chrome-headless-shell"))) {
|
|
// cpSync keeps each file's mode, so the executable stays executable.
|
|
cpSync(folder, join(stagingDir, BUNDLED_SHELL_DIR), { recursive: true });
|
|
return v;
|
|
}
|
|
}
|
|
throw new Error(`[build-zip] no linux64 chrome-headless-shell binary found under ${baseDir}.`);
|
|
}
|
|
|
|
/**
|
|
* Compare two semver-shaped strings like "131.0.6778.108". Treats any
|
|
* non-numeric directory name as `-Infinity` so it sorts to the bottom
|
|
* (Puppeteer's cache layout sometimes includes `latest` or branch tags).
|
|
* Used by `stageChromeHeadlessShell` to pick the newest cached Chrome
|
|
* without tripping on the lexicographic "99 > 131" trap.
|
|
*/
|
|
function compareSemver(a: string, b: string): number {
|
|
const partsA = a.split(".").map((s) => Number.parseInt(s, 10));
|
|
const partsB = b.split(".").map((s) => Number.parseInt(s, 10));
|
|
const len = Math.max(partsA.length, partsB.length);
|
|
for (let i = 0; i < len; i++) {
|
|
const ai = partsA[i] ?? 0;
|
|
const bi = partsB[i] ?? 0;
|
|
if (Number.isNaN(ai) && Number.isNaN(bi)) continue;
|
|
if (Number.isNaN(ai)) return -1;
|
|
if (Number.isNaN(bi)) return 1;
|
|
if (ai !== bi) return ai - bi;
|
|
}
|
|
return 0;
|
|
}
|