27f3710c8b
Next file tracing follows JS imports, and sql.js loads dist/sql-wasm.wasm by
path at runtime, so the standalone output carries the package's JS without its
wasm binary. When both native drivers fail the last-resort adapter then aborts
with ENOENT on the missing binary and the container never gets a database.
The CLI bundle already guards this explicitly (build-cli.js step 3b,
ensureModuleInBundle("sql.js")); the image just never got the same treatment.
Copy the package the same way node-forge and next already are.
Fixes #3248
57 lines
1.9 KiB
Docker
57 lines
1.9 KiB
Docker
# syntax=docker/dockerfile:1.7
|
|
ARG NODE_IMAGE=node:22-alpine
|
|
FROM ${NODE_IMAGE} AS base
|
|
WORKDIR /app
|
|
|
|
FROM base AS builder
|
|
|
|
RUN apk --no-cache upgrade && apk --no-cache add python3 make g++ linux-headers
|
|
|
|
COPY package.json ./
|
|
RUN --mount=type=cache,target=/root/.npm \
|
|
npm install
|
|
|
|
COPY . ./
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
RUN npm run build
|
|
|
|
FROM ${NODE_IMAGE} AS runner
|
|
WORKDIR /app
|
|
|
|
LABEL org.opencontainers.image.title="9router"
|
|
|
|
ENV NODE_ENV=production
|
|
ENV PORT=20128
|
|
ENV HOSTNAME=0.0.0.0
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV DATA_DIR=/app/data
|
|
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/.next/static ./.next/static
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder /app/custom-server.js ./custom-server.js
|
|
COPY --from=builder /app/open-sse ./open-sse
|
|
# Next file tracing can omit sibling files; MITM runs server.js as a separate process.
|
|
COPY --from=builder /app/src/mitm ./src/mitm
|
|
# Standalone node_modules may omit deps only required by the MITM child process.
|
|
COPY --from=builder /app/node_modules/node-forge ./node_modules/node-forge
|
|
# Ensure `next` is available at runtime in case tracing did not include it.
|
|
COPY --from=builder /app/node_modules/next ./node_modules/next
|
|
# sql.js loads dist/sql-wasm.wasm by path at runtime; tracing only follows JS imports,
|
|
# so the last-resort DB driver would abort with ENOENT on the missing binary.
|
|
COPY --from=builder /app/node_modules/sql.js ./node_modules/sql.js
|
|
|
|
RUN mkdir -p /app/data && chown -R node:node /app && \
|
|
mkdir -p /app/data-home && chown node:node /app/data-home && \
|
|
ln -sf /app/data-home /root/.9router 2>/dev/null || true
|
|
|
|
# Fix permissions at runtime (handles mounted volumes)
|
|
RUN apk --no-cache upgrade && apk --no-cache add su-exec && \
|
|
printf '#!/bin/sh\nchown -R node:node /app/data /app/data-home 2>/dev/null\nexec su-exec node "$@"\n' > /entrypoint.sh && \
|
|
chmod +x /entrypoint.sh
|
|
|
|
EXPOSE 20128
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
CMD ["node", "custom-server.js"]
|