FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu20.04

# suppose current folder contains these files:
#   miniconda_install.sh (required): conda install file, should be python3.8
#   pip.conf (optional): pip config file, if you are in China, you may need this
#   Beimingwu (required): Beimingwu source code folder
#   Learnware (required): Learnware source code folder
#   config.json (optional): config file for a specific deployment
#   swords.txt (optional): sensitive words file


COPY ./miniconda_install.sh /
RUN bash /miniconda_install.sh -b && rm /miniconda_install.sh
ENV PATH="/root/miniconda3/bin:$PATH"

RUN  sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN  sed -i s@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get update && apt-get install -y libffi-dev libssl-dev \
  ca-certificates sqlite3 xz-utils zlib1g-dev lsb-release wget gnupg

COPY ./pip.conf* /etc/
ADD ./Beimingwu/backend/requirements.txt /

RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | tee /etc/apt/trusted.gpg.d/postgres.asc
RUN apt-get update && apt-get install -y postgresql-client

RUN echo ${PATH}
RUN python3 -m pip install -r /requirements.txt
COPY ./Beimingwu/backend /learnware-backend/
COPY ./Beimingwu/deploy/kubernetes/learnware-check.yaml /learnware-backend/
COPY ./Learnware /learnware/

WORKDIR /learnware-backend
COPY ./config.json* /learnware-backend/
COPY ./swords.txt* /learnware-backend/swords.txt
COPY ./models--bert-base-uncased* /root/.learnware/cache/

RUN python3 -m pip install -e /learnware/

EXPOSE 8088

ENV PYTHONPATH=/learnware-backend

CMD ["gunicorn", "--bind", "0.0.0.0:8088", "--workers", "1", "--backlog", "1024", "--worker-connections", "60", "--threads", "1", "--timeout", "36000", "--log-level", "DEBUG", "--worker-class", "gevent", "scripts.main:create_app()"]