# Dockerfile

FROM       python:3.12-slim-bookworm

WORKDIR    /var/app

# Update and install common packages
RUN        apt-get update && apt-get install gcc g++ curl git tar zip -y

# Install pipenv
RUN        pip install setuptools pipenv

# Configure UWSGI
RUN        useradd uwsgi -s /bin/false
RUN        mkdir /var/log/uwsgi
RUN        chown -R uwsgi:uwsgi /var/log/uwsgi


# Add application and install requirements
COPY       . /var/app
RUN        if [ -f /var/app/Pipfile.lock ]; then pipenv install --ignore-pipfile --system; fi

RUN        chmod +x /var/app/uwsgi-start.sh
ENTRYPOINT ["/var/app/uwsgi-start.sh"]

ARG CURRENT_COMMIT_HASH
ENV CURRENT_COMMIT_HASH=${CURRENT_COMMIT_HASH}
# snowflake-connector-python 4.x stats Path.home()/.snowflake at import time.
# uwsgi workers drop to the uwsgi user and cannot access /root, causing a
# PermissionError on Python 3.12 where Path.exists() re-raises instead of
# returning False. Setting HOME to /tmp makes the stat safe for all users.
ENV HOME=/tmp

EXPOSE     8080
