FROM node:18-slim RUN apt-get update \ && apt-get install -y --no-install-recommends \ git \ ca-certificates \ wget \ && rm -rf /var/lib/apt/lists/* WORKDIR /app ARG BRANCH=Final_Deployment # ✅ Automatic cache-buster tied to branch HEAD ADD https://api.github.com/repos/YoussefElshaarawy/Pulse_Platform/commits?sha=${BRANCH}&per_page=1 /tmp/branch_head.json RUN rm -rf /app/* RUN git clone --depth 1 --branch ${BRANCH} \ https://github.com/YoussefElshaarawy/Pulse_Platform.git . \ && rm -rf .git RUN npm ci RUN npm run build # ✅ Create a tiny patch script (no escaping problems) RUN cat > /tmp/patch-dist.js <<'JS' const fs = require("fs"); const id = String(Date.now()); const stamp = `BUILD_ID=${id}\nUTC=${new Date().toISOString()}\n`; if (!fs.existsSync("dist")) { console.error("Missing dist/ directory"); process.exit(1); } fs.writeFileSync("dist/__build.txt", stamp, "utf8"); const indexPath = "dist/index.html"; if (!fs.existsSync(indexPath)) { console.error("Missing dist/index.html"); process.exit(1); } let h = fs.readFileSync(indexPath, "utf8"); // Replace both variants safely h = h.replaceAll('src="./Pulse.html"', `src="/Pulse.html?v=${id}"`); h = h.replaceAll('src="/Pulse.html"', `src="/Pulse.html?v=${id}"`); // Add a visible comment stamp at top h = `\n` + h; fs.writeFileSync(indexPath, h, "utf8"); console.log("Patched index.html iframe to:", `/Pulse.html?v=${id}`); JS # ✅ Run the patch script RUN node /tmp/patch-dist.js RUN npm install -g serve # ✅ Debug RUN echo "=== build stamp ===" && cat dist/__build.txt RUN echo "=== iframe line ===" && grep -n "Pulse.html" dist/index.html || true RUN echo "=== HTML files in dist ===" && find dist -maxdepth 2 -type f -iname "*.html" -print ENV PORT=7860 EXPOSE 7860 CMD ["sh", "-c", "serve dist -l tcp://0.0.0.0:${PORT:-7860}"]