fix(dashboard): public/ missing in git + add build validator #4
3
dashboard/public/.gitkeep
Normal file
3
dashboard/public/.gitkeep
Normal file
@@ -0,0 +1,3 @@
|
||||
# Static assets directory
|
||||
# Files placed here are served at the root path of the dashboard.
|
||||
# Currently empty — Next.js App Router doesn't require any static assets.
|
||||
187
dashboard/validate-build.sh
Executable file
187
dashboard/validate-build.sh
Executable file
@@ -0,0 +1,187 @@
|
||||
#!/bin/bash
|
||||
# Simulates a fresh `git clone` + `docker build` of the dashboard image,
|
||||
# WITHOUT requiring docker. Catches:
|
||||
# - COPY failures (file missing in build context)
|
||||
# - npm ci / build failures
|
||||
# - Standalone output sanity
|
||||
#
|
||||
# Run BEFORE pushing — catches the kind of issues we hit in PR #1/#2/#3
|
||||
# where the build worked locally but failed on prod because a file was
|
||||
# missing from git.
|
||||
#
|
||||
# Usage: bash dashboard/validate-build.sh # from repo root
|
||||
# or: bash validate-build.sh # from dashboard/
|
||||
# or: bash /path/to/validate-build.sh /path/to/GPU-Node
|
||||
|
||||
set -eu
|
||||
|
||||
# Auto-detect repo root: parent of this script's directory
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="${1:-$(dirname "$SCRIPT_DIR")}"
|
||||
DASH="$REPO/dashboard"
|
||||
|
||||
if [ ! -d "$DASH" ]; then
|
||||
echo "ERROR: dashboard dir not found at $DASH"
|
||||
echo "Usage: $0 [path/to/GPU-Node]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "ERROR: git is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v npm >/dev/null 2>&1; then
|
||||
echo "ERROR: npm is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TMP=$(mktemp -d)
|
||||
CTX="$TMP/build-context"
|
||||
mkdir -p "$CTX"
|
||||
|
||||
echo "==> [1/5] Listing git-tracked files in dashboard/"
|
||||
cd "$REPO"
|
||||
TRACKED=$(git ls-files dashboard/)
|
||||
echo " $(echo "$TRACKED" | wc -l) files tracked"
|
||||
|
||||
echo "==> [2/5] Simulating docker build context (git-tracked files only)"
|
||||
for f in $TRACKED; do
|
||||
rel="${f#dashboard/}"
|
||||
dest="$CTX/$rel"
|
||||
mkdir -p "$(dirname "$dest")"
|
||||
cp "$f" "$dest"
|
||||
done
|
||||
|
||||
# Apply .dockerignore: remove files matching patterns
|
||||
echo "==> [3/5] Applying .dockerignore patterns"
|
||||
cd "$CTX"
|
||||
if [ -f .dockerignore ]; then
|
||||
# Read patterns, skip comments
|
||||
while IFS= read -r line; do
|
||||
line="${line%%#*}"
|
||||
line="$(echo "$line" | xargs)"
|
||||
[ -z "$line" ] && continue
|
||||
# Skip patterns that point outside (like ../.git)
|
||||
case "$line" in
|
||||
../*) continue ;;
|
||||
esac
|
||||
# Use find to delete matches
|
||||
find . -name "$line" -type f -delete 2>/dev/null || true
|
||||
find . -name "$line" -type d -exec rm -rf {} + 2>/dev/null || true
|
||||
done < .dockerignore
|
||||
fi
|
||||
|
||||
echo "==> [4/5] Build context contents:"
|
||||
find . -type f | sort | head -30
|
||||
echo " ..."
|
||||
echo " total: $(find . -type f | wc -l) files"
|
||||
|
||||
echo "==> [5/5] Running npm ci + npm run build on build context"
|
||||
mkdir -p "$TMP/build"
|
||||
cp -r "$CTX/." "$TMP/build/"
|
||||
cd "$TMP/build"
|
||||
|
||||
# Simulate what the Dockerfile does:
|
||||
# Step 4: COPY package.json package-lock.json ./ (already done above)
|
||||
# Step 4: RUN npm ci --no-audit --no-fund
|
||||
# Step 5: RUN touch next-env.d.ts
|
||||
# Step 6: COPY tsconfig.json next.config.ts postcss.config.mjs .eslintrc.json ./
|
||||
# Step 7: COPY src ./src
|
||||
# Step 8: COPY public ./public
|
||||
# Step 9: RUN npm run build
|
||||
#
|
||||
# Validate each COPY source actually exists in build context BEFORE running
|
||||
# npm ci (so we fail fast on missing files).
|
||||
|
||||
echo "==> [5/5] Simulating Dockerfile COPY + RUN steps"
|
||||
cd "$TMP/build"
|
||||
|
||||
# Parse COPY commands from Dockerfile and verify each source exists
|
||||
echo " Validating COPY sources exist in build context..."
|
||||
MISSING=0
|
||||
while IFS= read -r line; do
|
||||
# Skip comments and blank lines
|
||||
case "$line" in
|
||||
\#*) continue ;;
|
||||
"") continue ;;
|
||||
esac
|
||||
# Only handle plain COPY (skip COPY --from=... multi-stage copies)
|
||||
case "$line" in
|
||||
"COPY "--from*) continue ;;
|
||||
COPY*) : ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
# Strip "COPY " prefix
|
||||
rest="${line#COPY}"
|
||||
# Trim leading/trailing whitespace
|
||||
rest="$(echo "$rest" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
# Split into tokens: last is destination, rest are sources
|
||||
set -- $rest
|
||||
if [ "$#" -lt 2 ]; then continue; fi
|
||||
# Last arg is destination
|
||||
n=$#
|
||||
dst="${!n}"
|
||||
# Sources are args 1..n-1
|
||||
i=1
|
||||
while [ "$i" -lt "$n" ]; do
|
||||
src="${!i}"
|
||||
i=$((i + 1))
|
||||
# Skip wildcards for simplicity (we already listed all files)
|
||||
case "$src" in
|
||||
*\**) continue ;;
|
||||
esac
|
||||
if [ ! -e "$src" ]; then
|
||||
echo " ✗ COPY source missing: $src (line: $line)"
|
||||
MISSING=$((MISSING + 1))
|
||||
else
|
||||
echo " ✓ COPY source present: $src"
|
||||
fi
|
||||
done
|
||||
done < Dockerfile
|
||||
|
||||
if [ $MISSING -gt 0 ]; then
|
||||
echo
|
||||
echo "==> ✗ $MISSING COPY source(s) missing in build context"
|
||||
echo " These will cause \`docker build\` to fail with:"
|
||||
echo " COPY failed: file not found in build context or excluded by .dockerignore"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo " All COPY sources present. Running npm ci + npm run build..."
|
||||
|
||||
# Step 5: RUN touch next-env.d.ts
|
||||
touch next-env.d.ts
|
||||
|
||||
# Step 4: npm ci --no-audit --no-fund
|
||||
npm ci --no-audit --no-fund 2>&1 | tail -5
|
||||
|
||||
# Step 8: RUN npm run build
|
||||
echo
|
||||
echo "==> Running npm run build..."
|
||||
if npm run build 2>&1 | tail -40; then
|
||||
echo
|
||||
echo "==> ✓ Build succeeded"
|
||||
if [ -f .next/standalone/server.js ]; then
|
||||
echo "==> ✓ Standalone output present"
|
||||
ls -la .next/standalone/server.js
|
||||
else
|
||||
echo "==> ✗ Standalone output MISSING"
|
||||
exit 1
|
||||
fi
|
||||
if [ -d .next/static ]; then
|
||||
echo "==> ✓ Static assets present"
|
||||
else
|
||||
echo "==> ✗ Static assets MISSING"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "==> ✗ BUILD FAILED"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "==> Cleanup: $TMP (kept for inspection)"
|
||||
echo " Build context: $CTX"
|
||||
echo " Build dir: $TMP/build"
|
||||
Reference in New Issue
Block a user