# This is nrao:workflow
FROM marconi.aoc.nrao.edu/ops/base:workspaces

# HTCondor install
RUN apt update && apt install -y wget gnupg sudo
RUN wget -qO - https://research.cs.wisc.edu/htcondor/debian/HTCondor-Release.gpg.key | sudo apt-key add -
RUN echo "deb http://research.cs.wisc.edu/htcondor/debian/8.8/buster buster contrib" > /etc/apt/sources.list.d/htcondor.list
RUN echo "deb-src http://research.cs.wisc.edu/htcondor/debian/8.8/buster buster contrib" >> /etc/apt/sources.list.d/htcondor.list
RUN sudo apt update
RUN sudo apt install -y htcondor

# Set up submit user
RUN adduser submituser --gecos "Submit User,,," --disabled-password

# HTCondor setup
# Copy over HTCondor submit node config
COPY ./config/htcondor/submit/99-workspaces-submit.dev.conf /etc/condor/config.d/99-workspaces-submit.dev.conf

# Change working directory to /code
WORKDIR /code

# set ownership of /code directory to vlapipe:vlapipe
RUN chown vlapipe . && chgrp vlapipe .

# Switch to vlapipe
USER vlapipe

# Copy service directory to /code in the image
# set ownership of content to vlapipe and the vlapipe group
COPY --chown=vlapipe:vlapipe ./services/workflow ./

# Change working directory to /packages
WORKDIR /packages/

# Copy shared, apps/cli/, and testing directories to /packages
# set ownership of content to vlapipe and the vlapipe group id
COPY --chown=vlapipe:vlapipe ./shared ./shared
COPY --chown=vlapipe:vlapipe ./apps/cli ./apps/cli
COPY --chown=vlapipe:vlapipe ./testing ./testing

# Change working directory to /code
WORKDIR /code

ENV PYTHONPATH "${PYTHONPATH}:/home/vlapipe/.local"
ENV PATH "${PATH}:/home/vlapipe/.local/bin"

RUN pip install --user -r requirements.txt \
    && python setup.py develop --install-dir="~/.local"

# Set Capo
ARG capo_env=dsoc-dev
ENV CAPO_PROFILE $capo_env
ENV PATH $PATH:/lustre/aoc/pipeline/$CAPO_PROFILE/workflow

USER root

CMD /code/bin/boot-condor-and-workflow.sh