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

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

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


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

# Remove tests, scripts, etc.
RUN         apt-get purge gcc -y
RUN         rm -rf /var/app/tests/ /var/app/dev.py /var/app/.flake8

USER        worker
ENTRYPOINT  ["scripts/run-with-timeout.sh"]


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

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

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

ENTRYPOINT  ["python", "dev.py"]


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

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

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