Model/backend/docker/lambda.Dockerfile
Khalim Conn-Kowlessar c56641d8dc added pkgconf
2023-08-24 17:40:34 +01:00

63 lines
2.5 KiB
Docker

# Some additional work is required to get mip to run on arm64 architecture.
# This is because the mip library relies on the CBC solver, which is not available for arm64.
# https://python-mip.readthedocs.io/en/latest/install.html
# Pull base image
FROM arm64v8/python:3.10.12-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 system dependencies
RUN apt-get update && apt-get install -y make gcc g++ gfortran libgfortran-9-dev liblapack-dev libamd2 libcholmod3 \
libmetis-dev libsuitesparse-dev libnauty2-dev git wget pkgconf
# Compile CBC for arm64
RUN mkdir -p ~/build && cd ~/build \
&& wget -nH https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew \
&& bash coinbrew fetch Cbc@master --no-prompt \
&& bash coinbrew build Cbc@master --no-prompt --prefix=/home/root/prog/ --tests=none --enable-cbc-parallel --enable-relocatable
# Install python dependencies
COPY ./backend/requirements/base.txt ./backend/requirements/base.txt
RUN pip install --upgrade pip \
&& pip install -r backend/requirements/base.txt && rm -rf /root/.cache
# Install the AWS Lambda RIC
RUN pip install awslambdaric
# Second stage: "runtime-image"
FROM arm64v8/python:3.10.12-slim-bullseye
# 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.10/site-packages/ /usr/local/lib/python3.10/site-packages/
COPY --from=build-image /home/root/prog/lib/ /usr/local/lib/
# Set environment variable for mip to use custom CBC binaries
ENV PMIP_CBC_LIBRARY="/usr/local/lib/libCbcSolver.so"
ENV LD_LIBRARY_PATH="/usr/local/lib/":$LD_LIBRARY_PATH
# Copy project files
COPY ./backend/ ./backend
COPY ./recommendations/ ./recommendations
COPY ./model_data/BaseUtility.py ./model_data/BaseUtility.py
COPY ./model_data/config.py ./model_data/config.py
COPY ./model_data/optimiser/ ./model_data/optimiser/
COPY ./model_data/__init__.py ./model_data/__init__.py
COPY ./model_data/EpcClean.py ./model_data/EpcClean.py
COPY ./model_data/utils.py ./model_data/utils.py
COPY ./model_data/epc_attributes/ ./model_data/epc_attributes/
COPY ./datatypes/ ./datatypes/
COPY ./utils/ ./utils/
# 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.app.main.handler"]