# Dockerfile

ARG AWS_ACCOUNT=086679231553

FROM ${AWS_ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python311 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

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

RUN python -m pip install --upgrade pip setuptools

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

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

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

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

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

USER worker

# Use startup script as entrypoint
ENTRYPOINT ["/uwsgi-start.sh"]

EXPOSE 8080

#################################
### Build image for lint-and-test ###
#################################
FROM base AS lint-and-test

COPY lint-and-test.sh /

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

USER        worker
ENTRYPOINT  ["/lint-and-test.sh"]
