-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
63 lines (49 loc) · 1.92 KB
/
Copy pathdockerfile
File metadata and controls
63 lines (49 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
###############################################
# Builder stage
# - Install all dependencies
# - Compile TypeScript to ./dist
# - Prune dev dependencies
# Hinweis: Hier wird bewusst npm verwendet; im Runtime-Image wird npm entfernt,
# damit die bekannte Schwachstelle (tar@7.5.1) nicht mehr vorhanden ist.
###############################################
FROM node:current-alpine3.22 AS builder
# Benötigte Tools für Build (z. B. git)
RUN apk add --no-cache git
# Arbeitsverzeichnis setzen
WORKDIR /app
# Nur Manifest-Dateien kopieren und Abhängigkeiten installieren
COPY package.json package-lock.json ./
# Reproduzierbare Installation anhand des Lockfiles
RUN npm ci
# Quellcode und TS-Config kopieren
COPY tsconfig.json ./
COPY server.ts ./
COPY src ./src
# TypeScript kompilieren
RUN npm run build
# Nur Produktionsabhängigkeiten behalten
RUN npm prune --omit=dev
###############################################
# Runtime stage (schlankes Image)
# - Kopiert nur dist/ und prod node_modules
# - Entfernt npm vollständig, um tar aus der Abhängigkeitskette zu eliminieren
###############################################
FROM node:24-alpine3.22 AS runtime
# Systempakete aktualisieren
RUN apk update && apk upgrade --no-cache
# Unnötige/verletzliche npm-Teile entfernen (wir benötigen npm zur Laufzeit nicht)
# Dadurch wird die in Harbor gemeldete Schwachstelle in npm->tar entfernt.
RUN rm -rf /usr/local/lib/node_modules/npm || true
# Non-Root-User anlegen
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Arbeitsverzeichnis
WORKDIR /app
# Artefakte aus dem Builder übernehmen
COPY --chown=appuser:appgroup --from=builder /app/node_modules ./node_modules
COPY --chown=appuser:appgroup --from=builder /app/dist ./dist
COPY --chown=appuser:appgroup --from=builder /app/src ./src
COPY --chown=appuser:appgroup healthcheck.js ./healthcheck.js
# Auf Non-Root wechseln
USER appuser
# Start-Kommando
CMD ["node", "./dist/server.js"]