FROM ubuntu:22.04@sha256:aa772c98400ef833586d1d517d3e8de670f7e712bf581ce6053165081773259d

RUN apt update && \
    apt install -y \
        git gawk make texinfo bison flex build-essential python3 libz-dev libexpat-dev autoconf device-tree-compiler ninja-build libpixman-1-dev build-essential ncurses-base ncurses-bin libncurses5-dev dialog curl wget ftp libgmp-dev python3-pip pkg-config libglib2.0-dev opam z3 zlib1g-dev automake autotools-dev libmpc-dev libmpfr-dev gperf libtool patchutils verilator cpio bc vim emacs gedit nano && \
    apt-get clean

# COPY requirements.txt /root
RUN pip3 install --no-cache-dir \
    sphinx sphinx_rtd_theme matplotlib scipy scikit-learn adjustText lief

RUN ln -s /usr/bin/python3 /usr/bin/python

# Create a user group 'xyzgroup'
ENV USERNAME=cad
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID ${USERNAME} \
    && useradd --uid $USER_UID --gid $USER_GID -m ${USERNAME} \
    # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
    && apt-get update \
    && apt-get install -y sudo \
    && echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \
    && chmod 0440 /etc/sudoers.d/${USERNAME}

# Change RISCV user
RUN chown -Rf cad:cad /opt

# Add cad user
USER ${USERNAME}
WORKDIR /home/${USERNAME}