# Dockerfile

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

WORKDIR /var/app

USER root
# Update and install common packages
RUN apt-get -y update \
  && apt-get -y upgrade \
  && apt-get -y install zip libffi-dev gcc \
  && apt-get -y clean \
  && rm -rf /var/lib/apt/lists/*

# Create and configure virtualenv and uwsgi
ENV VIRTUAL_ENV /var/venv
RUN python3.13 -m venv ${VIRTUAL_ENV}
ENV PATH "$VIRTUAL_ENV/bin:$PATH"

RUN python -m pip install --upgrade pip setuptools

# Add application and install requirements
COPY requirements.txt ./
RUN  pip install -I -r requirements.txt
COPY . /var/app

RUN apt-get -y update \
    && apt-get -y install gcc \
    && pip install uwsgi==2.0.28 \
    && apt-get -y remove --purge gcc \
    && apt-get -y autoremove \
    && apt-get -y clean \
    && rm -rf /var/lib/apt/lists/*

#######################################
### Build image for live deployment ###
#######################################
FROM base AS deploy

# Remove tests, scripts, etc.
RUN rm -rf /var/app/tests/ /var/app/devserver.py /var/app/.flake8

# Use startup script as entrypoint
COPY uwsgi-start.sh /
RUN  chmod +x /uwsgi-start.sh

USER worker
ENTRYPOINT  ["/uwsgi-start.sh"]

EXPOSE 8080
