# Dockerfile
ARG AWS_ACCOUNT=086679231553
FROM ${AWS_ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python312 AS base

WORKDIR    /var/app

USER       root

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

# Install pipenv
RUN        pip install pipenv

# Configure UWSGI
RUN        useradd uwsgi -s /bin/false

# Add application and install requirements
COPY       . /var/app
RUN        if [ -f /var/app/Pipfile.lock ]; then \
  apt-get -y install gcc \
    && pipenv install --ignore-pipfile --system \
    && apt-get -y remove gcc \
    && apt-get -y autoremove \
    && apt-get -y clean \
    && rm -rf /var/lib/apt/lists/* ; \
fi

USER       worker

RUN        mkdir /var/app/.snowflake
RUN        chmod 777 /var/app/.snowflake
ENV        SNOWFLAKE_HOME=/var/app/

# Add startup script
COPY       --chmod=755 uwsgi-start.sh /
ENTRYPOINT ["/uwsgi-start.sh"]

EXPOSE     8080
