# Node 22 LTS (Node 20 reached end of life in April 2026 and gets no more security fixes)
FROM node:22.23.5-alpine
# Refuse to build on a Node.js 22 older than 22.23.5 (security release of 11 Nov 2026). Pinned above; when a newer Node 22 security release comes out, change the FROM line.
RUN node -e "const [a,b,c]=process.versions.node.split('.').map(Number); if(a===22&&(b<23||(b===23&&c<5))){console.error('Node '+process.versions.node+' is too old: needs 22.23.5 or later. Change FROM in server/Dockerfile');process.exit(1)}"
WORKDIR /app
ENV NODE_ENV=production PORT=8080 FILES_DIR=/data/files BACKUP_DIR=/backups
# database backup tools (same major version as the database) and GNU tar for backups
RUN apk add --no-cache postgresql16-client tar
COPY package.json package-lock.json ./
# npm ci installs exactly what package-lock.json lists, so every build gets the same, audited versions
RUN npm ci --omit=dev --no-audit --no-fund && npm cache clean --force
COPY *.js migrations.sql ./
COPY public ./public
# The app files belong to root and are read-only for the app (it can read its code but never change it).
# chmod a+rX makes them readable whatever permissions they had on the computer they were built from.
RUN chmod -R a+rX,go-w /app && mkdir -p /data/files /backups && chown -R node:node /data /backups && chmod 700 /data/files /backups
USER node
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s CMD wget -qO- http://127.0.0.1:8080/healthz || exit 1
CMD ["node", "server.js"]
