File size: 1,505 Bytes
d736cc9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # ---- Stage 1: Build ----
# Mirrors BRIDGE Modul-E's proven HF pattern (node:20-alpine).
FROM node:20-alpine AS builder
WORKDIR /app
# Vite bakes VITE_* vars in at BUILD time — pass them as build args.
# Empty values keep the demo fallback UI.
ARG VITE_SUPABASE_URL=""
ARG VITE_SUPABASE_ANON_KEY=""
ARG VITE_API_URL=""
ENV VITE_SUPABASE_URL=$VITE_SUPABASE_URL \
VITE_SUPABASE_ANON_KEY=$VITE_SUPABASE_ANON_KEY \
VITE_API_URL=$VITE_API_URL
# Install dependencies first (layer caching).
# NOTE: only package.json is copied (no lockfile): the Windows-generated
# lockfile pins win32-only optional native deps (rollup) which break Linux
# builds — npm/cli bug #4828. Dependencies resolve fresh on Alpine/musl.
COPY package.json ./
RUN npm install --no-audit --no-fund
# Copy source and build frontend + bundle server (dist/server.cjs).
COPY . .
RUN npm run build
# ---- Stage 2: Production ----
FROM node:20-alpine AS production
WORKDIR /app
# HF Spaces routes to 7860 — the server MUST default to it (see server.ts).
ENV NODE_ENV=production \
PORT=7860
# Install production-only dependencies (esbuild, vitest, typescript excluded).
COPY package.json ./
RUN npm install --omit=dev && npm cache clean --force
# Copy the built output from builder stage.
COPY --from=builder /app/dist ./dist
EXPOSE 7860
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget -qO- http://127.0.0.1:7860/api/health >/dev/null 2>&1 || exit 1
CMD ["node", "dist/server.cjs"]
|