From 467abd16d48b3caa578dff13db09a74960c1ee2c Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Wed, 24 Jun 2026 10:45:06 +0800 Subject: [PATCH] fix(hwlab): avoid prepare-source yaml runtime dependency (#809) Co-authored-by: Codex --- config/hwlab-node-control-plane.yaml | 2 -- scripts/src/hwlab-node-impl.ts | 18 +++++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/config/hwlab-node-control-plane.yaml b/config/hwlab-node-control-plane.yaml index e498c938..135a7f6d 100644 --- a/config/hwlab-node-control-plane.yaml +++ b/config/hwlab-node-control-plane.yaml @@ -152,8 +152,6 @@ targets: - COPY --from=python-runtime /usr/local /usr/local - COPY --from=docker-cli-runtime /usr/local/bin/docker /usr/local/bin/docker - RUN ln -sf /usr/local/bin/bun /usr/local/bin/bunx - - ENV NODE_PATH=/usr/local/lib/node_modules - - RUN npm install -g --omit=dev --ignore-scripts --no-audit --no-fund yaml@2.8.3 && NODE_PATH=/usr/local/lib/node_modules node -e "require.resolve('yaml')" - RUN node --version && npm --version && bun --version && git --version && python3 --version && docker --version && ssh -V buildArgs: NODE_IMAGE: docker.io/library/node:22-bookworm-slim diff --git a/scripts/src/hwlab-node-impl.ts b/scripts/src/hwlab-node-impl.ts index be1acf37..ca063fe2 100644 --- a/scripts/src/hwlab-node-impl.ts +++ b/scripts/src/hwlab-node-impl.ts @@ -4949,18 +4949,7 @@ function nodeRuntimePipelinePostprocessScript(): string[] { "const stepEnv = { ...proxyEnv, ...dockerProxyEnv, ...(overlay.stepEnv || {}) };", "function prepareSourceDependencyScript() {", " return `prepare_source_dependencies_started_ms=\"$(ci_now_ms)\"", - "node <<'NODE_UNIDESK_YAML_DEPENDENCY'", - "const dependency = 'yaml';", - "function emit(status, extra = {}) { console.error(JSON.stringify({ event: 'prepare-source-dependencies', status, dependency, ...extra })); }", - "try {", - " const resolved = require.resolve('yaml');", - " emit('cached', { manager: 'tools-image', resolved });", - " process.exit(0);", - "} catch (error) {", - " emit('failed', { reason: 'tools-image-missing-yaml', message: error && error.message ? error.message : String(error) });", - " process.exit(34);", - "}", - "NODE_UNIDESK_YAML_DEPENDENCY", + "echo '{\"event\":\"prepare-source-dependencies\",\"status\":\"not-required\",\"dependency\":\"yaml\",\"manager\":\"inline-service-id-parser\"}' >&2", "ci_timing_emit prepare-source-dependencies succeeded \"$prepare_source_dependencies_started_ms\"`;", "}", "function validatePrepareSourceDependencyScript(script) {", @@ -5620,6 +5609,9 @@ function nodeRuntimePipelinePostprocessScript(): string[] { "}", "function patchScript(script) {", " let result = String(script || '');", + " const inlineDeployServiceIdParser = `const deployText = fs.readFileSync(deployPath, 'utf8');\\nconst deploy = { services: [...deployText.matchAll(/(?:^|\\\\n)\\\\s*serviceId:\\\\s*[\\\"']?([^\\\"'\\\\n#]+)[\\\"']?/g)].map((match) => ({ serviceId: match[1].trim() })) };`;", + " result = result.split('import { readStructuredFile } from \"./scripts/src/structured-config.mjs\";\\n').join('');", + " result = result.split('const deploy = await readStructuredFile(process.cwd(), deployPath);').join(inlineDeployServiceIdParser);", " if (result.includes('npm run gitops:ts:check')) {", " result = result.replace(/\\n[ \\t]*npm run gitops:ts:check\\n/g, '\\n echo \\'{\"event\":\"unidesk-node-contract-check\",\"status\":\"skipped\",\"reason\":\"d601-yaml-render-check-replaces-tsc-gate\"}\\' >&2\\n');", " }", @@ -5859,7 +5851,7 @@ function nodeRuntimePipelinePostprocessScript(): string[] { "}", "if (!structured && !changed && !text.includes(`--gitops-root ${quotedRoot}`) && !text.includes(`--gitops-root ${escapedQuotedRoot}`)) { throw new Error(`generated pipeline missing expected gitops-render invocation in ${pipelinePath}`); }", "if (text.includes('prepare_source_dependencies_started_ms=\"$(ci_now_ms)\"') && text.includes('npm ci --ignore-scripts --no-audit --prefer-offline')) { throw new Error(`generated pipeline still uses full npm ci prepare-source dependency install in ${pipelinePath}`); }", - "if (text.includes('prepare_source_dependencies_started_ms=\"$(ci_now_ms)\"') && !text.includes('NODE_UNIDESK_YAML_DEPENDENCY')) { throw new Error(`generated pipeline missing UniDesk yaml dependency install in ${pipelinePath}`); }", + "if (text.includes('readStructuredFile(process.cwd(), deployPath)')) { throw new Error(`generated pipeline still imports YAML parser for prepare-source catalog check in ${pipelinePath}`); }", "if (text.includes('/yaml/-/yaml-') || text.includes('bun add --no-save --ignore-scripts') || text.includes('npm install --package-lock=false --no-save')) { throw new Error(`generated pipeline still downloads yaml during prepare-source in ${pipelinePath}`); }", "if (text.includes('npm run gitops:ts:check')) { throw new Error(`generated pipeline still uses npm gitops:ts:check gate in ${pipelinePath}`); }", "fs.writeFileSync(pipelinePath, text);",