1# =============================================================================2# Node.js Production Dockerfile3# =============================================================================4# Customize the following before use:5# - APP_NAME: Replace in comments as needed6# - PORT: Change EXPOSE port if not 30007# - ENTRY_POINT: Change the final CMD to your main file (e.g. dist/main.js)8# - BUILD_CMD: Adjust "npm run build --if-present" if your build script differs9#10# Package manager support:11# - npm: This file is configured for npm by default12# - yarn: Replace "npm ci" with "yarn install --frozen-lockfile"13# Replace "package-lock.json" with "yarn.lock"14# - pnpm: Replace "npm ci" with "corepack enable && pnpm install --frozen-lockfile"
21# Base: current Node LTS, Alpine variant. See references/base-images.md.
22FROM node:<LATEST_STABLE_NODE>-alpine AS build
23
24WORKDIR /app
25
26# Layer caching: copy dependency manifests first so the install layer is
27# only rebuilt when dependencies change, not on every source edit.
28COPY package.json package-lock.json ./
29
30RUN npm ci
31
32# Copy the rest of the source and build
33COPY . .
34
35RUN npm run build --if-present
36
37# Guard: verify build output exists at expected location
38RUN test -d /app/dist || (echo "ERROR: Build output directory '/app/dist' not found." && echo "Your build script did not produce output in the 'dist/' directory." && echo "Update the 'COPY --from=build /app/dist ./dist' line in the runtime stage" && echo "to match your build script's output directory (e.g., 'build/', 'out/', 'public/')." && exit 1)
39
40# Remove dev dependencies to slim down the production node_modules