ARG MATLAB_VERSION

FROM mathworks/matlab:$MATLAB_VERSION

# Use root for installing in the system.
USER root

RUN  apt update \
  && apt install software-properties-common --yes \
  && add-apt-repository ppa:deadsnakes/ppa \
  && apt update \
  && apt install --yes \
                 git \
                 python3-pip \
                 python3-venv \
                 python3.8 \
                 libpython3.8 \
                 python3.9 \
                 libpython3.9 \
                 python3.10 \
                 libpython3.10 \
                 python3.11 \
                 libpython3.11 \
  && apt clean \
  && apt --yes autoremove \
  && rm -rf /var/lib/apt/lists/*

ARG TOX_VERSION=4.11.1

RUN  pip install pipx \
  && pipx install 'tox<4' \
  && pipx install 'tox<4' --suffix 3 \
  && pipx install tox==$TOX_VERSION --suffix 4 \
  && rm -rf $HOME/.cache/pip

# Explicitely update PATH because gitlab runner run the container in a way
# that prevent .bashrc to be sourced.
ENV PATH="/root/.local/bin:${PATH}"

# The matlabengine package from PyPI expects matlab to be installed in /usr/local/MATLAB
RUN  mkdir -p /usr/local \
  && ln -s /opt/matlab /usr/local/MATLAB

ARG MLM_LICENSE_FILE="27000@licence-matlab.pf.irt-aese.local"
ENV MLM_LICENSE_FILE=$MLM_LICENSE_FILE

# Reset for having a standard usage.
ENTRYPOINT []
CMD ["bash"]
