
ARG BASE_IMAGE=gitlab.catalyst.net.nz:4567/riskscape/riskscape/base
FROM ${BASE_IMAGE}

ARG DEBIAN_FRONTEND=noninteractive
ENV LANG=en_NZ.UTF-8
ENV LC_ALL=C.UTF-8

ARG IMAGE_UID=1000
ARG IMAGE_GID=1000

USER root

ADD requirements.txt /tmp/requirements.txt
ADD bin/plantuml.jar /usr/local/bin/plantuml.jar
# chmod plantuml.jar otherwise mode is base on current users umask which may
# not be good.
RUN chmod 755 /usr/local/bin/plantuml.jar

RUN set -o errexit -o nounset \
    && groupadd --system --gid $IMAGE_GID docbuilder \
    && useradd --system --gid docbuilder --uid $IMAGE_UID --shell /bin/bash --create-home docbuilder \
    && apt-get update \
    && apt-get install -y build-essential python3-pip zip tar graphviz aspell aspell-en python3-dev python3-setuptools python3-wheel \
    && apt-get autoremove -yq \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN set -o errexit -o nounset \
    && pip3 install --break-system-packages -r /tmp/requirements.txt

# Bundle the spell check scripts into the image. this allows for other projects
# to make use of them
RUN mkdir -p /opt/docbuilder
ADD bin/spell-check-docs.sh /opt/docbuilder/spell-check-docs.sh
ADD bin/spell-check.sh      /opt/docbuilder/spell-check.sh
ADD aspell/riskscape.txt    /opt/docbuilder/riskscape.txt

# Create docbuilder volume
USER docbuilder
VOLUME "/home/docbuilder/"
WORKDIR /home/docbuilder

RUN set -o errexit -o nounset \
    && echo "Testing sphinx installation" \
&& sphinx-build --version

ENTRYPOINT make
