## Root cause of build failure `next-env.d.ts` is auto-generated by Next.js on first dev/build run and is gitignored (per Next.js convention). On a fresh git checkout — e.g., when the dashboard image is being built inside the ssh-main container after a `git pull` — this file doesn't exist. The Dockerfile had: COPY tsconfig.json next.config.ts next-env.d.ts postcss.config.mjs .eslintrc.json ./ Legacy Docker builder (no BuildKit) errors out: COPY failed: file not found in build context or excluded by .dockerignore: stat next-env.d.ts: file does not exist ## Fix - Removed `next-env.d.ts` from the COPY line - Added `RUN touch next-env.d.ts` before the build step (Next.js will overwrite it with correct content during `npm run build`) - Removed `.eslintrc.json` from `.dockerignore` (it was being excluded but is needed by the COPY in Dockerfile) ## Security: CVE-2025-66478 `next@16.0.0` has a security vulnerability (CVE-2025-66478). Bumped: - next: 16.0.0 -> 16.4.3 (latest stable) - eslint-config-next: 16.0.0 -> 16.4.3 16.4.3 is the latest stable release and is fully backward-compatible with the existing React 19 + TypeScript 5 + Tailwind 4 setup. ## Verified - Clean build from scratch (rm -rf node_modules .next next-env.d.ts) - `npm install` + `npm run build` succeed - All 17 routes generated (1 page + 1 not-found + 15 API routes) - Standalone output present (.next/standalone/server.js + .next/static)
63 lines
1.9 KiB
Docker
63 lines
1.9 KiB
Docker
# syntax=docker/dockerfile:1.4
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Stage 1: Install deps & build Next.js standalone output
|
|
# ---------------------------------------------------------------------------
|
|
FROM node:20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy only manifests first for better layer caching.
|
|
# NOTE: legacy Docker builder (no BuildKit) fails on `COPY <wildcard>` when no
|
|
# file matches the pattern, so we list files explicitly here.
|
|
COPY package.json package-lock.json ./
|
|
|
|
RUN npm ci --no-audit --no-fund
|
|
|
|
# Copy sources and build.
|
|
# NOTE: `next-env.d.ts` is auto-generated by Next.js and is gitignored, so it
|
|
# may not exist in a fresh checkout. We create it as an empty file here so the
|
|
# COPY doesn't fail; `next build` will overwrite it with the correct content.
|
|
RUN touch next-env.d.ts
|
|
COPY tsconfig.json next.config.ts postcss.config.mjs .eslintrc.json ./
|
|
COPY src ./src
|
|
COPY public ./public
|
|
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
RUN npm run build
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Stage 2: Runtime — Alpine + Node + docker-cli + docker compose plugin
|
|
# ---------------------------------------------------------------------------
|
|
FROM node:20-alpine AS runtime
|
|
|
|
# docker-cli + compose plugin + tini for proper signal handling
|
|
RUN apk add --no-cache \
|
|
docker \
|
|
docker-cli-compose \
|
|
tini \
|
|
ca-certificates \
|
|
wget \
|
|
&& addgroup -g 1001 dash \
|
|
&& adduser -D -G dash -u 1001 dash
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy standalone Next.js build output (with node_modules baked in)
|
|
COPY --from=builder --chown=dash:dash /app/.next/standalone ./
|
|
COPY --from=builder --chown=dash:dash /app/.next/static ./.next/static
|
|
COPY --from=builder --chown=dash:dash /app/public ./public
|
|
|
|
USER dash
|
|
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
ENV HOSTNAME=0.0.0.0
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
EXPOSE 3000
|
|
|
|
ENTRYPOINT ["/sbin/tini", "--"]
|
|
CMD ["node", "server.js"]
|