Spaces:
Running
Running
File size: 3,759 Bytes
509e21e f4514c9 34ddba0 db192b0 fe5af86 34ddba0 fe5af86 34ddba0 3435546 509e21e 3435546 a0d2087 3435546 f4514c9 3435546 f4514c9 a0d2087 509e21e f4514c9 509e21e 051fa16 509e21e da42e2e da8db3e 182e10c 509e21e 182e10c 509e21e 182e10c | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | ## Multi-stage Dockerfile for Next.js app (suitable for Hugging Face Spaces Docker runtime)
# - Builder stage installs deps and builds the Next app
# - Runner stage copies build artifacts and runs `npm run start` on $PORT (default 3000)
FROM node:18-bullseye-slim AS builder
WORKDIR /app
ARG PNPM_VERSION=10.25.0
# Build-time data-source configuration. HF Spaces "Variables" are NOT injected
# into Docker RUN steps automatically — only into the final runtime — so we
# bake the DuckDB-mode defaults here. `cache-hf-data.mjs` reads these to know
# which dataset to clone and to apply lean cache mode (skip JSON-fallback
# artifacts). Override at build time via `--build-arg HF_DATASET_REPO=...`.
ARG DATA_BACKEND=duckdb
ARG HF_DATASET_REPO=https://huggingface.co/datasets/evaleval/card_backend
# Static prerender (`next build`) executes route handlers, which call
# `getModelCards` etc. → `lib/duckdb-data.ts`, which requires
# `LOCAL_PIPELINE_OUTPUT`. The cache populated by `cache-hf-data.mjs`
# lives at `/app/.cache/hf-data`. `HF_DATA_OFFLINE=1` keeps the metadata
# fetchers (`lib/hf-data.ts`) from attempting `evaleval/card_backend`
# network reads with `revalidate: 0` (which Next 15 treats as dynamic
# and fails the static export of `/`).
ENV DATA_BACKEND=${DATA_BACKEND} \
HF_DATASET_REPO=${HF_DATASET_REPO} \
LOCAL_PIPELINE_OUTPUT=/app/.cache/hf-data \
HF_DATA_LOCAL_DIR=/app/.cache/hf-data \
HF_DATA_OFFLINE=1
# install OS build deps required by some native node modules and package manager
# copy lockfile first to leverage Docker layer caching
COPY package*.json ./
COPY pnpm-lock.yaml ./
# Install minimal build tools for native modules (node-gyp) and install pnpm.
# Using the repo's `pnpm-lock.yaml` keeps installs deterministic on Spaces.
ENV DEBIAN_FRONTEND=noninteractive \
CI=true
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates python3 build-essential git curl \
&& rm -rf /var/lib/apt/lists/* \
&& npm install -g pnpm@${PNPM_VERSION} \
&& pnpm install --frozen-lockfile
# copy source and build
COPY . ./
RUN pnpm run build
FROM node:18-bullseye-slim AS runner
WORKDIR /app
# Runtime needs the same DuckDB-mode envs that the builder used. HF Space
# Variables aren't set on this Space, and Docker multi-stage doesn't carry
# ENVs across stages — without these, lib/duckdb-data.ts throws
# "DATA_BACKEND=duckdb requires LOCAL_PIPELINE_OUTPUT" at request time and
# every model/eval/developer endpoint returns empty.
ENV NODE_ENV=production \
DATA_BACKEND=duckdb \
LOCAL_PIPELINE_OUTPUT=/app/.cache/hf-data \
HF_DATA_LOCAL_DIR=/app/.cache/hf-data \
HF_DATA_OFFLINE=1
# minimal packages for certificates (if needed by model download / https)
RUN apt-get update && apt-get install -y ca-certificates --no-install-recommends && rm -rf /var/lib/apt/lists/*
# copy runtime artifacts from builder
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/data ./data
COPY --from=builder /app/.cache ./.cache
COPY --from=builder /app/next.config.mjs ./next.config.mjs
# Expose a common port (informational). Hugging Face Spaces will inject $PORT at runtime
# and the CMD below ensures Next listens on that port. Do not hardcode PORT here.
EXPOSE 3000
# If you use private/gated HF models, set HF_TOKEN in the Space secrets and expose here
# e.g. in Space settings: add secret HF_TOKEN with your token
# Ensure `next start` uses the $PORT provided by the Spaces runtime. We use a shell
# wrapper so the environment variable is expanded at container runtime.
CMD ["sh", "-c", "npm run start -- -p ${PORT:-3000}"]
|