# 00e7fa691e5c2e4594f9705f2ee9340fd792d1330eee357cc545b05fe81961ac
# Dockerfile generated by Maru 0.1.1

# Staged build using builder container
FROM janeliascicomp/builder:1.2.1 as builder
ARG GIT_TAG=master

# Checkout and build the code
WORKDIR /tmp/app
RUN git clone --branch $GIT_TAG --depth 1 https://github.com/GFleishman/bigstream.git . \
    && /usr/local/bin/buildinfo.sh

# Create final image
FROM continuumio/miniconda3:4.9.2

COPY environment.yml /tmp/
RUN conda env create -f /tmp/environment.yml \
    && conda clean -afy \
    && mkdir -p /opt/conda/envs/myenv/etc/conda/activate.d \
    # It's necessary to set TMPDIR for running with Singularity, because /opt/conda will be read-only
    && echo "export TMPDIR=/tmp" > /opt/conda/envs/myenv/etc/conda/activate.d/env_vars.sh

# OpenGL is needed for opencv
# procps is needed to get ps so that Nextflow Tower can do metrics collection
RUN apt-get --allow-releaseinfo-change update \
    && apt-get install -y libgl1-mesa-glx procps

COPY --from=builder /tmp/app /app
COPY --from=builder /buildinfo /
COPY waitforpaths.sh /app/scripts/

RUN echo "#!/bin/bash" >> /entrypoint.sh \
    && echo "source /opt/conda/etc/profile.d/conda.sh" >> /entrypoint.sh \
    && echo "SCRIPT_NAME=\$1; shift" >> /entrypoint.sh \
    && echo "conda activate myenv" >> /entrypoint.sh \
    && echo 'python /app/bigstream/${SCRIPT_NAME}.py "$@"' >> /entrypoint.sh \
    && chmod +x /entrypoint.sh
