FROM python:3.13.2-alpine3.21

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    HOME=/home/app \
    APP_HOME=/home/app/web

RUN mkdir -p $HOME && \
    mkdir $APP_HOME && \
    addgroup --system app && \
    adduser --system -G app app && \
    apk update && \
    apk add --no-cache netcat-openbsd

WORKDIR $APP_HOME

COPY ./requirements.txt $APP_HOME
RUN pip install --upgrade pip && \
    pip install -r requirements.txt

COPY . $APP_HOME

RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.sh && \
    chown -R app:app $APP_HOME && \
    chmod +x  $APP_HOME/entrypoint.sh && \
    chown root:root $APP_HOME/fix_permissions.sh && \
    chmod +x  $APP_HOME/fix_permissions.sh && \
    chmod u+s $APP_HOME/fix_permissions.sh


USER app

ENTRYPOINT ["/home/app/web/entrypoint.sh"]
