FROM debian:bookworm-slim

ENV TZ Europe/Madrid

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        cups \
        curl \
        ca-certificates \
        sudo \
        libcupsimage2 \
        nodejs \
        npm \
    && rm -rf /var/lib/apt/lists/*

# Cups

RUN useradd admin && usermod -g lpadmin admin

COPY ctzcls-cups_1.1.0-2_amd64.deb /tmp/
RUN chmod a+x /tmp/ctzcls-cups_1.1.0-2_amd64.deb \
    && dpkg -i /tmp/ctzcls-cups_1.1.0-2_amd64.deb

# Fix defunct processeses: https://github.com/jenkinsci/docker-inbound-agent/issues/51
ENV TINI_VERSION v0.19.0
RUN wget -O /tini https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini \
    && chmod 755 /tini

# Printnatura

WORKDIR /printnatura

COPY \
    package.json \
    package-lock.json \
    ./
RUN npm install

COPY \
    main.js \
    print-server.js \
    config.yml \
    entrypoint.sh \
    .npmrc \
    ./
COPY sql sql

ENTRYPOINT ["/tini", "--", "/printnatura/entrypoint.sh"]
CMD ["node", "main.js"]