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:
@@ -333,7 +333,18 @@ const environmentBindingSchema = z
|
||||
const checkoutStep = z.object({ kind: z.literal("checkout") }).strict();
|
||||
const setupNodeStep = z.object({ kind: z.literal("setup-node") }).strict();
|
||||
const frozenInstallStep = z.object({ kind: z.literal("frozen-install") }).strict();
|
||||
const browserInstallStep = z.object({ kind: z.literal("browser-install") }).strict();
|
||||
/**
|
||||
* `image`: the job runs in Playwright's own image for the pinned
|
||||
* @playwright/test version, which already holds the browsers and their OS
|
||||
* libraries (tests/unit/ci-browser-image.test.ts keeps the versions equal).
|
||||
* Without it the step downloads them, about 900 MB and 3 to 4 minutes a job.
|
||||
*/
|
||||
export const PLAYWRIGHT_JOB_IMAGE_PATTERN =
|
||||
/^mcr\.microsoft\.com\/playwright:v(\d+\.\d+\.\d+)-noble@sha256:[0-9a-f]{64}$/u;
|
||||
const browserInstallStep = z.object({
|
||||
kind: z.literal("browser-install"),
|
||||
image: z.string().regex(PLAYWRIGHT_JOB_IMAGE_PATTERN).optional(),
|
||||
}).strict();
|
||||
const runGateStep = z.object({ kind: z.literal("run-gate") }).strict();
|
||||
const archiveCandidateStep = z
|
||||
.object({
|
||||
@@ -1001,6 +1012,9 @@ function validateContractSemantics(
|
||||
const browserSteps = job.steps.filter(({ kind }) => kind === "browser-install").length;
|
||||
const expected = job.browserGateIds.length > 0 ? 1 : 0;
|
||||
if (browserSteps !== expected) issue(`browser install step drift: ${job.id}`);
|
||||
// A matrix job's non-browser lanes would run in the browser image too.
|
||||
const imaged = job.steps.some((step) => step.kind === "browser-install" && step.image !== undefined);
|
||||
if (imaged && job.kind !== "gate-sequence") issue(`browser job image outside a gate sequence: ${job.id}`);
|
||||
}
|
||||
for (const cycle of findCycles(contract.jobs.map((job) => [job.id, job.needs] as const))) {
|
||||
issue(`job dependency cycle: ${cycle.join(" -> ")}`);
|
||||
|
||||
@@ -190,6 +190,8 @@ function renderJob(
|
||||
" runs-on: ubuntu-latest",
|
||||
` timeout-minutes: ${job.timeoutMinutes}`,
|
||||
);
|
||||
const image = jobImage(job);
|
||||
if (image) lines.push(" container:", ` image: ${yamlScalar(image)}`);
|
||||
if (job.kind === "immutable") {
|
||||
const archive = job.steps.find((step) => step.kind === "archive-candidate");
|
||||
if (!archive || archive.kind !== "archive-candidate") throw new TypeError("immutable job lacks archive step");
|
||||
@@ -213,12 +215,13 @@ function renderJob(
|
||||
lines.push(" outputs:", " deployed: ${{ steps.deploy.outputs.deployed }}");
|
||||
}
|
||||
const jobEnvironment = job.environment.filter((binding) => !isStepScopedSecret(job, binding));
|
||||
if (jobEnvironment.length > 0) {
|
||||
lines.push(" env:");
|
||||
for (const binding of jobEnvironment) {
|
||||
lines.push(` ${binding.name}: ${yamlScalar(binding.value)}`);
|
||||
}
|
||||
}
|
||||
// The build records the image it ran in (scripts/lib/build-environment.ts):
|
||||
// a job in its own image names that one, not the runner label's.
|
||||
const environmentLines = [
|
||||
...(image ? [` CI_RUNNER_IMAGE: ${yamlScalar(image)}`] : []),
|
||||
...jobEnvironment.map((binding) => ` ${binding.name}: ${yamlScalar(binding.value)}`),
|
||||
];
|
||||
if (environmentLines.length > 0) lines.push(" env:", ...environmentLines);
|
||||
if (job.kind === "gate-matrix") {
|
||||
lines.push(" strategy:", " fail-fast: false", " matrix:", " include:");
|
||||
const includesBrowser = job.steps.some(({ kind }) => kind === "browser-install");
|
||||
@@ -263,6 +266,14 @@ function gateHostPrefix(gate: Readonly<{ hostEnvironment?: "system-container" |
|
||||
return gate?.hostEnvironment === "system-container" ? "scripts/run-in-system-container.sh " : "";
|
||||
}
|
||||
|
||||
/** The Playwright image a browser job runs in (`browser-install.image`), if any. */
|
||||
function jobImage(job: CiWorkflowJob): string | undefined {
|
||||
for (const step of job.steps) {
|
||||
if (step.kind === "browser-install" && step.image) return step.image;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function renderStep(
|
||||
job: CiWorkflowJob,
|
||||
step: CiWorkflowStep,
|
||||
@@ -290,6 +301,16 @@ function renderStep(
|
||||
" corepack pnpm install --frozen-lockfile --ignore-scripts",
|
||||
];
|
||||
case "browser-install":
|
||||
if (step.image) {
|
||||
// The job image holds the browsers and their OS libraries; the goldens'
|
||||
// faces are still OS packages it lacks, and it ships no package lists.
|
||||
return [
|
||||
" - name: Install visual-test fonts",
|
||||
" run: |",
|
||||
" $(command -v sudo || true) apt-get update",
|
||||
` $(command -v sudo || true) ${VISUAL_TEST_FONT_INSTALL_ARGUMENTS}`,
|
||||
];
|
||||
}
|
||||
return [
|
||||
" - name: Install Playwright browsers",
|
||||
...(job.kind === "gate-matrix" ? [" if: ${{ matrix.browser }}"] : []),
|
||||
|
||||
Reference in New Issue
Block a user