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
This commit is contained in:
2025-10-09 10:11:38 +02:00
parent 271eb107a2
commit 0dac1a5505
2 changed files with 17 additions and 10 deletions

View File

@@ -1,15 +1,22 @@
FROM node:23-slim FROM node:24-slim AS builder
WORKDIR /usr/src/app 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 EXPOSE 3000
COPY package.json /usr/src/app/package.json
RUN npm install
USER node
COPY . /usr/src/app/
CMD ["npm", "start"] CMD ["npm", "start"]

View File

@@ -1,6 +1,6 @@
{ {
"name": "no-as-service", "name": "no-as-service",
"version": "1.0.0", "version": "1.0.1",
"description": "A lightweight API that returns random rejection or no reasons.", "description": "A lightweight API that returns random rejection or no reasons.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {