FROM codercom/code-server:latest

ARG FROM_DIR=./
USER root
# Update the package list and install required packages
RUN sudo apt-get update && apt-get install -y \
    apt-utils \
    rsync \
    openssh-client \
    software-properties-common \ 
    build-essential \
    zlib1g-dev \
    libncurses5-dev \
    libgdbm-dev \ 
    libnss3-dev \
    libssl-dev \
    libreadline-dev \
    libffi-dev \
    libsqlite3-dev \
    libbz2-dev \
    curl \
    wget \
    jq

# ----------------------------------------
RUN mkdir -p /tmp
WORKDIR /tmp
RUN wget https://www.python.org/ftp/python/3.12.5/Python-3.12.5.tgz

RUN tar -xf Python-3.12.5.tgz
WORKDIR /tmp/Python-3.12.5

RUN ./configure --enable-optimizations --prefix=/usr
RUN make -j$(nproc)
RUN make altinstall

# ----------------------------------------
RUN rm /usr/bin/python3
RUN ln -s /usr/bin/python3.12 /usr/bin/python3

RUN ln -snf /usr/bin/pip3.12 /usr/bin/pip

COPY ./requirements.txt /
RUN pip install --upgrade pip --root-user-action=ignore
RUN pip install -r /requirements.txt --root-user-action=ignore

RUN mkdir -p /home/coder/.ssh
RUN chmod 700 /home/coder/.ssh
RUN chown 1001:1001 /home/coder/.ssh

COPY ./id_rsa /home/coder/.ssh/
COPY ./id_rsa.pub /home/coder/.ssh/
RUN chown 1001:1001 /home/coder/.ssh/id_rsa*
RUN chmod 600 /home/coder/.ssh/id_rsa*

COPY ./.gitconfig /home/coder
RUN chown 1001:1001 /home/coder/.gitconfig

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

WORKDIR /home/coder
