FROM nvidia/cuda:12.3.0-runtime-ubuntu22.04

ENV VERSION=v1.7.0
ARG VERSION

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update -y \
 && apt-get -qq install -y --no-install-recommends \
    git git-lfs libgl1 pkg-config python-is-python3 python3-dev python3-pip \
 && rm -rf /var/lib/apt/lists/*

RUN git clone --branch ${VERSION} --single-branch --depth 1 -c advice.detachedHead=false \
    https://github.com/AUTOMATIC1111/stable-diffusion-webui.git /app

WORKDIR /app

ENV PIP_NO_CACHE_DIR=true
ENV PIP_ROOT_USER_ACTION=ignore
RUN sed -i -e 's/    start()/    #start()/g' /app/launch.py \
 && python launch.py --skip-torch-cuda-test \
 && sed -i -e 's/    #start()/    start()/g' /app/launch.py

ADD requirements_*.txt /tmp/
RUN pip install --extra-index-url https://pypi.nvidia.com -r /tmp/requirements_add.txt \
 && pip uninstall -r /tmp/requirements_remove.txt -y

EXPOSE 7860

ENTRYPOINT ["python", "launch.py", "--listen", "--data-dir", "/app/data", "--disable-console-progressbars", "--enable-insecure-extension-access", "--api"]