FROM nvidia/cuda:11.6.1-runtime-ubuntu20.04
ENV DEBIAN_FRONTEND=noninteractive

#Install core packages
RUN apt-get update && apt-get install -y \
      libncurses5 python3 python3-pip curl git apt-utils ssh ca-certificates \
      tmux nano vim sudo bash rsync htop wget unzip python3.8-venv \
      python3-virtualenv python3-distutils python3-numpy tini && \
    update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
    update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 && \
    pip3 install --no-cache-dir --upgrade pip

#Install Torch(chonky!)
RUN pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

#Install Python deps
RUN pip3 install --no-cache-dir dotmap icecream sentry-sdk numpy fastapi "uvicorn[standard]" gunicorn
RUN pip3 install omegaconf transformers einops
#RUN git clone https://github.com/NovelAI/stable-diffusion
#RUN pip3 install -e stable-diffusion/.
RUN pip3 install pytorch_lightning
RUN pip3 install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
#RUN wget -O stable-diffusion-private-hypernets.zip https://www.dropbox.com/s/lbxm6oijjawmeew/stable-diffusion-private-buckets.zip?dl=1
#RUN unzip stable-diffusion-private-hypernets.zip
ADD stable-diffusion-private stable-diffusion-private
RUN pip3 install -e stable-diffusion-private/
RUN pip3 install https://github.com/NovelAI/k-diffusion-multigen/archive/f8510e590b2bc6e7061156ca73f87e0a431a4bf8.zip
RUN pip3 install simplejpeg
RUN pip3 install min-dalle
#RUN pip3 install https://github.com/microsoft/DeepSpeed/archive/55b7b9e008943b8b93d4903d90b255313bb9d82c.zip
#basedformer
RUN pip3 install https://www.dropbox.com/s/8ozhhbo1g7y5dsz/basedformer-f7c8c4fe12f8a0acf6588d8d09a8b9b0481895e3.zip?dl=1
#built DS
#RUN pip3 install https://www.dropbox.com/s/euzpgpfrs9isf1z/deepspeed-0.7.3%2B55b7b9e0-cp38-cp38-linux_x86_64.whl?dl=1
RUN pip3 install faiss-cpu sentence_transformers
RUN wget https://f004.backblazeb2.com/file/naipublicbucketxyz/xformers.zip
RUN unzip xformers.zip
WORKDIR xformers
RUN python3 setup.py develop


#Open ports
EXPOSE 8080
EXPOSE 80
EXPOSE 443
EXPOSE 4369
EXPOSE 5672
EXPOSE 25672
EXPOSE 15672
EXPOSE 15692
EXPOSE 50051
#Copy node src and run
WORKDIR /usr/src/app
COPY . .

CMD [ "gunicorn", "main:app", "--workers 1", "--worker-class uvicorn.workers.UvicornWorker", "--bind 0.0.0.0:80", "--timeout 0", "--keep-alive 60", "--log-level=debug" ]
#CMD [ "python3", "main.py" ]
