# Linux image that runs DDD and compiles the c code it generates.
#
# Built and used through docker compose from a WSL shell:
#   wsl -d Ubuntu
#   cd /mnt/c/path/to/ddd && docker compose run --rm compile
#
# This image exists to prove that the generated c compiles, and that proof is only worth
# something if it is the same toolchain tomorrow. The tag below still floats: pin it to a
# digest before relying on the result for a release, with
#
#   docker pull python:3.12-slim-bookworm
#   docker inspect --format='{{index .RepoDigests 0}}' python:3.12-slim-bookworm
#
# and replace the tag with the "python@sha256:..." it prints.
FROM python:3.12-slim-bookworm

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# gcc compiles the generated sources and binutils (nm) verifies that every variable DDD
# promised really ends up in the object file exactly once.
#
# graphviz and plantuml draw the figures of the documentation, which builds with warnings as
# errors: without them the `docs` service fails rather than dropping a diagram. plantuml brings
# a headless jre with it, which is most of what these two add to the image.
#
# No node here, deliberately. The VS Code extension under editors/vscode is built and tested by
# ci, which can put python and node 20 side by side with two setup actions; carrying a second
# toolchain in this image would cost everyone who only wants to compile c or build the
# documentation, to save a contributor changing typescript from installing node.
RUN apt-get update \
    && apt-get install --no-install-recommends --yes \
        gcc \
        libc6-dev \
        binutils \
        graphviz \
        plantuml \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /opt/ddd
COPY pyproject.toml README.md LICENSE requirements*.txt ./
COPY src ./src
COPY cmake ./cmake
# Every path the wheel force-includes has to be here, or the install below cannot build it.
# The templates are the one that is easy to forget: they live under examples/ rather than
# beside the other two, and leaving them out fails the image build rather than the tests.
COPY examples/templates ./examples/templates
# The dev requirements bring cmake and ninja as wheels, which is what builds the example that
# integrates the tool through cmake/Ddd.cmake. They come from pypi rather than from apt because
# the module needs the TRANSITIVE_LINK_PROPERTIES feature of CMake 3.30 and debian bookworm
# still ships 3.25 - and because tests/test_cmake.py runs against exactly this pair.
#
# The docs requirements are here rather than in the `docs` service, which used to install them
# on every run: a service that installs anything is a second build step nothing pins, needs the
# network before every documentation build, and leaves the five other services sharing an image
# that cannot do what the sixth does.
RUN pip install --no-cache-dir ".[dev,docs]"

COPY docker/compile.sh docker/verify_symbols.py /opt/ddd/bin/
RUN chmod +x /opt/ddd/bin/compile.sh \
    && ln -s /opt/ddd/bin/compile.sh /usr/local/bin/ddd-compile

# The project is bind mounted here by docker compose; PYTHONPATH=/work/src then
# shadows the copy installed above, so the container always runs the working tree.
WORKDIR /work

CMD ["ddd", "--help"]
