# A dockerfile to run document builds with a minimal TeXLive that has only
# the packages needed for the template pre-installed.
FROM harbor.cta-observatory.org/proxy_cache/python:3.12-slim-bookworm

ARG TEXLIVE_VERSION=2024
ARG PLANTUML_VERSION="1.2025.2"

RUN apt update \
    && apt install -y --no-install-recommends \
        curl make git fontconfig locales gpg gpg-agent \
        default-jre graphviz yamllint \
        perl perl-modules libgetopt-long-descriptive-perl libdigest-perl-md5-perl \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /var/cache/apt/ \
    && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8


ENV LANG=en_US.utf8 \
    PATH="/opt/texlive/${TEXLIVE_VERSION}/bin/x86_64-linux:$PATH" \
    TEXLIVE_INSTALL_NO_CONTEXT_CACHE=1 \
    NOPERLDOC=1


ADD tex-packages.txt /tmp/

RUN python -m pip install --no-cache ruamel.yaml pygments jsonschema install_texlive \
    && install_texlive \
        -p /opt/texlive \
        -t ${TEXLIVE_VERSION} \
        --collections='-a' \
        --package-file /tmp/tex-packages.txt \
        --update \
    && rm -rf /tmp/texlive-${TEXLIVE_VERSION} /tmp/tex-packages.txt

RUN mkdir -p /usr/local/share/java/ \
  && curl -sSfLo /usr/local/share/java/plantuml.jar \
    https://github.com/plantuml/plantuml/releases/download/v${PLANTUML_VERSION}/plantuml-pdf-${PLANTUML_VERSION}.jar
ADD --chmod=755 ./plantuml /usr/local/bin/plantuml

CMD ["/bin/bash"]
