FROM debian:trixie-slim
ARG BRANCH="main"
ARG GIT_URL="https://codeberg.org/seshat/seshat.git"

# This builds a self-updating (development) container using dependencies from PyPI.
# For production-grade builds, see the "release-build" file.

RUN apt-get update \
    && apt-get install -y autoconf automake make git python3 python3-venv \
    && rm -rf /var/lib/dpkg/info/*.list /var/lib/apt/lists/* \
    && useradd -mg users -d /opt/seshat -u 7001 seshat \
    && mkdir -p /data && chown -R seshat: /data \
    &&  echo '#!/bin/sh\n/usr/bin/git -C /opt/seshat/seshat pull\nGIT_VERSION=$(git -C /opt/seshat/seshat rev-parse --short HEAD)\nsed -i "s|AC_INIT|AC_INIT(seshat, 0.0.dev0+t${GIT_VERSION}) dnl AC_INIT|g" /opt/seshat/seshat/configure.ac\ncd /opt/seshat/seshat; autoreconf -if && ./configure\nVIRTUAL_ENV=/opt/seshat/virtual-env\n/opt/seshat/virtual-env/bin/pip install --editable /opt/seshat/seshat\n' > /usr/bin/update-seshat \
    && chmod +x /usr/bin/update-seshat \
    && echo '#!/bin/sh\n/usr/bin/update-seshat\nVIRTUAL_ENV=/opt/seshat/virtual-env\n/opt/seshat/virtual-env/bin/seshat $@' > /usr/bin/seshat && chmod +x /usr/bin/seshat

USER seshat

RUN git clone --branch "$BRANCH" --depth 1 "$GIT_URL" /opt/seshat/seshat \
    && cd /opt/seshat/seshat; autoreconf -if && ./configure \
    && python3 -m venv /opt/seshat/virtual-env \
    && . /opt/seshat/virtual-env/bin/activate \
    && pip install python3-saml --editable /opt/seshat/seshat

CMD ["/bin/bash"]
