# ── Synapse-Talk production image ─────────────────────────────────────────
FROM node:20-alpine

# App lives here.
WORKDIR /app

# Install deps first for better layer caching. Only package manifests change
# infrequently, so this layer is reused across code edits.
COPY package*.json ./
RUN npm ci --omit=dev

# Copy the rest of the source.
COPY . .

# Runtime-writable dirs (JSON store + uploaded images). These are also mounted
# as named volumes in compose so data survives container rebuilds.
RUN mkdir -p data public/uploads \
  && chown -R node:node /app

# Drop root.
USER node

ENV NODE_ENV=production \
    PORT=3000

EXPOSE 3000

# Basic container healthcheck against the bootstrap endpoint.
HEALTHCHECK --interval=30s --timeout=4s --start-period=5s --retries=3 \
  CMD node -e "fetch('http://127.0.0.1:'+(process.env.PORT||3000)+'/api/bootstrap').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"

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