Files
kochwas/Dockerfile
hsiegeln 83f5b88d94
Some checks failed
Build & Publish Docker Image / build-and-push (push) Failing after 51s
fix(docker): node-addon-api + ignore-scripts/rebuild fuer sharp
Drei Schichten Absicherung gegen den arm64-Build-Fehler:

- --ignore-scripts beim npm install verhindert, dass sharp's postinstall
  check.js laeuft, bevor das @img/sharp-linuxmusl-arm64-Paket entpackt
  ist (Race in parallelem Install).
- npm rebuild danach: alle Deps sind jetzt auf Disk, Postinstalls laufen
  sauber in Dependency-Reihenfolge.
- node-addon-api als Runtime-Dep: falls die Prebuilt-Binary im npm-Tree
  nicht landet, kann sharp from-source bauen (vips-dev + python3 + make
  + g++ sind im Dockerfile bereits installiert).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 11:49:41 +02:00

53 lines
1.8 KiB
Docker

# syntax=docker/dockerfile:1.7
FROM node:22-alpine AS builder
WORKDIR /app
# Alpine needs build tools for better-sqlite3 native module.
# vips-dev provides libvips + libheif for sharp (incl. HEIC input from iOS).
RUN apk add --no-cache python3 make g++ libc6-compat vips-dev
COPY package*.json ./
# Zwei Fallstricke werden hier adressiert:
# (a) Der auf Windows erzeugte package-lock.json markiert die linux-musl-
# arm64-Prebuilts von sharp als "dev": true, weshalb npm ci sie selbst
# mit --include=optional nicht installiert. --> npm install statt ci.
# (b) Parallel-Install laesst sharp's postinstall laufen, bevor das
# @img/sharp-linuxmusl-arm64-Paket entpackt ist. --> --ignore-scripts
# hier, dann npm rebuild mit allen Deps auf Disk. node-addon-api ist
# als devDep da, damit der from-source Fallback ebenfalls funktioniert
# (python3 + make + g++ + vips-dev sind oben installiert).
RUN npm install --ignore-scripts --include=optional --no-audit --no-fund
RUN npm rebuild
COPY . .
RUN npm run build
# Fresh-Install fuer den Runtime-Stage: nur Produktions-Deps, gleicher Ansatz.
RUN rm -rf node_modules \
&& npm install --ignore-scripts --omit=dev --include=optional --no-audit --no-fund \
&& npm rebuild
FROM node:22-alpine AS runner
WORKDIR /app
RUN apk add --no-cache libc6-compat
COPY --from=builder /app/build ./build
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=3000
ENV DATABASE_PATH=/data/kochwas.db
ENV IMAGE_DIR=/data/images
VOLUME ["/data"]
EXPOSE 3000
HEALTHCHECK --interval=15s --timeout=5s --retries=3 --start-period=20s --start-interval=2s \
CMD wget -qO- http://127.0.0.1:3000/api/health > /dev/null || exit 1
CMD ["node", "build/index.js"]