# Do not change this file, its content is generating automatically
FROM {DISTRO_NAME}:{DISTRO_VERSION}

SHELL [ "/bin/bash", "-c" ]

ARG PYTHON_VERSION_TAG={PYTHON_VERSION}.1
ARG LINK_PYTHON_TO_PYTHON3=1

# Existing lsb_release causes issues with modern installations of Python3
# https://github.com/pypa/pip/issues/4924#issuecomment-435825490
# Set (temporarily) DEBIAN_FRONTEND to avoid interacting with tzdata
RUN apt-get -qq -y update && \
    DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
        libxml2-dev libxslt1-dev libldap2-dev\  
        libsasl2-dev libtiff5-dev libjpeg62 libopenjp2-7-dev\  
        zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev\  
        libharfbuzz-dev libfribidi-dev libxcb1-dev libpq-dev\
        openssl build-essential libssl-dev libxrender-dev \
        git-core libx11-dev libxext-dev libfontconfig1-dev libfreetype6-dev fontconfig\
        xvfb libfontconfig python3-virtualenv virtualenv libx11-xcb1 ffmpeg \
        git postgresql-client node-less npm ssh  \
        software-properties-common && \
    mv /usr/bin/lsb_release /usr/bin/lsb_release.bak && \
    apt-get -y autoclean && \
    apt-get -y autoremove && \
    rm -rf /var/lib/apt/lists/* \
    && python3 -m pip install pre-commit 

COPY install_python.sh install_python.sh
RUN bash install_python.sh $PYTHON_VERSION_TAG $LINK_PYTHON_TO_PYTHON3 && \
    rm -r install_python.sh Python-$PYTHON_VERSION_TAG

# Enable tab completion by uncommenting it from /etc/bash.bashrc
# The relevant lines are those below the phrase "enable bash completion in interactive shells"
RUN export SED_RANGE="$(($(sed -n '\|enable bash completion in interactive shells|=' /etc/bash.bashrc)+1)),$(($(sed -n '\|enable bash completion in interactive shells|=' /etc/bash.bashrc)+7))" && \
    sed -i -e "$SED_RANGE"' s/^#//' /etc/bash.bashrc && \
    unset SED_RANGE
  
# Переменные проекта
ARG USER_UID={CURRENT_USER_UID}
ARG USER_GID={CURRENT_USER_GID}

ARG USER_NAME={CURRENT_USER}
ARG PASSWORD={CURRENT_PASSWORD}

# Prepare internal user
RUN groupadd --gid $USER_GID $USER_NAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USER_NAME -p $(openssl passwd -6 $PASSWORD) \
    && apt-get update \
    && apt-get install -y sudo \
    && echo $USER_NAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER_NAME \
    && chmod 0440 /etc/sudoers.d/$USER_NAME\
    && mkdir /home/$USER_NAME/.ssh\
    && chown $USER_NAME:$USER_NAME /home/$USER_NAME/.ssh\
    && mkdir -p /home/$USER_NAME/.vscode-server\
    && chown -R $USER_NAME:$USER_NAME /home/$USER_NAME/.vscode-server

RUN apt-get install -y wget
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
 


# Here we download and install wkhtmltox from its website, because from debian packages it has less functionality, and does not
# render headers and footers
RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_{PROCESSOR_ARCH}.deb \
    && apt-get install -y ./wkhtmltox_0.12.6.1-2.jammy_{PROCESSOR_ARCH}.deb

USER $USER_NAME