FROM python:3.11-bookworm

ARG USER_ID=1000
ARG GROUP_ID=1000
ARG USER_NAME=dev

RUN apt-get update && apt-get install -y --no-install-recommends \
    bash-completion \
    build-essential \
    cargo \
    ca-certificates \
    curl \
    fd-find \
    fzf \
    git \
    golang \
    jq \
    less \
    libffi-dev \
    libssl-dev \
    make \
    neovim \
    nodejs \
    npm \
    procps \
    ripgrep \
    rsync \
    rustc \
    sqlite3 \
    tar \
    tmux \
    unzip \
    wget \
    which \
    zip && \
    rm -rf /var/lib/apt/lists/* && \
    ln -sf /usr/bin/fdfind /usr/local/bin/fd

RUN groupadd -g "${GROUP_ID}" "${USER_NAME}" 2>/dev/null || true && \
    useradd -m -u "${USER_ID}" -g "${GROUP_ID}" -s /bin/bash "${USER_NAME}"

USER ${USER_NAME}
WORKDIR /home/${USER_NAME}

# Build a project virtualenv and preinstall dependencies.
COPY --chown=${USER_NAME}:${USER_NAME} requirements.txt /tmp/requirements.txt
RUN bash -lc 'set -e; \
    python3.11 -m venv /home/${USER_NAME}/.venv/gia && \
    /home/${USER_NAME}/.venv/gia/bin/pip install --upgrade pip setuptools wheel && \
    grep -Ev "^(git\\+https://git\\.zm\\.is/|aiograpi$)" /tmp/requirements.txt > /tmp/requirements.build.txt && \
    /home/${USER_NAME}/.venv/gia/bin/pip install -r /tmp/requirements.build.txt'

ENV VIRTUAL_ENV=/home/${USER_NAME}/.venv/gia
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"

CMD ["/bin/bash"]
