FROM biopipen/cellranger:10.0.0 AS cellranger
FROM biopipen/base:latest

COPY --from=cellranger /cellranger /cellranger

# in case we have updates about the pipeline
COPY --chown=$MAMBA_USER:$MAMBA_USER docker/cellranger_pipeline /biopipen/docker/cellranger_pipeline
# also copy the cleanup scripts in case we have updates
COPY --chown=$MAMBA_USER:$MAMBA_USER docker/cleanup.py /biopipen/docker/cleanup.py
COPY --chown=$MAMBA_USER:$MAMBA_USER docker/cleanup.list /biopipen/docker/cleanup.list

ARG MAMBA_DOCKERFILE_ACTIVATE=1

RUN micromamba env update -n base -f /biopipen/docker/cellranger_pipeline/env.yml && \
    micromamba clean --all --yes && \
    ln -s /cellranger/cellranger-*/bin/cellranger /opt/conda/bin/cellranger && \
    chmod +x /biopipen/docker/cellranger_pipeline/entry.sh && \
    ln -s /biopipen/docker/cellranger_pipeline/entry.sh /opt/conda/bin/entry.sh && \
    /opt/conda/bin/cellranger telemetry disable all && \
    python /biopipen/docker/cleanup.py

WORKDIR /example
RUN /bin/bash /biopipen/docker/cellranger_pipeline/make-examples.sh && \
    cp /biopipen/docker/cellranger_pipeline/board.toml /example/board.toml && \
    cp /biopipen/docker/cellranger_pipeline/CellrangerCountPipeline.config.toml /example/CellrangerCountPipeline.config.toml  && \
    cp /biopipen/docker/cellranger_pipeline/CellrangerVdjPipeline.config.toml /example/CellrangerVdjPipeline.config.toml

WORKDIR /workdir

ENTRYPOINT [ "/bin/bash", "/biopipen/docker/cellranger_pipeline/entry.sh" ]
