Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -0,0 +1,10 @@
|
||||
[history]
|
||||
maxAge = 86400
|
||||
maxEntries = 20
|
||||
|
||||
[worker.oci]
|
||||
gc = true
|
||||
reservedSpace = "2GB"
|
||||
maxUsedSpace = "30GB"
|
||||
minFreeSpace = "100GB"
|
||||
max-parallelism = 12
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
deploy_web() {
|
||||
pnpm --offline --config.inject-workspace-packages=true \
|
||||
--filter @hivegrid/runtime-web deploy --prod /prod/web
|
||||
}
|
||||
|
||||
deploy_api() {
|
||||
pnpm --offline --config.inject-workspace-packages=true \
|
||||
--filter @hivegrid/runtime-api deploy --prod --no-optional /prod/api
|
||||
}
|
||||
|
||||
deploy_mcp() {
|
||||
pnpm --offline --config.inject-workspace-packages=true \
|
||||
--filter @hivegrid/runtime-mcp deploy --prod --no-optional /prod/mcp
|
||||
}
|
||||
|
||||
deploy_portal_controller() {
|
||||
pnpm --offline --config.inject-workspace-packages=true \
|
||||
--filter @hivegrid/runtime-portal-domain-controller deploy --prod --no-optional /prod/portal-domain-controller
|
||||
}
|
||||
|
||||
deploy_worker() {
|
||||
pnpm --offline --config.inject-workspace-packages=true \
|
||||
--filter @hivegrid/runtime-worker deploy --prod /prod/worker
|
||||
}
|
||||
|
||||
tasks=(deploy_web deploy_api deploy_mcp deploy_portal_controller deploy_worker)
|
||||
targets=(web api mcp portal-domain-controller worker)
|
||||
mkdir -p /prod
|
||||
|
||||
run_wave() {
|
||||
local phase="$1"
|
||||
local status=0
|
||||
local child_status
|
||||
local index
|
||||
local task
|
||||
local -a pids=()
|
||||
|
||||
for task in "${tasks[@]}"; do
|
||||
echo "[production-deps] START phase=${phase} task=${task}" >&2
|
||||
"$task" &
|
||||
pids+=("$!")
|
||||
done
|
||||
|
||||
# Always reap every child. A quick failure must not leave another deploy
|
||||
# writing into /prod while the fallback cleans or retries the closures.
|
||||
for index in "${!pids[@]}"; do
|
||||
if wait "${pids[$index]}"; then
|
||||
echo "[production-deps] PASS phase=${phase} task=${tasks[$index]}" >&2
|
||||
continue
|
||||
else
|
||||
child_status=$?
|
||||
fi
|
||||
|
||||
echo "[production-deps] FAIL phase=${phase} task=${tasks[$index]} exit_code=${child_status}" >&2
|
||||
if [[ "$status" -eq 0 ]]; then
|
||||
status="$child_status"
|
||||
fi
|
||||
done
|
||||
|
||||
return "$status"
|
||||
}
|
||||
|
||||
initial_status=0
|
||||
run_wave offline-first || initial_status=$?
|
||||
if [[ "$initial_status" -eq 0 ]]; then
|
||||
echo "[production-deps] READY source=warm-store" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[production-deps] REFRESH initial_exit_code=${initial_status}" >&2
|
||||
for target in "${targets[@]}"; do
|
||||
rm -rf -- "/prod/${target}"
|
||||
done
|
||||
|
||||
if pnpm fetch --frozen-lockfile; then
|
||||
echo "[production-deps] FETCH PASS" >&2
|
||||
else
|
||||
fetch_status=$?
|
||||
echo "[production-deps] FETCH FAIL exit_code=${fetch_status} initial_exit_code=${initial_status}" >&2
|
||||
exit "$fetch_status"
|
||||
fi
|
||||
|
||||
retry_status=0
|
||||
run_wave after-fetch || retry_status=$?
|
||||
if [[ "$retry_status" -ne 0 ]]; then
|
||||
echo "[production-deps] RETRY FAIL exit_code=${retry_status} initial_exit_code=${initial_status}" >&2
|
||||
exit "$retry_status"
|
||||
fi
|
||||
|
||||
echo "[production-deps] READY source=refreshed-store initial_exit_code=${initial_status}" >&2
|
||||
@@ -0,0 +1,266 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck source=scripts/lib/docker-runtime-smoke.sh
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)/docker-runtime-smoke.sh"
|
||||
|
||||
TARGET="${1:-all}"
|
||||
DOCKER_SMOKE_RUN_ID="${DOCKER_SMOKE_RUN_ID:-local-$$}"
|
||||
DOCKER_SMOKE_REVISION="${DOCKER_SMOKE_REVISION:-}"
|
||||
DOCKER_SMOKE_BUILD_TIMEOUT_SECONDS="${DOCKER_SMOKE_BUILD_TIMEOUT_SECONDS:-1200}"
|
||||
DOCKER_SMOKE_WEB_RUNTIME_TIMEOUT_SECONDS="${DOCKER_SMOKE_WEB_RUNTIME_TIMEOUT_SECONDS:-720}"
|
||||
DOCKER_SMOKE_SERVICE_RUNTIME_TIMEOUT_SECONDS="${DOCKER_SMOKE_SERVICE_RUNTIME_TIMEOUT_SECONDS:-420}"
|
||||
DOCKER_SMOKE_ARTIFACT_TIMEOUT_SECONDS="${DOCKER_SMOKE_ARTIFACT_TIMEOUT_SECONDS:-60}"
|
||||
DOCKER_SMOKE_COMPOSE_TIMEOUT_SECONDS="${DOCKER_SMOKE_COMPOSE_TIMEOUT_SECONDS:-60}"
|
||||
DOCKER_SMOKE_RUNTIME_GRACE_SECONDS="${DOCKER_SMOKE_RUNTIME_GRACE_SECONDS:-30}"
|
||||
|
||||
if [[ -z "$DOCKER_SMOKE_RUN_ID" || ${#DOCKER_SMOKE_RUN_ID} -gt 80 || ! "$DOCKER_SMOKE_RUN_ID" =~ ^[A-Za-z0-9_.-]+$ ]]; then
|
||||
echo "DOCKER_SMOKE_RUN_ID must contain 1-80 Docker-safe characters" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ ! "$DOCKER_SMOKE_REVISION" =~ ^[0-9a-fA-F]{40}$ ]]; then
|
||||
echo "DOCKER_SMOKE_REVISION must be a concrete 40-character Git SHA" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
case "$TARGET" in
|
||||
all | web | worker | api | mcp | hocuspocus | portal-domain-controller) ;;
|
||||
*)
|
||||
echo "Docker smoke target must be one of: all, web, worker, api, mcp, hocuspocus, portal-domain-controller" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
WEB_IMAGE="hivegrid-web:smoke-${DOCKER_SMOKE_RUN_ID}"
|
||||
WORKER_IMAGE="hivegrid-worker:smoke-${DOCKER_SMOKE_RUN_ID}"
|
||||
API_IMAGE="hivegrid-api:smoke-${DOCKER_SMOKE_RUN_ID}"
|
||||
MCP_IMAGE="hivegrid-mcp:smoke-${DOCKER_SMOKE_RUN_ID}"
|
||||
HOCUSPOCUS_IMAGE="hivegrid-hocuspocus:smoke-${DOCKER_SMOKE_RUN_ID}"
|
||||
PORTAL_CONTROLLER_IMAGE="hivegrid-portal-domain-controller:smoke-${DOCKER_SMOKE_RUN_ID}"
|
||||
WEB_ARTIFACT_CONTAINER_NAME="hivegrid-web-artifact-smoke-${DOCKER_SMOKE_RUN_ID}"
|
||||
|
||||
export DOCKER_SMOKE_RUN_ID
|
||||
export DOCKER_SMOKE_REVISION
|
||||
export DOCKER_SMOKE_MIGRATOR_IMAGE="$WEB_IMAGE"
|
||||
export DOCKER_WEB_SMOKE_TRANSPORT="${DOCKER_WEB_SMOKE_TRANSPORT:-exec}"
|
||||
export DOCKER_API_SMOKE_TRANSPORT="${DOCKER_API_SMOKE_TRANSPORT:-exec}"
|
||||
export DOCKER_MCP_SMOKE_TRANSPORT="${DOCKER_MCP_SMOKE_TRANSPORT:-exec}"
|
||||
export DOCKER_PORTAL_DOMAIN_CONTROLLER_SMOKE_REVISION="$DOCKER_SMOKE_REVISION"
|
||||
|
||||
cleanup() {
|
||||
docker_smoke_cleanup_container "suite:cleanup:web-artifact" "$WEB_ARTIFACT_CONTAINER_NAME"
|
||||
}
|
||||
|
||||
docker_smoke_install_cleanup_traps cleanup
|
||||
cleanup
|
||||
|
||||
run_parallel_wave() {
|
||||
local wave="$1"
|
||||
local task
|
||||
local index
|
||||
local child_status
|
||||
local status=0
|
||||
local -a tasks=()
|
||||
local -a pids=()
|
||||
shift
|
||||
|
||||
if [[ "$#" -eq 0 ]]; then
|
||||
echo "[docker-smoke] FAIL stage=wave:${wave} reason=no_tasks exit_code=2" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
echo "[docker-smoke] WAVE_START wave=${wave} tasks=$#" >&2
|
||||
for task in "$@"; do
|
||||
tasks+=("$task")
|
||||
"$task" &
|
||||
pids+=("$!")
|
||||
done
|
||||
|
||||
for index in "${!pids[@]}"; do
|
||||
if wait "${pids[$index]}"; then
|
||||
echo "[docker-smoke] WAVE_PASS wave=${wave} task=${tasks[$index]}" >&2
|
||||
continue
|
||||
else
|
||||
child_status=$?
|
||||
fi
|
||||
|
||||
echo "[docker-smoke] WAVE_FAIL wave=${wave} task=${tasks[$index]} exit_code=${child_status}" >&2
|
||||
if [[ "$status" -eq 0 ]]; then
|
||||
status="$child_status"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$status" -ne 0 ]]; then
|
||||
return "$status"
|
||||
fi
|
||||
echo "[docker-smoke] WAVE_PASS wave=${wave} tasks=${#tasks[@]}" >&2
|
||||
}
|
||||
|
||||
build_root_target() {
|
||||
local target="$1"
|
||||
local image="$2"
|
||||
local build_args
|
||||
|
||||
build_args=(
|
||||
docker build
|
||||
--target "$target"
|
||||
--build-arg "APP_REVISION=${DOCKER_SMOKE_REVISION}"
|
||||
)
|
||||
if [[ "$target" == "web" ]]; then
|
||||
build_args+=(--build-arg VITE_HOCUSPOCUS_URL=wss://collab.invalid)
|
||||
fi
|
||||
build_args+=(--tag "$image" .)
|
||||
|
||||
docker_smoke_run "build:${target}" "$DOCKER_SMOKE_BUILD_TIMEOUT_SECONDS" "${build_args[@]}"
|
||||
}
|
||||
|
||||
build_hocuspocus() {
|
||||
docker_smoke_run "build:hocuspocus" "$DOCKER_SMOKE_BUILD_TIMEOUT_SECONDS" \
|
||||
docker build \
|
||||
--file apps/hocuspocus/Dockerfile \
|
||||
--target hocuspocus \
|
||||
--build-arg "APP_REVISION=${DOCKER_SMOKE_REVISION}" \
|
||||
--tag "$HOCUSPOCUS_IMAGE" \
|
||||
.
|
||||
}
|
||||
|
||||
image_matches_revision() {
|
||||
local image="$1"
|
||||
local actual_revision=""
|
||||
|
||||
if ! docker_smoke_capture actual_revision "image:inspect" "$DOCKER_SMOKE_PROBE_TIMEOUT_SECONDS" \
|
||||
docker image inspect -f '{{ index .Config.Labels "org.opencontainers.image.revision" }}' "$image"; then
|
||||
return 1
|
||||
fi
|
||||
[[ "$actual_revision" == "$DOCKER_SMOKE_REVISION" ]]
|
||||
}
|
||||
|
||||
ensure_web_migrator_image() {
|
||||
if image_matches_revision "$WEB_IMAGE"; then
|
||||
echo "[docker-smoke] REUSE stage=image:web revision=${DOCKER_SMOKE_REVISION}" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
build_root_target web "$WEB_IMAGE"
|
||||
}
|
||||
|
||||
validate_web() {
|
||||
docker_smoke_run "artifacts:web" "$DOCKER_SMOKE_ARTIFACT_TIMEOUT_SECONDS" \
|
||||
docker run --rm --name "$WEB_ARTIFACT_CONTAINER_NAME" --entrypoint /bin/sh "$WEB_IMAGE" -lc \
|
||||
'test -f /myapp/apps/web/build/server/index.js && test -d /myapp/apps/web/build/client && test -f /myapp/apps/web/build-portal/server/index.js && test -d /myapp/apps/web/build-portal/client && test -f /myapp/build/server-runtime/server.js'
|
||||
docker_smoke_run_with_grace "runtime:web" "$DOCKER_SMOKE_WEB_RUNTIME_TIMEOUT_SECONDS" "$DOCKER_SMOKE_RUNTIME_GRACE_SECONDS" \
|
||||
bash scripts/docker-web-runtime-smoke.sh "$WEB_IMAGE"
|
||||
}
|
||||
|
||||
build_web() {
|
||||
build_root_target web "$WEB_IMAGE"
|
||||
}
|
||||
|
||||
build_worker() {
|
||||
build_root_target worker "$WORKER_IMAGE"
|
||||
}
|
||||
|
||||
validate_worker() {
|
||||
docker_smoke_run_with_grace "runtime:worker" "$DOCKER_SMOKE_SERVICE_RUNTIME_TIMEOUT_SECONDS" "$DOCKER_SMOKE_RUNTIME_GRACE_SECONDS" \
|
||||
bash scripts/docker-worker-runtime-smoke.sh "$WORKER_IMAGE"
|
||||
}
|
||||
|
||||
build_and_validate_worker() {
|
||||
build_worker
|
||||
validate_worker
|
||||
}
|
||||
|
||||
build_api() {
|
||||
build_root_target api "$API_IMAGE"
|
||||
}
|
||||
|
||||
validate_api() {
|
||||
docker_smoke_run_with_grace "runtime:api" "$DOCKER_SMOKE_SERVICE_RUNTIME_TIMEOUT_SECONDS" "$DOCKER_SMOKE_RUNTIME_GRACE_SECONDS" \
|
||||
bash scripts/docker-api-runtime-smoke.sh "$API_IMAGE"
|
||||
}
|
||||
|
||||
build_and_validate_api() {
|
||||
build_api
|
||||
validate_api
|
||||
}
|
||||
|
||||
build_mcp() {
|
||||
build_root_target mcp "$MCP_IMAGE"
|
||||
}
|
||||
|
||||
validate_mcp() {
|
||||
docker_smoke_run_with_grace "runtime:mcp" "$DOCKER_SMOKE_SERVICE_RUNTIME_TIMEOUT_SECONDS" "$DOCKER_SMOKE_RUNTIME_GRACE_SECONDS" \
|
||||
bash scripts/docker-mcp-runtime-smoke.sh "$MCP_IMAGE"
|
||||
}
|
||||
|
||||
build_and_validate_mcp() {
|
||||
build_mcp
|
||||
validate_mcp
|
||||
}
|
||||
|
||||
validate_hocuspocus() {
|
||||
docker_smoke_run_with_grace "runtime:hocuspocus" "$DOCKER_SMOKE_SERVICE_RUNTIME_TIMEOUT_SECONDS" "$DOCKER_SMOKE_RUNTIME_GRACE_SECONDS" \
|
||||
bash scripts/docker-hocuspocus-runtime-smoke.sh "$HOCUSPOCUS_IMAGE"
|
||||
}
|
||||
|
||||
build_and_validate_hocuspocus() {
|
||||
build_hocuspocus
|
||||
validate_hocuspocus
|
||||
}
|
||||
|
||||
build_portal_controller() {
|
||||
build_root_target portal-domain-controller "$PORTAL_CONTROLLER_IMAGE"
|
||||
}
|
||||
|
||||
validate_portal_controller() {
|
||||
docker_smoke_run_with_grace "runtime:portal-domain-controller" "$DOCKER_SMOKE_SERVICE_RUNTIME_TIMEOUT_SECONDS" "$DOCKER_SMOKE_RUNTIME_GRACE_SECONDS" \
|
||||
bash scripts/docker-portal-domain-controller-runtime-smoke.sh "$PORTAL_CONTROLLER_IMAGE"
|
||||
}
|
||||
|
||||
build_and_validate_portal_controller() {
|
||||
build_portal_controller
|
||||
validate_portal_controller
|
||||
}
|
||||
|
||||
# Validate interpolation against a committed non-secret fixture. `--quiet`
|
||||
# prevents Compose from echoing resolved developer or CI credentials.
|
||||
docker_smoke_run "compose:config" "$DOCKER_SMOKE_COMPOSE_TIMEOUT_SECONDS" \
|
||||
docker compose --env-file .env.test config --quiet
|
||||
|
||||
case "$TARGET" in
|
||||
all)
|
||||
# All images are complete before any service consumes the web migrator image.
|
||||
run_parallel_wave builds \
|
||||
build_web build_worker build_api build_mcp build_hocuspocus build_portal_controller
|
||||
# Runtime resources are service- and run-scoped; their databases and Redis instances
|
||||
# intentionally remain isolated while the six unchanged validations run concurrently.
|
||||
run_parallel_wave runtimes \
|
||||
validate_web validate_worker validate_api validate_mcp validate_hocuspocus validate_portal_controller
|
||||
;;
|
||||
web)
|
||||
build_web
|
||||
validate_web
|
||||
;;
|
||||
worker)
|
||||
ensure_web_migrator_image
|
||||
build_and_validate_worker
|
||||
;;
|
||||
api)
|
||||
ensure_web_migrator_image
|
||||
build_and_validate_api
|
||||
;;
|
||||
mcp)
|
||||
ensure_web_migrator_image
|
||||
build_and_validate_mcp
|
||||
;;
|
||||
hocuspocus)
|
||||
ensure_web_migrator_image
|
||||
build_and_validate_hocuspocus
|
||||
;;
|
||||
portal-domain-controller)
|
||||
build_and_validate_portal_controller
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Docker smoke suite passed for target=${TARGET} revision=${DOCKER_SMOKE_REVISION} run=${DOCKER_SMOKE_RUN_ID}"
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Gitea's act runner does not preserve setup-node's GITHUB_PATH update between
|
||||
# steps. Link the downloaded, version-pinned runtime into a stable PATH entry so
|
||||
# later Node.js, Corepack, and pnpm steps cannot fall back to the runner image.
|
||||
node_version="$(tr -d '[:space:]' < .nvmrc)"
|
||||
node_version="${node_version#v}"
|
||||
tool_cache="${RUNNER_TOOL_CACHE:-/opt/hostedtoolcache}"
|
||||
install_directory="${HIVEGRID_CI_TOOL_BIN:-/usr/local/bin}"
|
||||
node_binary="$(find "$tool_cache/node/$node_version" -type f -path '*/bin/node' -perm -u+x -print -quit 2>/dev/null || true)"
|
||||
|
||||
if [[ -z "$node_binary" ]]; then
|
||||
echo "setup-node runtime $node_version was not found below $tool_cache/node" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
node_bin_directory="$(dirname "$node_binary")"
|
||||
corepack_binary="$node_bin_directory/corepack"
|
||||
if [[ ! -x "$corepack_binary" ]]; then
|
||||
echo "Corepack is missing beside setup-node runtime $node_binary" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -d "$install_directory" || ! -w "$install_directory" ]]; then
|
||||
echo "Persistent tool directory $install_directory is not writable" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ln -sfn "$node_binary" "$install_directory/node"
|
||||
ln -sfn "$corepack_binary" "$install_directory/corepack"
|
||||
|
||||
actual_version="$("$install_directory/node" --version)"
|
||||
if [[ "$actual_version" != "v$node_version" ]]; then
|
||||
echo "Persistent Node.js runtime mismatch: expected v$node_version, got $actual_version" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Persisted Node.js $actual_version and Corepack in $install_directory"
|
||||
@@ -0,0 +1,66 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import { afterEach, describe, it } from "vitest";
|
||||
|
||||
const scriptPath = path.resolve("scripts/ci/persist-node-toolchain.sh");
|
||||
const temporaryDirectories = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const directory of temporaryDirectories.splice(0)) {
|
||||
fs.rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
function createFixture({ reportedVersion = "v24.18.0", includeCorepack = true } = {}) {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "hivegrid-node-toolchain-"));
|
||||
temporaryDirectories.push(root);
|
||||
const toolCache = path.join(root, "toolcache");
|
||||
const toolBin = path.join(root, "persistent-bin");
|
||||
const downloadedBin = path.join(toolCache, "node", "24.18.0", "x64", "bin");
|
||||
fs.mkdirSync(downloadedBin, { recursive: true });
|
||||
fs.mkdirSync(toolBin, { recursive: true });
|
||||
fs.writeFileSync(path.join(root, ".nvmrc"), "v24.18.0\n");
|
||||
fs.writeFileSync(path.join(downloadedBin, "node"), `#!/bin/sh\nprintf '%s\\n' '${reportedVersion}'\n`, { mode: 0o755 });
|
||||
if (includeCorepack) {
|
||||
fs.writeFileSync(path.join(downloadedBin, "corepack"), "#!/bin/sh\nexit 0\n", { mode: 0o755 });
|
||||
}
|
||||
return { root, toolCache, toolBin, downloadedBin };
|
||||
}
|
||||
|
||||
function environment(fixture) {
|
||||
return {
|
||||
...process.env,
|
||||
RUNNER_TOOL_CACHE: fixture.toolCache,
|
||||
HIVEGRID_CI_TOOL_BIN: fixture.toolBin,
|
||||
};
|
||||
}
|
||||
|
||||
describe("persist-node-toolchain", () => {
|
||||
it("links setup-node's pinned runtime into a stable tool directory", () => {
|
||||
const fixture = createFixture();
|
||||
|
||||
execFileSync("bash", [scriptPath], { cwd: fixture.root, env: environment(fixture) });
|
||||
|
||||
assert.equal(fs.realpathSync(path.join(fixture.toolBin, "node")), fs.realpathSync(path.join(fixture.downloadedBin, "node")));
|
||||
assert.equal(fs.realpathSync(path.join(fixture.toolBin, "corepack")), fs.realpathSync(path.join(fixture.downloadedBin, "corepack")));
|
||||
});
|
||||
|
||||
it("fails closed when Corepack is absent from the downloaded runtime", () => {
|
||||
const fixture = createFixture({ includeCorepack: false });
|
||||
const result = spawnSync("bash", [scriptPath], { cwd: fixture.root, env: environment(fixture), encoding: "utf8" });
|
||||
|
||||
assert.equal(result.status, 1);
|
||||
assert.match(result.stderr, /Corepack is missing/);
|
||||
});
|
||||
|
||||
it("fails closed when the persisted runtime does not match .nvmrc", () => {
|
||||
const fixture = createFixture({ reportedVersion: "v24.17.0" });
|
||||
const result = spawnSync("bash", [scriptPath], { cwd: fixture.root, env: environment(fixture), encoding: "utf8" });
|
||||
|
||||
assert.equal(result.status, 1);
|
||||
assert.match(result.stderr, /runtime mismatch/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd -- "$SCRIPT_DIR/../.." && pwd)"
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
if [[ ! -f package.json || ! -d apps || ! -d packages || ! -d prisma ]]; then
|
||||
echo "[quality-groups] repository workspace is incomplete" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Web typechecking normally generates the tracked Prisma client. Complete that
|
||||
# single writer before any Vitest reader starts, then run the remaining
|
||||
# typecheck commands explicitly inside the parallel group below.
|
||||
echo "[quality-groups] PREPARE prisma-client"
|
||||
pnpm run db:generate
|
||||
echo "[quality-groups] READY prisma-client"
|
||||
|
||||
run_typecheck_lint() {
|
||||
pnpm --filter @hivegrid/portal-domain-controller typecheck
|
||||
pnpm --filter @hivegrid/web typegen
|
||||
(
|
||||
cd apps/web
|
||||
node ../../scripts/typecheck-web.mjs
|
||||
)
|
||||
pnpm lint
|
||||
}
|
||||
|
||||
run_foundation_packages() {
|
||||
# The CI host also builds six Docker targets in parallel. Bound both the
|
||||
# Vitest pool and pnpm's recursive package fan-out so this job cannot starve
|
||||
# BuildKit (or push the shared runner back into swap) while retaining the
|
||||
# three-way overlap with typecheck/lint and the core suite.
|
||||
pnpm run test:foundation --maxWorkers=2
|
||||
PNPM_CONFIG_WORKSPACE_CONCURRENCY=2 pnpm run test:packages --maxWorkers=1
|
||||
}
|
||||
|
||||
run_core_tests() {
|
||||
pnpm run test --maxWorkers=4
|
||||
}
|
||||
|
||||
declare -a QUALITY_GROUP_NAMES=()
|
||||
declare -a QUALITY_GROUP_PIDS=()
|
||||
|
||||
start_group() {
|
||||
local name="$1"
|
||||
local function_name="$2"
|
||||
(
|
||||
set -euo pipefail
|
||||
echo "[quality-groups] START $name"
|
||||
"$function_name"
|
||||
) &
|
||||
QUALITY_GROUP_NAMES+=("$name")
|
||||
QUALITY_GROUP_PIDS+=("$!")
|
||||
}
|
||||
|
||||
terminate_groups() {
|
||||
trap - HUP INT TERM
|
||||
for pid in "${QUALITY_GROUP_PIDS[@]:-}"; do
|
||||
kill -TERM "$pid" 2>/dev/null || true
|
||||
done
|
||||
for pid in "${QUALITY_GROUP_PIDS[@]:-}"; do
|
||||
wait "$pid" 2>/dev/null || true
|
||||
done
|
||||
echo "[quality-groups] interrupted; child groups terminated" >&2
|
||||
exit 130
|
||||
}
|
||||
|
||||
trap terminate_groups HUP INT TERM
|
||||
|
||||
start_group "typecheck-lint" run_typecheck_lint
|
||||
start_group "foundation-packages" run_foundation_packages
|
||||
start_group "core-tests" run_core_tests
|
||||
|
||||
QUALITY_FAILED=0
|
||||
for index in "${!QUALITY_GROUP_PIDS[@]}"; do
|
||||
name="${QUALITY_GROUP_NAMES[$index]}"
|
||||
pid="${QUALITY_GROUP_PIDS[$index]}"
|
||||
if wait "$pid"; then
|
||||
echo "[quality-groups] PASS $name"
|
||||
else
|
||||
status=$?
|
||||
echo "[quality-groups] FAIL $name (exit $status)" >&2
|
||||
QUALITY_FAILED=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$QUALITY_FAILED" -ne 0 ]]; then
|
||||
echo "[quality-groups] one or more groups failed" >&2
|
||||
exit "$QUALITY_FAILED"
|
||||
fi
|
||||
|
||||
echo "[quality-groups] PASS all groups"
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env node
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
function stripComment(line) {
|
||||
let quote = "";
|
||||
let escaped = false;
|
||||
for (let index = 0; index < line.length; index += 1) {
|
||||
const character = line[index];
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
continue;
|
||||
}
|
||||
if (quote === '"' && character === "\\") {
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
if (quote) {
|
||||
if (character === quote) quote = "";
|
||||
continue;
|
||||
}
|
||||
if (character === '"' || character === "'") {
|
||||
quote = character;
|
||||
continue;
|
||||
}
|
||||
if (character === "#") return line.slice(0, index);
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
function normalizeValue(rawValue) {
|
||||
const value = rawValue.trim();
|
||||
if (value.length >= 2 && ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")))) {
|
||||
return value.slice(1, -1);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function parseBuildkitToml(content) {
|
||||
const sections = new Map();
|
||||
let currentSection = "";
|
||||
|
||||
for (const rawLine of content.split(/\r?\n/)) {
|
||||
const line = stripComment(rawLine).trim();
|
||||
if (!line) continue;
|
||||
|
||||
const sectionMatch = line.match(/^\[([^\]]+)\]$/);
|
||||
if (sectionMatch) {
|
||||
currentSection = sectionMatch[1];
|
||||
if (sections.has(currentSection)) throw new Error(`duplicate section ${currentSection}`);
|
||||
sections.set(currentSection, new Map());
|
||||
continue;
|
||||
}
|
||||
|
||||
const assignment = line.match(/^([A-Za-z0-9_-]+)\s*=\s*(.+)$/);
|
||||
if (!assignment || !currentSection) throw new Error("unsupported deploy BuildKit TOML syntax");
|
||||
const values = sections.get(currentSection);
|
||||
if (values.has(assignment[1])) throw new Error(`duplicate key ${currentSection}.${assignment[1]}`);
|
||||
values.set(assignment[1], normalizeValue(assignment[2]));
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
export function verifyLoadedBuildkitConfig(expectedContent, actualContent) {
|
||||
try {
|
||||
const expected = parseBuildkitToml(expectedContent);
|
||||
const actual = parseBuildkitToml(actualContent);
|
||||
|
||||
for (const [section, expectedValues] of expected) {
|
||||
const actualValues = actual.get(section);
|
||||
if (!actualValues || actualValues.size !== expectedValues.size) return false;
|
||||
for (const [key, expectedValue] of expectedValues) {
|
||||
if (actualValues.get(key) !== expectedValue) return false;
|
||||
}
|
||||
}
|
||||
for (const [section, actualValues] of actual) {
|
||||
if (!expected.has(section) && !(section === "worker" && actualValues.size === 0)) return false;
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const expectedPath = process.argv[2];
|
||||
if (!expectedPath) {
|
||||
console.error("Expected deploy BuildKit config path is required");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const expectedContent = fs.readFileSync(path.resolve(expectedPath), "utf8");
|
||||
const actualContent = fs.readFileSync(0, "utf8");
|
||||
if (!verifyLoadedBuildkitConfig(expectedContent, actualContent)) {
|
||||
console.error("Running deploy BuildKit configuration does not match the reviewed repository config");
|
||||
process.exit(1);
|
||||
}
|
||||
console.log("Running deploy BuildKit configuration matches the reviewed repository config");
|
||||
}
|
||||
|
||||
if (path.resolve(process.argv[1] ?? "") === fileURLToPath(import.meta.url)) main();
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseBuildkitToml, verifyLoadedBuildkitConfig } from "./verify-deploy-buildkit-config.mjs";
|
||||
|
||||
const expected = `[history]
|
||||
maxAge = 86400
|
||||
maxEntries = 20
|
||||
|
||||
[worker.oci]
|
||||
gc = true
|
||||
reservedSpace = "2GB"
|
||||
maxUsedSpace = "30GB"
|
||||
minFreeSpace = "100GB"
|
||||
max-parallelism = 12
|
||||
`;
|
||||
|
||||
describe("verify-deploy-buildkit-config", () => {
|
||||
it("accepts Buildx-normalized ordering, quotes, and its empty parent section", () => {
|
||||
const actual = `[history]
|
||||
maxEntries = 20
|
||||
maxAge = 86400
|
||||
|
||||
[worker]
|
||||
[worker.oci]
|
||||
minFreeSpace = '100GB'
|
||||
gc = true
|
||||
maxUsedSpace = '30GB'
|
||||
reservedSpace = '2GB'
|
||||
max-parallelism = 12
|
||||
`;
|
||||
|
||||
expect(verifyLoadedBuildkitConfig(expected, actual)).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects a changed history bound", () => {
|
||||
expect(verifyLoadedBuildkitConfig(expected, expected.replace("maxEntries = 20", "maxEntries = 2000"))).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects a missing OCI cache bound", () => {
|
||||
expect(verifyLoadedBuildkitConfig(expected, expected.replace(' maxUsedSpace = "30GB"\n', ""))).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects an extra setting in a reviewed section", () => {
|
||||
expect(verifyLoadedBuildkitConfig(expected, expected.replace(" gc = true", " gc = true\n debug = true"))).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects an unexpected non-empty section", () => {
|
||||
expect(verifyLoadedBuildkitConfig(expected, `${expected}\n[registry.\"unsafe.example\"]\n insecure = true\n`)).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects duplicate keys instead of silently selecting one", () => {
|
||||
expect(() => parseBuildkitToml(expected.replace(" maxEntries = 20", " maxEntries = 20\n maxEntries = 21"))).toThrow("duplicate key history.maxEntries");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user