ci(gates): 브라우저 job을 Playwright 이미지에서 돌린다
문제: merge / browser tests job은 `playwright install --with-deps`로 매번 apt 276개(180MB)와 브라우저 넷(전체 Chrome 포함), 글꼴 220MB를 받는다. runner에서 job마다 198~242초, 약 900MB다(run 56·80·81). run 54에서는 이 단계 중 desktop 루트가 90%까지 차 Gitea가 내려갔다. 고른 방법: browser-install 단계에 `image`를 두고, 생성기가 그 job의 container로 그린다. 값은 @playwright/test와 같은 버전의 Playwright 공식 이미지 digest(mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed…)다. 그 이미지에는 1.62의 브라우저와 OS 라이브러리가 들어 있다. 단계는 visual 골든의 글꼴만 apt로 설치한다(이미지에 패키지 목록이 없어 apt-get update 먼저). job env의 CI_RUNNER_IMAGE를 그 이미지로 적어, 빌드가 기록하는 runner 이미지가 실제와 맞는다. - 계약: image는 Playwright 레지스트리의 noble 태그 + digest만 받고, gate-sequence job에만 둔다(matrix의 비브라우저 lane까지 그 이미지로 돌지 않게). tests/unit/ci-browser-image.test.ts가 태그 버전 = package.json @playwright/test 버전을 지킨다. - release_gate(lab-performance)는 그대로 둔다(release 단계, 범위 밖). - 버린 대안: runner 이미지 위에 브라우저를 구운 자체 이미지(레지스트리 쓰기 토큰과 빌드 경로가 필요), 브라우저 폴더 캐시(apt 의존성 100초가 남는다). 위험·한계: 이미지의 OS 라이브러리 판이 runner 이미지와 조금 다를 수 있어 visual 골든(maxDiffPixels 50)이 바뀔 수 있다. runner 실행으로 확인한다. 이미지(압축 947MB)를 runner의 dind가 한 번 받는다. Playwright를 올릴 때 이미지 digest도 같이 바꿔야 한다(위 시험이 막는다). 검증(desktop): generate:ci-workflow 뒤 check:ci PASS, ci-workflow-generation ·ci-browser-image 시험 통과(스냅샷 1개 갱신), check:types·eslint rc=0. runner 실행은 PR에서.
This commit is contained in:
@@ -126,6 +126,10 @@ jobs:
|
||||
if: \${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
container:
|
||||
image: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
env:
|
||||
CI_RUNNER_IMAGE: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
||||
with:
|
||||
@@ -137,9 +141,9 @@ jobs:
|
||||
run: |
|
||||
corepack enable
|
||||
corepack pnpm install --frozen-lockfile --ignore-scripts
|
||||
- name: Install Playwright browsers
|
||||
- name: Install visual-test fonts
|
||||
run: |
|
||||
corepack pnpm exec playwright install --with-deps chromium firefox webkit
|
||||
$(command -v sudo || true) apt-get update
|
||||
$(command -v sudo || true) apt-get install -y fonts-noto-core fonts-noto-cjk fonts-noto-cjk-extra fonts-liberation
|
||||
- name: "FE-GATE-008 / e2e"
|
||||
if: \${{ !cancelled() }}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { loadCiGateContract, PLAYWRIGHT_JOB_IMAGE_PATTERN } from "../../scripts/contracts/ci-gates.ts";
|
||||
import { renderCiWorkflow } from "../../scripts/generate-ci-workflow.ts";
|
||||
|
||||
/**
|
||||
* merge_browser runs in Playwright's own image so it does not download the
|
||||
* browsers and their OS libraries in every job (about 900 MB, 200 to 240 s on
|
||||
* the runner). The image's browsers are the ones @playwright/test of the same
|
||||
* version expects; a Playwright update without the image left the browsers
|
||||
* missing (or the image without the version's revisions).
|
||||
*/
|
||||
describe("browser job image", () => {
|
||||
it("is Playwright's image for the pinned @playwright/test version, by digest", async () => {
|
||||
const pinned = (
|
||||
JSON.parse(readFileSync("package.json", "utf8")) as { devDependencies: Record<string, string> }
|
||||
).devDependencies["@playwright/test"];
|
||||
const contract = await loadCiGateContract(process.cwd());
|
||||
const images = contract.jobs.flatMap((job) =>
|
||||
job.steps.flatMap((step) => (step.kind === "browser-install" && step.image ? [[job.id, step.image] as const] : [])),
|
||||
);
|
||||
expect(images.map(([jobId]) => jobId)).toEqual(["merge_browser"]);
|
||||
for (const [, image] of images) {
|
||||
expect(PLAYWRIGHT_JOB_IMAGE_PATTERN.exec(image)?.[1]).toBe(pinned);
|
||||
}
|
||||
});
|
||||
|
||||
it("is the job container, and the runner image the build records", async () => {
|
||||
const contract = await loadCiGateContract(process.cwd());
|
||||
const image = contract.jobs
|
||||
.find(({ id }) => id === "merge_browser")!
|
||||
.steps.find((step) => step.kind === "browser-install");
|
||||
const workflow = renderCiWorkflow(contract);
|
||||
const job = workflow.slice(workflow.indexOf(" merge_browser:\n"), workflow.indexOf(" release_gate:\n"));
|
||||
expect(image?.kind === "browser-install" && image.image).toBeTruthy();
|
||||
const ref = image?.kind === "browser-install" ? image.image! : "";
|
||||
expect(job).toContain(` container:\n image: "${ref}"\n`);
|
||||
expect(job).toContain(` env:\n CI_RUNNER_IMAGE: "${ref}"\n`);
|
||||
expect(job).not.toContain("playwright install");
|
||||
});
|
||||
|
||||
it("refuses an image outside Playwright's registry or without a digest", async () => {
|
||||
for (const image of [
|
||||
"mcr.microsoft.com/playwright:v1.62.0-noble",
|
||||
"docker.io/library/ubuntu:24.04@sha256:" + "a".repeat(64),
|
||||
]) {
|
||||
expect(PLAYWRIGHT_JOB_IMAGE_PATTERN.test(image), image).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1641,17 +1641,25 @@ describe("CI workflow generation", () => {
|
||||
// them, after `--with-deps` has refreshed the package lists.
|
||||
it("installs the visual-test font packages in every browser step", async () => {
|
||||
const workflow = renderCiWorkflow(await loadCiGateContract(process.cwd()));
|
||||
const browserSteps = workflow
|
||||
.split(" - name: ")
|
||||
.filter((step) => step.startsWith("Install Playwright browsers"));
|
||||
expect(browserSteps).toHaveLength(2);
|
||||
for (const step of browserSteps) {
|
||||
const steps = workflow.split(" - name: ");
|
||||
const fontsInstall = `apt-get install -y ${VISUAL_TEST_FONT_PACKAGES.join(" ")}`;
|
||||
// A job without its own image downloads the browsers with their OS
|
||||
// libraries; `--with-deps` refreshes the package lists first.
|
||||
const downloading = steps.filter((step) => step.startsWith("Install Playwright browsers"));
|
||||
// merge_browser runs in Playwright's image, which has the browsers but no
|
||||
// package lists (tests/unit/ci-browser-image.test.ts).
|
||||
const imaged = steps.filter((step) => step.startsWith("Install visual-test fonts"));
|
||||
expect([downloading.length, imaged.length]).toEqual([1, 1]);
|
||||
for (const step of downloading) {
|
||||
const playwright = step.indexOf("playwright install --with-deps");
|
||||
const fonts = step.indexOf(
|
||||
`apt-get install -y ${VISUAL_TEST_FONT_PACKAGES.join(" ")}`,
|
||||
);
|
||||
expect(playwright).toBeGreaterThan(0);
|
||||
expect(fonts).toBeGreaterThan(playwright);
|
||||
expect(step.indexOf(fontsInstall)).toBeGreaterThan(playwright);
|
||||
}
|
||||
for (const step of imaged) {
|
||||
expect(step).not.toContain("playwright install");
|
||||
const update = step.indexOf("apt-get update");
|
||||
expect(update).toBeGreaterThan(0);
|
||||
expect(step.indexOf(fontsInstall)).toBeGreaterThan(update);
|
||||
}
|
||||
expect(VISUAL_TEST_FONT_PACKAGES).toEqual([
|
||||
"fonts-noto-core",
|
||||
|
||||
Reference in New Issue
Block a user