From 2948cb62d222c2ff445f3f4080184e4d053c87d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Thu, 18 Dec 2025 14:05:59 +0100 Subject: [PATCH] fix: docker image and control plane standalone build --- .github/workflows/test.yml | 17 +++++++++++++++++ docker/standalone/Dockerfile | 17 +++++++++++++---- hindsight-control-plane/package.json | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ef01eef4..a48c7f3a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -113,8 +113,25 @@ jobs: - name: Verify standalone build run: | test -f hindsight-control-plane/standalone/server.js || exit 1 + test -d hindsight-control-plane/standalone/node_modules || exit 1 node hindsight-control-plane/bin/cli.js --help + - name: Smoke test - verify server starts + run: | + cd hindsight-control-plane + node bin/cli.js --port 9999 & + SERVER_PID=$! + sleep 5 + if curl -sf http://localhost:9999 > /dev/null 2>&1; then + echo "Server started successfully" + kill $SERVER_PID 2>/dev/null || true + exit 0 + else + echo "Server failed to respond" + kill $SERVER_PID 2>/dev/null || true + exit 1 + fi + build-docs: runs-on: ubuntu-latest diff --git a/docker/standalone/Dockerfile b/docker/standalone/Dockerfile index 54d9d67a..c655343f 100644 --- a/docker/standalone/Dockerfile +++ b/docker/standalone/Dockerfile @@ -98,13 +98,22 @@ COPY --from=sdk-builder /app/hindsight-clients/typescript ./node_modules/@vector RUN npm exec -- next build # Create standalone directory structure manually -# Next.js standalone output structure varies, so we find server.js and work from there -RUN mkdir -p standalone/.next && \ - STANDALONE_ROOT=$(dirname $(find .next/standalone -name "server.js" | head -1)) && \ +# Note: Must exclude node_modules from find to avoid wrong server.js from next/dist/experimental/testmode/ +# Note: Must explicitly copy .next since glob * doesn't match hidden directories +RUN STANDALONE_ROOT=$(find .next/standalone -path '*/node_modules' -prune -o -name 'server.js' -print | head -1 | xargs dirname) && \ + mkdir -p standalone && \ cp -r "$STANDALONE_ROOT"/* standalone/ && \ + cp -r "$STANDALONE_ROOT"/.next standalone/.next && \ + # Copy node_modules if separate from app dir (monorepo structure) + if [ -d ".next/standalone/node_modules" ] && [ "$STANDALONE_ROOT" != ".next/standalone" ]; then \ + cp -r .next/standalone/node_modules standalone/node_modules; \ + fi && \ cp -r .next/static standalone/.next/static && \ mkdir -p standalone/public && \ - cp -r public/* standalone/public/ 2>/dev/null || true + cp -r public/* standalone/public/ 2>/dev/null || true && \ + # Verify required files exist + test -f standalone/server.js || (echo "ERROR: server.js missing!" && exit 1) && \ + test -f standalone/.next/BUILD_ID || (echo "ERROR: BUILD_ID missing!" && exit 1) # ============================================================================= # Stage: Final Image - API Only diff --git a/hindsight-control-plane/package.json b/hindsight-control-plane/package.json index 36a1cba6..f5c2fc79 100644 --- a/hindsight-control-plane/package.json +++ b/hindsight-control-plane/package.json @@ -13,7 +13,7 @@ "scripts": { "dev": "next dev", "build": "next build && npm run build:standalone", - "build:standalone": "rm -rf standalone && STANDALONE_ROOT=$(dirname $(find .next/standalone -name 'server.js' | head -1)) && cp -r \"$STANDALONE_ROOT\" standalone && mkdir -p standalone/.next && cp -r .next/static standalone/.next/static && mkdir -p standalone/public && cp -r public/* standalone/public/ 2>/dev/null || true", + "build:standalone": "rm -rf standalone && STANDALONE_ROOT=$(find .next/standalone -path '*/node_modules' -prune -o -name 'server.js' -print | head -1 | xargs dirname) && cp -r \"$STANDALONE_ROOT\" standalone && cp -r .next/standalone/node_modules standalone/node_modules && mkdir -p standalone/.next && cp -r .next/static standalone/.next/static && mkdir -p standalone/public && cp -r public/* standalone/public/ 2>/dev/null || true", "start": "next start", "lint": "next lint", "prepublishOnly": "npm run build"