#  sudo docker run -d -p 3005:3005 --name rental-contract-pdf rental-contract-pdf

FROM node:20-bookworm-slim

RUN apt-get update \
  && apt-get install -y --no-install-recommends \
    libreoffice-writer \
    fonts-noto-cjk \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY package*.json ./
RUN npm ci --omit=dev

COPY . .

RUN if [ -d fonts ] && ls fonts/*.{ttf,otf,ttc} 2>/dev/null | grep -q .; then \
      mkdir -p /usr/local/share/fonts/custom && \
      cp fonts/*.ttf fonts/*.otf fonts/*.ttc /usr/local/share/fonts/custom/ 2>/dev/null || true && \
      fc-cache -f; \
    fi

ENV NODE_ENV=production
ENV PORT=3005
ENV TEMPLATE_DIR=/app/templates
ENV TEMP_DIR=/tmp/rental-contracts
ENV SOFFICE_BIN=soffice

EXPOSE 3005

CMD ["npm", "start"]
