# This is meant to turn a conda environment.yml file into a container. To be used like:
# docker build -t image_name:tag --build-arg ENV_FILE=myenv.yml --build-arg CONDA_IMAGE=continuumio/miniconda3 --build-arg APT_PACKAGES="git libgl1" -f src/meadowrun/docker_files/CondaDockerfile .
# This assumes that ./myenv.yml exists and defines the environment

ARG CONDA_IMAGE

FROM $CONDA_IMAGE

ENV PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

ARG DEBIAN_FRONTEND=noninteractive
ARG APT_PACKAGES
RUN apt update && \
    apt install -y $APT_PACKAGES && \
    rm -rf /var/lib/apt

# See PipAptDockerfile for comments
RUN git config --global --add safe.directory '*'; exit 0

WORKDIR /tmp/

ARG ENV_FILE

COPY $ENV_FILE ./
# we would rather not assume that the name of the environment in $ENV_NAME.yml is the
# same as the filename, so we just hardcode a name here
RUN conda env create -f $ENV_FILE -n the_env
ENV PATH /opt/conda/envs/the_env/bin:$PATH
