ARG AWS_ACCOUNT=086679231553

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

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1

USER root

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

USER worker
WORKDIR /var/app

COPY requirements.txt ./

RUN python3 -m venv ./venv
RUN venv/bin/python -m pip install --upgrade pip setuptools && \
    venv/bin/python -m pip install -I -r requirements.txt

USER root
RUN apt-get -y remove --purge gcc \
    && apt-get -y autoremove \
    && apt-get -y clean \
    && rm -rf /var/lib/apt/lists/*
USER worker

#######################################
### Build image for live deployment ###
#######################################
FROM base AS deploy
COPY product_configuration ./product_configuration
COPY application.py uwsgi.ini ./
COPY uwsgi-start.sh /
ENTRYPOINT ["/uwsgi-start.sh"]

EXPOSE 8080

FROM base AS unitlint
COPY requirements-dev.txt ./
RUN venv/bin/python -m pip install -r requirements-dev.txt
COPY application.py docker-compose.yml dev.py .flake8 ./
COPY product_configuration ./product_configuration
COPY scripts ./scripts
COPY tests ./tests

ENTRYPOINT [ "scripts/lint-and-test.sh" ]
