# 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 -y upgrade
RUN apt-get -y install zip libffi-dev gcc

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

RUN python -m pip install --upgrade pip setuptools
RUN /var/venv/bin/pip install uwsgi==2.0.23

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


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

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

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

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

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

EXPOSE      8080


###########################
### Build image for dev ###
###########################
FROM base AS dev

RUN pip install -r /var/app/requirements-dev.txt

# Enables prints in python to flush to stdout
ENV PYTHONUNBUFFERED 1

# Start dev server
ENTRYPOINT  ["/var/venv/bin/python"]
CMD         ["dev.py", "2>&1"]


#################################
### Build image for unit-lint ###
#################################
FROM base AS unit-lint

# Install dev/test requirements
RUN pip install -r requirements-dev.txt

ENTRYPOINT  ["scripts/unit-lint.sh"]


########################################
### Build image for test-integration ###
########################################

FROM base AS test-integration

# Install dev/test requirements
RUN pip install -r requirements-dev.txt

ENTRYPOINT [ "scripts/test-integration.sh" ]


########################################
### Build image for bulk-update-physical-pricing ###
########################################

FROM base AS bulk-update-physical-pricing

# Install dev/test requirements
RUN pip install -r requirements.txt

ENTRYPOINT  ["/var/venv/bin/python"]
CMD         ["scripts/bulk_update_physical_pricing.py", "2>&1"]


########################################
### Build image for ingest-physical-pricing-jenkins ###
########################################

FROM base AS ingest-physical-pricing-jenkins

# Install dev/test requirements
RUN pip install -r requirements.txt

ENTRYPOINT  ["/var/venv/bin/python"]
CMD         ["scripts/ingest_physical_pricing_jenkins.py", "2>&1"]
