1- FROM node:22-slim
1+ # ================================
2+ # Stage 1: Build stage
3+ # ================================
4+ FROM node:22-alpine AS builder
5+
6+ WORKDIR /build
7+
8+ # Install build dependencies needed for native modules (better-sqlite3)
9+ RUN apk add --no-cache python3 make g++
10+
11+ # Copy package files first for better layer caching
12+ COPY package.json yarn.lock ./
13+
14+ # Install all dependencies (including devDependencies for building)
15+ RUN yarn config set network-timeout 600000 \
16+ && yarn --frozen-lockfile
17+
18+ # Copy source files needed for build
19+ COPY index.html vite.config.js ./
20+ COPY ui ./ui
21+ COPY lib ./lib
22+
23+ # Build frontend assets
24+ RUN yarn build:frontend
25+
26+ # ================================
27+ # Stage 2: Production stage
28+ # ================================
29+ FROM node:22-alpine
230
331WORKDIR /fredy
432
5- # Install Chromium and curl without extra recommended packages and clean apt cache
6- # curl is needed for the health check
7- RUN apt-get update \
8- && apt-get install -y --no-install-recommends chromium curl \
9- && rm -rf /var/lib/apt/lists/*
33+ # Install Chromium and curl (for healthcheck)
34+ # Using Alpine's chromium package which is much smaller
35+ RUN apk add --no-cache chromium curl
1036
1137ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
12- PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
38+ PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
1339
14- # Copy lockfiles first to leverage cache for dependencies
15- COPY package.json yarn.lock .
40+ # Install build dependencies for native modules, then remove them after yarn install
41+ COPY package.json yarn.lock ./
1642
17- # Set Yarn timeout, install dependencies and PM2 globally
18- RUN yarn config set network-timeout 600000 \
19- && yarn --frozen-lockfile \
20- && yarn global add pm2
43+ RUN apk add --no-cache --virtual .build-deps python3 make g++ \
44+ && yarn config set network-timeout 600000 \
45+ && yarn --frozen-lockfile --production \
46+ && yarn cache clean \
47+ && apk del .build-deps
2148
22- # Copy application source and build production assets
23- COPY . .
24- RUN yarn build:frontend
49+ # Copy built frontend from builder stage
50+ COPY --from=builder /build/ui/public ./ui/public
51+
52+ # Copy application source (only what's needed at runtime)
53+ COPY index.js ./
54+ COPY index.html ./
55+ COPY lib ./lib
2556
2657# Prepare runtime directories and symlinks for data and config
2758RUN mkdir -p /db /conf \
@@ -34,5 +65,4 @@ EXPOSE 9998
3465VOLUME /db
3566VOLUME /conf
3667
37- # Start application using PM2 runtime
38- CMD ["pm2-runtime" , "index.js" ]
68+ CMD ["node" , "index.js" ]
0 commit comments