Refactor Dockerfile for multi-stage build and better dependency management
- Updated Dockerfile to use a multi-stage build process for improved efficiency. - Compiled better-sqlite3 from source in the builder stage. - Pruned development dependencies in the runner stage to reduce image size. - Streamlined the copying of necessary files between build stages.
This commit is contained in:
+14
-15
@@ -1,26 +1,29 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
#
|
||||
# better-sqlite3 is a native addon — compile it in a Debian (glibc) builder,
|
||||
# then copy node_modules into a slim runner. Do not reuse host node_modules.
|
||||
|
||||
FROM node:22-bookworm-slim AS web-build
|
||||
WORKDIR /app
|
||||
FROM node:22-bookworm-slim AS builder
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends python3 make g++ \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
RUN npm ci \
|
||||
&& npm rebuild better-sqlite3 --build-from-source
|
||||
|
||||
COPY web ./web
|
||||
COPY src ./src
|
||||
RUN npm run build:web
|
||||
RUN npm run build:web \
|
||||
&& npm prune --omit=dev
|
||||
|
||||
FROM node:22-bookworm-slim AS runner
|
||||
|
||||
FROM node:22-bookworm-slim AS runtime
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends python3 make g++ \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV DATA_DIR=/app/data
|
||||
ENV PORT=3000
|
||||
@@ -28,13 +31,9 @@ ENV WATCH_CRON="0 * * * *"
|
||||
ENV WATCH_TITLE_INTERVAL_HOURS="24"
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --omit=dev \
|
||||
&& apt-get purge -y python3 make g++ \
|
||||
&& apt-get autoremove -y \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY src ./src
|
||||
COPY --from=web-build /app/public ./public
|
||||
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user