FROM rocker/r-ver:4.1.0

# Install python 3.7 so we can run Prefect
RUN export DEBIAN_FRONTEND=noninteractive && \
    apt-get update && \
    apt-get install --no-install-recommends -y software-properties-common && \
    add-apt-repository ppa:deadsnakes/ppa && \
    apt-get install --no-install-recommends -y \
        software-properties-common \
        python3.7 \
        python3-pip \
        python3-venv \
        git && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
RUN update-alternatives --set python /usr/bin/python3.7
RUN pip --no-cache-dir install virtualenv

# Create virtual environment and add it to the PATH
ENV VIRTUAL_ENV=/opt/venv
RUN virtualenv -p python3.7 $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN pip install --no-cache-dir prefect[all_orchestration_extras]==0.14.19

RUN mkdir /opt/R
COPY flows/R/test.R /opt/R
WORKDIR /opt/R

ENTRYPOINT ["Rscript", "/opt/R/test.R"]
