# Reproducible build + test image for the igraph extension. Builds the vendored igraph C library
# (static) together with the wrapper, enables the extension, and (by default) runs the .phpt suite.
# Useful on hosts without the full build toolchain.
#
#   docker build -t php-igraph .
#   docker run --rm php-igraph                 # runs `make test` (the .phpt suite)
#   docker run --rm php-igraph php --ri igraph
#
# $PHPIZE_DEPS + docker-php-ext-enable come from the official php image. igraph adds: cmake (its
# build system), flex + bison (a git checkout generates its parsers), libxml2-dev (GraphML), and a
# C++ compiler (igraph has C++ internals). valgrind is installed for the leak/UB proof.
#
# The build context must include the vendored submodule — run `git submodule update --init
# vendor/igraph` before `docker build` (a submodule is not fetched automatically).
FROM php:8.5-cli

RUN apt-get update \
 && apt-get install -y --no-install-recommends \
      $PHPIZE_DEPS cmake flex bison libxml2-dev g++ valgrind \
 && rm -rf /var/lib/apt/lists/*

COPY . /ext
WORKDIR /ext

# Strip any host build artifacts that rode in (they bake absolute host paths into the generated
# Makefile and the igraph build), then build cleanly in-image from the tracked sources.
RUN rm -rf Makefile Makefile.* config.h config.h.in config.log config.nice config.status \
      configure configure.ac libtool build .libs .deps modules autom4te.cache run-tests.php \
      vendor/igraph-build \
 && find . -path ./vendor/igraph -prune -o \
      \( -name '*.lo' -o -name '*.la' -o -name '*.o' -o -name '*.dep' \) -print -delete \
 && phpize \
 && ./configure --enable-igraph \
 && make -j"$(nproc)" \
 && make install \
 && docker-php-ext-enable igraph \
 && php --ri igraph

CMD ["make", "test", "NO_INTERACTION=1"]
