diff --git a/scripts/src/cicd.ts b/scripts/src/cicd.ts index d1c7f62f..e54c4fb1 100644 --- a/scripts/src/cicd.ts +++ b/scripts/src/cicd.ts @@ -3,6 +3,7 @@ import { createHash } from "node:crypto"; import { readFileSync } from "node:fs"; import { isAbsolute } from "node:path"; +import { gunzipSync } from "node:zlib"; import { repoRoot, rootPath, type UniDeskConfig } from "./config"; import { runCommand, type CommandResult } from "./command"; import { startJob } from "./jobs"; @@ -1881,7 +1882,7 @@ function kubeConfigMapFollowerState(registry: BranchFollowerRegistry, options: P function kubeConfigMapDataValue(registry: BranchFollowerRegistry, options: ParsedOptions, key: string): { ok: boolean; present: boolean; value: string | null; omitted: boolean; error: string } { const template = `{{ with index .data ${JSON.stringify(key)} }}{{ . }}{{ end }}`; - const maxValueBytes = 6144; + const maxValueBytes = 32_768; const script = [ "set -eu", "tmpdir=$(mktemp -d)", @@ -1905,8 +1906,13 @@ function kubeConfigMapDataValue(registry: BranchFollowerRegistry, options: Parse " printf '{\"ok\":true,\"present\":true,\"valueB64\":null,\"omitted\":true,\"valueBytes\":%s,\"errorB64\":\"\"}' \"$value_bytes\"", " exit 0", "fi", - "value_b64=$(printf '%s' \"$value\" | base64 | tr -d '\\n')", - "printf '{\"ok\":true,\"present\":true,\"valueB64\":\"%s\",\"omitted\":false,\"valueBytes\":%s,\"errorB64\":\"\"}' \"$value_b64\" \"$value_bytes\"", + "if command -v gzip >/dev/null 2>&1; then", + " value_b64=$(printf '%s' \"$value\" | gzip -c | base64 | tr -d '\\n')", + " printf '{\"ok\":true,\"present\":true,\"valueB64\":\"%s\",\"encoding\":\"gzip-base64\",\"omitted\":false,\"valueBytes\":%s,\"errorB64\":\"\"}' \"$value_b64\" \"$value_bytes\"", + "else", + " value_b64=$(printf '%s' \"$value\" | base64 | tr -d '\\n')", + " printf '{\"ok\":true,\"present\":true,\"valueB64\":\"%s\",\"encoding\":\"base64\",\"omitted\":false,\"valueBytes\":%s,\"errorB64\":\"\"}' \"$value_b64\" \"$value_bytes\"", + "fi", ].join("\n"); const result = runKubeScript(registry, options, script, "", 10_000); const parsed = result.exitCode === 0 ? parseJsonObject(result.stdout) : null; @@ -1925,10 +1931,12 @@ function kubeConfigMapDataValue(registry: BranchFollowerRegistry, options: Parse const present = parsed.present === true; const omitted = parsed.omitted === true; const valueB64 = typeof parsed.valueB64 === "string" ? parsed.valueB64 : null; + const encoding = stringOrNull(parsed.encoding) ?? "base64"; + const valueBuffer = valueB64 === null ? null : Buffer.from(valueB64, "base64"); return { ok, present, - value: valueB64 === null ? null : Buffer.from(valueB64, "base64").toString("utf8"), + value: valueBuffer === null ? null : encoding === "gzip-base64" ? gunzipSync(valueBuffer).toString("utf8") : valueBuffer.toString("utf8"), omitted, error: redactText(error), };