ARG BASE_IMAGE=ubuntu:24.04
ARG CHALLENGE

FROM ghcr.io/tig-foundation/tig-monorepo/${CHALLENGE}/dev AS dev

FROM ${BASE_IMAGE}

ARG CHALLENGE
ENV CHALLENGE=${CHALLENGE}
RUN if [ -z "$CHALLENGE" ]; then echo "Error: '--build-arg CHALLENGE' must be set." && exit 1; fi
ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && apt install -y python3 python3-pip
RUN pip3 install requests --break-system-packages

COPY scripts/ /usr/local/bin/tig-scripts/
RUN chmod +x /usr/local/bin/tig-scripts/*
ENV PATH="/usr/local/bin/tig-scripts:${PATH}"

COPY --from=dev /usr/local/bin/tig-runtime /usr/local/bin/tig-runtime
COPY --from=dev /usr/local/bin/tig-verifier /usr/local/bin/tig-verifier
COPY --from=dev /usr/local/lib/rust /usr/local/lib/rust

RUN chmod +x /usr/local/bin/tig-runtime && \
    chmod +x /usr/local/bin/tig-verifier
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib/rust"

RUN if ls /usr/lib/*-linux-gnu/libcudnn*.so.[0-9] 1>/dev/null 2>&1; then for f in /usr/lib/*-linux-gnu/libcudnn*.so.[0-9]; do ln -sf "$(basename "$f")" "${f%.*.*}.so"; done; fi

WORKDIR /app
