From 7e3173f5b36df275975a03cdb59016cdb05124e3 Mon Sep 17 00:00:00 2001 From: elpatron Date: Mon, 6 Oct 2025 17:55:14 +0200 Subject: [PATCH] docker: install build deps and enable scripts for bcrypt; rebuild native module in prod images --- Dockerfile | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 494dd4e..7c447f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ FROM node:22-alpine AS builder -# Install pnpm -RUN npm install -g pnpm +# Install pnpm and build deps for native modules (e.g., bcrypt) +RUN npm install -g pnpm \ + && apk add --no-cache python3 make g++ libc6-compat WORKDIR /app # Install all deps for building server COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ -RUN pnpm install --frozen-lockfile +RUN pnpm install --frozen-lockfile --ignore-scripts=false # Copy only server sources and tsconfig for server build COPY src/server ./src/server @@ -19,8 +20,9 @@ RUN pnpm tsc -p tsconfig.server.build.json FROM node:22-alpine AS production -# Install pnpm and required runtime tools -RUN npm install -g pnpm ts-node && apk add --no-cache su-exec curl +# Install pnpm, runtime tools and build deps for native modules present in prod deps +RUN npm install -g pnpm ts-node \ + && apk add --no-cache su-exec curl python3 make g++ libc6-compat # Set working directory WORKDIR /app @@ -29,7 +31,8 @@ WORKDIR /app COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ # Install production dependencies only -RUN pnpm install --frozen-lockfile --prod +RUN pnpm install --frozen-lockfile --prod --ignore-scripts=false \ + && pnpm rebuild bcrypt || true # Copy prebuilt application artifacts from repository (no TS build in image) COPY dist ./dist @@ -67,11 +70,13 @@ CMD ["/app/start.sh"] # Prebuilt runtime stage (used locally): copies prebuilt dist and server-dist from context FROM node:22-alpine AS production-prebuilt -RUN npm install -g pnpm ts-node && apk add --no-cache su-exec curl +RUN npm install -g pnpm ts-node \ + && apk add --no-cache su-exec curl python3 make g++ libc6-compat WORKDIR /app COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ -RUN pnpm install --frozen-lockfile --prod +RUN pnpm install --frozen-lockfile --prod --ignore-scripts=false \ + && pnpm rebuild bcrypt || true # Copy prebuilt artifacts from repository COPY dist ./dist