# DTN7-rs Dockerfile that contains the necessary dependencies for interoperability tests

FROM buildpack-deps:bullseye

RUN apt-get update && \
    apt-get dist-upgrade -y && \
    apt-get install python3-venv python3-pip curl sqlite3 libjansson-dev -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Set environment variables for Rust installation
ENV CARGO_HOME=/usr/local/cargo
ENV RUSTUP_HOME=/usr/local/rustup

# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# Add Rust binaries to the PATH
ENV PATH="${CARGO_HOME}/bin:${PATH}"

# Clone DTN7 repository from GitHub
ARG GIT_REF="master"
RUN git clone https://github.com/dtn7/dtn7-rs.git

# Install DTN7 system-wide
WORKDIR dtn7-rs
RUN git checkout $GIT_REF
RUN cargo install --path ./core/dtn7

# Switch back to UD3TN directory
WORKDIR ..

COPY ./pyd3tn/requirements.txt /req-pyd3tn.txt
COPY ./python-ud3tn-utils/requirements.txt /req-utils.txt
COPY ./test/integration/requirements.txt /req-test.txt
COPY ./tools/analysis/requirements.txt /req-analysis.txt

# NOTE: pyd3tn is explicitly installed in `prepare_for_test.sh`; this might
# otherwise install the wrong version (from PyPI) and lead to clashes!
RUN sed -i '/^pyd3tn==/d' /req-utils.txt

RUN python3 -m venv /ud3tn_venv && \
    /ud3tn_venv/bin/python -m pip install --no-cache-dir -U setuptools pip wheel && \
    /ud3tn_venv/bin/python -m pip install --no-cache-dir -U -r /req-pyd3tn.txt && \
    /ud3tn_venv/bin/python -m pip install --no-cache-dir -U -r /req-utils.txt && \
    /ud3tn_venv/bin/python -m pip install --no-cache-dir -U -r /req-test.txt && \
    /ud3tn_venv/bin/python -m pip install --no-cache-dir -U -r /req-analysis.txt
