Files
MIKROTIK-RMM/scripts/ci-preflight.sh
T
2GT-RichandClaude Opus 5 273a0da737 fix(deploy): restore NetFlow to the published compose file, and generate it (v0.23.34-beta)
Closes #121.

The Quick Deploy file was missing NETFLOW_BIND_PORT and the 2055/udp mapping, so
the collector bound inside the container and nothing reached it. NetFlow did
nothing, silently, with an empty traffic page and no error — for everyone
following the path the README tells new users to take.

The report was accurate and understated. docker-compose.ghcr.yml had drifted for
seven weeks, and three closed issues had never reached it:

  * NETFLOW_BIND_PORT and the UDP port — as reported
  * all five POLLER_* tunables — #114, whose fix was "pass the tunables through"
  * the Redis memory ceiling and eviction policy — #116
  * TZ on the postgres service, which nobody had noticed at all

The middle one is the uncomfortable part. Four days ago #114 was closed by
forwarding poller settings that were documented but inert, with a comment saying
setting them "did precisely nothing". On Quick Deploy that remained true, because
one compose file was fixed and the other was not — including the advice given to
that reporter about which knob to turn.

So patching the four gaps would have been treating the symptom. The two files
describe the same system and differ only in where images come from; maintaining
both by hand meant remembering every change twice, and the one forgotten was
always the file no maintainer runs.

docker-compose.ghcr.yml is now generated from docker-compose.yml by
scripts/generate-ghcr-compose.mjs, which performs the two build-to-image swaps
and nothing else. Substitution is textual rather than parse-and-reserialise so
comments survive — the reasoning about Redis eviction is worth more than the two
lines it explains. The file stays committed and browsable, because the README
tells people to curl it directly.

A --check mode runs as the first preflight gate and as its own CI job, both of
which fail when the committed file does not match what the generator produces.
Verified by deleting the NetFlow line and watching the guard reject it, with the
reason and the fix in the failure message.

Reported by @mamb1329, on their first issue.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 13:08:56 -07:00

70 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run the same gates GitHub Actions runs, locally, before pushing.
#
# Mirrors .github/workflows/ci.yml exactly (frontend lint/type-check/build,
# backend lint/type-check/build, prod-dependency audits) and additionally runs
# the backend Jest suite, which CI does not currently cover.
#
# Usage: scripts/ci-preflight.sh [--skip-audit]
# Exit: 0 = everything CI checks would pass, 1 = at least one gate failed.
#
# Runs every gate rather than failing fast, so one invocation surfaces all
# problems instead of dribbling them out one push at a time.
set -uo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SKIP_AUDIT=0
[[ "${1:-}" == "--skip-audit" ]] && SKIP_AUDIT=1
FAILED=()
run() {
local label="$1" dir="$2"; shift 2
printf ' %-34s' "$label"
if (cd "$ROOT/$dir" && "$@") >/tmp/ci-preflight-out 2>&1; then
echo "ok"
else
echo "FAIL"
FAILED+=("$label")
# Keep a trimmed excerpt so the caller can see why without re-running.
{
echo "----- $label -----"
tail -25 /tmp/ci-preflight-out
echo
} >>/tmp/ci-preflight-failures
fi
}
: >/tmp/ci-preflight-failures
echo "Running CI gates locally (mirrors .github/workflows/ci.yml)"
# The published deployment file is generated. Checking it first because it costs
# nothing and because drift here is invisible to every maintainer — it only ever
# breaks the Quick Deploy path that no one on the team runs (#121).
run "compose: ghcr in sync" . node scripts/generate-ghcr-compose.mjs --check
run "backend: lint" backend npm run lint
run "backend: type-check" backend npx tsc --noEmit
run "backend: build" backend npm run build
run "backend: tests" backend npx jest --silent
run "frontend: lint" frontend npm run lint
run "frontend: type-check" frontend npx tsc --noEmit
run "frontend: build" frontend npm run build
if [[ $SKIP_AUDIT -eq 0 ]]; then
run "frontend: audit (prod)" frontend \
npx --yes audit-ci@^7 --high --skip-dev --allowlist GHSA-qwww-vcr4-c8h2
run "backend: audit (prod)" backend \
npx --yes audit-ci@^7 --high --skip-dev
fi
if [[ ${#FAILED[@]} -eq 0 ]]; then
echo "All CI gates passed."
exit 0
fi
echo
echo "FAILED: ${FAILED[*]}"
echo "Details in /tmp/ci-preflight-failures"
exit 1