FROM node:20-bookworm-slim

# Native tools the repair strategies depend on
RUN apt-get update && apt-get install -y --no-install-recommends \
      python3 \
      python3-pil \
      imagemagick \
      libjpeg-turbo-progs \
      libimage-exiftool-perl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY package.json ./
RUN npm install --omit=dev

COPY . .

# Allow ImageMagick to read PDFs and label fonts (some hosts lock these)
RUN sed -i 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml || true

ENV PORT=3000
EXPOSE 3000
CMD ["node", "server.js"]
