ARG WMS_BASE_IMAGE="harbor.cta-observatory.org/dpps/wms-base:dev"
FROM ${WMS_BASE_IMAGE}

ARG USERID=1000
ARG GROUPID=1000

LABEL maintainer="Natthan Pigoux <natthan.pigoux@lupm.in2p3.fr>, Luisa Arrabito <arrabito@in2p3.fr>"
LABEL description="CTADIRAC client docker image"
LABEL org.opencontainers.image.url=https://gitlab.cta-observatory.org/cta-computing/dpps/CTADIRAC

ENV DIRAC_DIR="/home/dirac"
ENV PYTHONUSERBASE="${DIRAC_DIR}/.local"
ENV PATH="${PYTHONUSERBASE}/bin:${PATH}"
ENV X509_CERT_DIR="${DIRACOS}/etc/grid-security/certificates" \
  X509_VOMSES="${DIRACOS}/etc/grid-security/vomses" \
  X509_VOMS_DIR="${DIRACOS}/etc/grid-security/vomsdir"

RUN \
  if getent group ${GROUPID}; then \
    groupmod --new-name dirac $(getent group ${GROUPID} | cut -d: -f1); \
  else \
    groupadd --gid ${GROUPID} dirac; \
  fi\
  && adduser --uid ${USERID} --gid dirac -s /bin/bash -d /home/dirac dirac \
  && mkdir -p ${DIRAC_DIR} \
  && chown -R dirac:dirac ${DIRAC_DIR} \
  && mkdir -p \
    ${DIRAC_DIR}/.globus \
    ${PYTHONUSERBASE} \
    "${DIRACOS}/etc/grid-security/certificates" \
    "${DIRACOS}/etc/grid-security/vomses" \
    "${DIRACOS}/etc/grid-security/vomsdir" \
  && chown -R dirac:dirac \
    ${DIRAC_DIR}/.globus \
    ${PYTHONUSERBASE} \
    "${DIRACOS}/etc"

WORKDIR ${DIRAC_DIR}

RUN dnf install -y bzip2 git && dnf clean all -y

RUN "${DIRACOS}/bin/pip" install --no-cache-dir dirac-cwl==1.3.0

COPY --chown=dirac:dirac --chmod=755 Entrypoint.sh /Entrypoint.sh

USER dirac

ENTRYPOINT ["/Entrypoint.sh"]
