blob: 250006e5159d5a81d848407414871c45c1af90b2 [file] [log] [blame]
Marc Kupietz03ba3012025-12-11 16:14:05 +01001# Multi-stage Docker build for size optimization
2FROM node:alpine AS builder
3
4# Set the working directory
5WORKDIR /app
6
7# Copy package files first (for better layer caching)
8COPY package*.json ./
9
10# Install dependencies (production only)
11RUN npm ci --only=production
12
13# Production stage
14FROM node:alpine AS production
15
16# metadata
17LABEL maintainer="Marc Kupietz <kupietz@ids-mannheim.de>"
18
19# Install minimal runtime dependencies
20RUN apk add --no-cache --update \
21 shadow \
22 && rm -rf /var/cache/apk/*
23
24# Add non-root user
25RUN groupadd -r appuser && useradd -r -g appuser appuser
26
27# Set the working directory
28WORKDIR /app
29
30# Copy node_modules from builder
31COPY --from=builder --chown=appuser:appuser /app/node_modules /app/node_modules
32
33# Copy application source
34COPY --chown=appuser:appuser package.json /app/
35COPY --chown=appuser:appuser src /app/src
36
37# Copy entry point
38COPY --chown=appuser:appuser docker-entrypoint.sh /docker-entrypoint.sh
39RUN chmod +x /docker-entrypoint.sh
40
41# Switch to non-root user
42USER appuser
43
44# Define the entry point
45ENTRYPOINT ["/docker-entrypoint.sh"]