# Pull base image
FROM python:3.11.10-slim-bullseye as build-image

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory to the root of your project
WORKDIR var/task/Model

# Install python dependencies - we also install the fastapi dependencies here, since we use similar
# functionality (though the api isn't served via fastapi). We will probably simplify this in the future
COPY ./backend/engine/requirements.txt ./requirements1.txt
COPY ./backend/app/requirements/requirements.txt ./requirements2.txt

RUN cat requirements1.txt requirements2.txt > requirements.txt \
    && pip install --upgrade pip \
    && pip install -r requirements.txt \
    && rm -rf /root/.cache

# Since we are not using a base AWS image, there is some additional setup required. We need to set up the runtime
# interface client
# https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-clients
# Additionally install the AWS Lambda RIC
RUN pip install awslambdaric

# Second stage: "runtime-image"
FROM python:3.11.10-slim-bullseye

# Create the extensions directory to avoid warnings with RIE
RUN mkdir -p /opt/extensions

# Set work directory to the root of your project
WORKDIR /var/task/Model

# Copy the python dependencies from the build-image
COPY --from=build-image /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/

# Copy project files
COPY ./backend/ ./backend
COPY ./recommendations/ ./recommendations
COPY ./utils/ ./utils/
COPY ./etl/epc/ ./etl/epc/
COPY ./etl/epc_clean/ ./etl/epc_clean/
COPY ./etl/bill_savings/ ./etl/bill_savings/
COPY ./etl/spatial/ ./etl/spatial/
COPY ./BaseUtility.py ./BaseUtility.py
COPY ./datatypes/ ./datatypes/
COPY ./etl/find_my_epc/ ./etl/find_my_epc/

# Set the ENTRYPOINT to the AWS Lambda RIC and CMD to your function handler
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
# Define the handler location
CMD ["backend.engine.handler.handler"]