1- FROM node:24
1+ # ---- Builder: install production dependencies ----
2+ # The C++ toolchain lives only in this stage. better-sqlite3 ships prebuilt
3+ # binaries for linux amd64/arm64 (glibc), so `npm ci` normally downloads a
4+ # binary and compiles nothing; the toolchain is the automatic fallback for
5+ # platforms without a prebuild.
6+ FROM node:24-slim AS builder
27WORKDIR /app
38
9+ RUN apt-get update && \
10+ apt-get install -y --no-install-recommends python3 make g++ && \
11+ rm -rf /var/lib/apt/lists/*
12+
13+ COPY package*.json ./
14+ RUN npm ci --omit=dev --no-audit --no-fund
15+
16+ # ---- Runtime ----
17+ FROM node:24-slim
18+ WORKDIR /app
19+
20+ # tzdata: chore scheduling depends on the TZ env var. Node's bundled ICU covers
21+ # JS Date/Intl on its own, but the OS zoneinfo db is ~3MB of insurance for
22+ # anything else that reads /usr/share/zoneinfo.
23+ RUN apt-get update && \
24+ apt-get install -y --no-install-recommends tzdata && \
25+ rm -rf /var/lib/apt/lists/*
26+
427# Accept PORT and TZ as build arguments with defaults
528ARG PORT=5000
629ARG TZ=America/New_York
@@ -9,24 +32,15 @@ ARG BACKEND_GIT_COMMIT=
932ARG BACKEND_GITHUB_REPOSITORY=jherforth/HomeGlow
1033
1134# Set as environment variables for runtime
35+ ENV NODE_ENV=production
1236ENV PORT=$PORT
1337ENV TZ=$TZ
1438ENV APP_VERSION=$BACKEND_VERSION
1539ENV BACKEND_VERSION=$BACKEND_VERSION
1640ENV BACKEND_GIT_COMMIT=$BACKEND_GIT_COMMIT
1741ENV BACKEND_GITHUB_REPOSITORY=$BACKEND_GITHUB_REPOSITORY
1842
19- # Install SQLite3 dependencies with GPG error handling
20- RUN apt-get clean && \
21- rm -rf /var/lib/apt/lists/* && \
22- apt-get update --allow-insecure-repositories || apt-get update && \
23- apt-get install -y --allow-unauthenticated libsqlite3-dev python3 make g++
24-
25- COPY package*.json ./
26- RUN npm install -g npm@latest
27- RUN npm install || { echo 'npm install failed' ; exit 1; }
28- RUN npm rebuild better-sqlite3 --build-from-source
29-
43+ COPY --from=builder /app/node_modules ./node_modules
3044COPY . .
3145RUN mkdir -p /app/uploads/users /app/widgets && chmod -R 777 /app/uploads /app/widgets
3246
0 commit comments