FROM mambaorg/micromamba:2.5.0 AS builder

COPY --chown=$MAMBA_USER:$MAMBA_USER ./docker /immunopipe/docker

ARG MAMBA_DOCKERFILE_ACTIVATE=1
RUN micromamba env update -n base -f /immunopipe/docker/environment_rpkgs.yml && \
    micromamba clean --all --yes && \
    python /immunopipe/docker/cleanup.py

# Fresh stage to avoid metadata bloat
FROM justold/immunopipe-base:latest

# Copy only the new packages, not the entire environment
COPY --from=builder /opt/conda/lib/R/library/scRepertoire /opt/conda/lib/R/library/scRepertoire
# COPY --from=builder /opt/conda/lib/R/library/hitype /opt/conda/lib/R/library/hitype
COPY --from=builder /opt/conda/lib/R/library/gglogger /opt/conda/lib/R/library/gglogger
COPY --from=builder /opt/conda/lib/R/library/enrichit /opt/conda/lib/R/library/enrichit
COPY --from=builder /opt/conda/lib/R/library/plotthis /opt/conda/lib/R/library/plotthis
COPY --from=builder /opt/conda/lib/R/library/scplotter /opt/conda/lib/R/library/scplotter
COPY --from=builder /opt/conda/lib/R/library/biopipen.utils /opt/conda/lib/R/library/biopipen.utils

ARG MAMBA_DOCKERFILE_ACTIVATE=1
ENTRYPOINT [ "/usr/local/bin/_entrypoint.sh" ]
