# syntax=docker/dockerfile:1
# node:22-alpine, weil node:sqlite (SQLite-Persistenz in server.js) erst ab
# Node 22.13 (ohne Flag) stabil verfügbar ist.
FROM node:22-alpine

WORKDIR /app

# package.json und package-lock.json zuerst kopieren, damit npm-Installation gecacht wird
COPY package.json package-lock.json ./
RUN npm ci --production

# Nur die Laufzeit-Dateien kopieren
COPY server.js ./
COPY public ./public

# Sessions-Ordner fuer die SQLite-Datenbank sicherstellen
RUN mkdir -p /app/sessions && chown -R node:node /app

USER node

EXPOSE 3003

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD node -e "require('http').get('http://localhost:3003/health', r => r.statusCode === 200 ? process.exit(0) : process.exit(1)).on('error', () => process.exit(1))"

CMD ["node", "server.js"]
