From 0dac1a55057eac11da944aa9da64ade570d99345 Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Thu, 9 Oct 2025 10:11:38 +0200 Subject: [PATCH] build: optimize Docker image with multi-stage build and security improvements - Implement multi-stage build to reduce final image size - Install only production dependencies with npm ci --only=production - Clean npm cache to reduce image size - Improve layer caching by copying package files before application code - Update package version from 1.0.0 to 1.0.1 --- Dockerfile | 25 ++++++++++++++++--------- package.json | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 702bfd2..818b40e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,22 @@ -FROM node:23-slim +FROM node:24-slim AS builder WORKDIR /usr/src/app +# Copy dependency files first +COPY package*.json ./ + +# Install production dependencies only +RUN npm ci --only=production && npm cache clean --force + +FROM node:24-slim + +WORKDIR /usr/src/app + +COPY --from=builder /usr/src/app/node_modules ./node_modules + +# Copy application code +COPY . . + EXPOSE 3000 -COPY package.json /usr/src/app/package.json - -RUN npm install - -USER node - -COPY . /usr/src/app/ - CMD ["npm", "start"] diff --git a/package.json b/package.json index e5f628f..19b95fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "no-as-service", - "version": "1.0.0", + "version": "1.0.1", "description": "A lightweight API that returns random rejection or no reasons.", "main": "index.js", "scripts": {