forked from youjingru0314/forge-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
172 lines (144 loc) · 5.2 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Stage 1: Base
#ARG BASE_IMAGE
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 as base
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=on \
SHELL=/bin/zsh \
RUNNING_IN_DOCKER=true
# Install Ubuntu packages
RUN apt update && \
apt -y upgrade && \
apt install -y --no-install-recommends \
software-properties-common \
build-essential \
python3.10-venv \
python3-pip \
python3-tk \
python3-dev \
nginx \
bash \
zsh \
dos2unix \
git \
ncdu \
net-tools \
openssh-server \
libglib2.0-0 \
libsm6 \
libgl1 \
libxrender1 \
libxext6 \
ffmpeg \
wget \
curl \
psmisc \
rsync \
vim \
zip \
unzip \
htop \
screen \
tmux \
bc \
pkg-config \
libcairo2-dev \
libgoogle-perftools4 \
libtcmalloc-minimal4 \
apt-transport-https \
ca-certificates && \
update-ca-certificates && \
apt clean && \
rm -rf /var/lib/apt/lists/* && \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
# Set Python
RUN ln -s /usr/bin/python3.10 /usr/bin/python
# Stage 2: Install Stable Diffusion WebUI Forge and python modules
#FROM base as setup
WORKDIR /
RUN mkdir -p /sd-models
# Download the model file from the cloud storage service
# Replace <cloud-storage-url> with the actual URL of the model file in the cloud storage service
#ADD https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors /sd-models/
#COPY sd_xl_base_1.0.safetensors /sd-models/sd_xl_base_1.0.safetensors
# Create and use the Python venv
RUN python3 -m venv /venv
# Clone the git repo of Stable Diffusion WebUI Forge and set version
ARG FORGE_COMMIT
RUN git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git && \
cd /stable-diffusion-webui-forge
# Install the dependencies for Stable Diffusion WebUI Forge
ARG INDEX_URL
ARG TORCH_VERSION
ARG XFORMERS_VERSION
WORKDIR /stable-diffusion-webui-forge
ENV TORCH_INDEX_URL=${INDEX_URL}
ENV TORCH_COMMAND="pip install torch==${TORCH_VERSION} torchvision==0.16.0 --index-url ${TORCH_INDEX_URL}"
#ENV XFORMERS_PACKAGE="xformers==${XFORMERS_VERSION} --index-url ${TORCH_INDEX_URL}"
RUN source /venv/bin/activate && \
${TORCH_COMMAND} && \
pip3 install -r requirements_versions.txt --extra-index-url ${TORCH_INDEX_URL} && \
#pip3 install ${XFORMERS_PACKAGE} && \
deactivate
COPY forge/cache-sd-model.py forge/install-forge.py ./
RUN source /venv/bin/activate && \
python3 -m install-forge --skip-torch-cuda-test && \
deactivate
# Cache the Stable Diffusion Models
# SDXL models result in OOM kills with 8GB system memory, need 30GB+ to cache these
# RUN source /venv/bin/activate && \
# python3 cache-sd-model.py --no-half-vae --no-half --xformers --use-cpu=all --ckpt /sd-models/sd_xl_base_1.0.safetensors && \
# deactivate
# Copy Stable Diffusion WebUI Forge config files
COPY forge/relauncher.py forge/webui-user.sh forge/config.json forge/ui_config_pkjApril2024-FINAL.json forge/ui-config.json /stable-diffusion-webui-forge/
# ADD SDXL styles.csv
ADD https://raw.githubusercontent.com/Douleb/SDXL-750-Styles-GPT4-/main/styles.csv /stable-diffusion-webui/styles.csv
# Install Jupyter, gdown and OhMyRunPod
RUN pip3 install -U --no-cache-dir ipykernel \
ipywidgets \
gdown \
OhMyRunPod
# Install RunPod File Uploader
RUN curl -sSL https://github.com/kodxana/RunPod-FilleUploader/raw/main/scripts/installer.sh -o installer.sh && \
chmod +x installer.sh && \
./installer.sh
# Install rclone
RUN curl https://rclone.org/install.sh | bash
# Install runpodctl
ARG RUNPODCTL_VERSION
RUN wget "https://github.com/runpod/runpodctl/releases/download/${RUNPODCTL_VERSION}/runpodctl-linux-amd64" -O runpodctl && \
chmod a+x runpodctl && \
mv runpodctl /usr/local/bin
# Install croc
RUN curl https://getcroc.schollz.com | bash
# Install speedtest CLI
RUN curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash && \
apt install speedtest
# Install CivitAI Model Downloader
ARG CIVITAI_DOWNLOADER_VERSION
RUN git clone https://github.com/ashleykleynhans/civitai-downloader.git && \
cd civitai-downloader && \
git checkout tags/${CIVITAI_DOWNLOADER_VERSION} && \
cp download.py /usr/local/bin/download-model && \
chmod +x /usr/local/bin/download-model && \
cd .. && \
rm -rf civitai-downloader
# Remove existing SSH host keys
RUN rm -f /etc/ssh/ssh_host_*
# NGINX Proxy
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/502.html /usr/share/nginx/html/502.html
# Set template version
ARG RELEASE
ENV TEMPLATE_VERSION=${RELEASE}
# Set the venv path
ARG VENV_PATH
ENV VENV_PATH=${VENV_PATH}
# Copy the scripts
WORKDIR /
COPY --chmod=755 scripts/dockershell.sh scripts/fix_venv.sh scripts/model-import.sh /scripts/pre_start.sh /scripts/start_forge.sh /scripts
RUN mkdir -p /logs
# Start the container
SHELL ["/bin/bash", "--login", "-c"]
CMD [ "/bin/bash", "--login", "-c", "/start.sh 2>&1 | tee /logs/startup.log" ]