# Use an official Python runtime as a parent image
FROM python:3.11-slim

ARG APP_USER
ARG UID
ARG GID

# Update the package list and install necessary packages
RUN apt-get update && apt-get install -y \
    build-essential \
    libffi-dev \
    libssl-dev \
    python3-dev \
    git \
    pkg-config \
    libmariadb-dev \
    aria2 \
    wget \
    bzip2 \
    firefox-esr

# Set timezone to Budapest
RUN ln -fs /usr/share/zoneinfo/Europe/Budapest /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata

# Install GeckoDriver
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz && \
    tar -xvzf /tmp/geckodriver.tar.gz -C /usr/local/bin && \
    chmod +x /usr/local/bin/geckodriver && \
    rm /tmp/geckodriver.tar.gz

# Install pip for Python 3.10
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
RUN ln -s /usr/local/bin/pip /usr/bin/pip
RUN python -m pip install --upgrade pip

RUN mkdir /app; \
    mkdir /venv; \
    useradd --create-home --home /app --non-unique --uid $UID $APP_USER && \
    usermod -aG $APP_USER $APP_USER && \
    chown -R $APP_USER:$APP_USER /app; \ 
    chown -R $APP_USER:$APP_USER /venv


COPY --chown=$APP_USER:$APP_USER start.sh /start.sh
RUN chmod +x /start.sh

# Set the working directory in the container
WORKDIR /app

USER $APP_USER

# Expose port for the server
EXPOSE 5005

# Command to run the server
CMD ["bash", "/start.sh"]
