mirror of
https://github.com/AbdBarho/stable-diffusion-webui-docker.git
synced 2026-02-03 14:14:18 +01:00
Expose build args to container which allow the web service
to run as given uid:gid.
By default, this behavior is "off". Building via docker compose still
defaults to root:root on everything. Unless these args are explicitly
set, no users should notice a difference.
Build arguments are also exposed as Docker environment variables, so they can
be freely referenced in the `entrypoint.sh`
Output files will be owned by PUID and PGID, so if set, no more root:root
images (unless desired).
New arguments:
- ARG PUID=0
- ARG PGID=0
- ARG USER_HOME=/root
New environment variable:
- RSYNC_FLAGS
- NFS share doesn't like `-a` changing every bit on a directory
Example docker-compose.override.yaml using these flags
```
version: '3.9'
services:
auto:
environment:
RSYNC_FLAGS: -vrlgotO
build:
args:
USER_HOME: /opt/stablediffusion
PUID: 1000
PGID: 1002
volumes:
- /media/data:/data
- /tmp:/output
download:
volumes:
- /media/data:/data
```
77 lines
2.2 KiB
Bash
Executable file
77 lines
2.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -Eeuo pipefail
|
|
RSYNC_FLAGS="${RSYNC_FLAGS:--a}"
|
|
|
|
# TODO: move all mkdir -p ?
|
|
mkdir -p /data/config/auto/scripts/
|
|
# mount scripts individually
|
|
find "${ROOT}/scripts/" -maxdepth 1 -type l -delete
|
|
cp -vrfTs /data/config/auto/scripts/ "${ROOT}/scripts/"
|
|
|
|
# Set up config file
|
|
python /docker/config.py /data/config/auto/config.json
|
|
|
|
if [ ! -f /data/config/auto/ui-config.json ]; then
|
|
echo '{}' >/data/config/auto/ui-config.json
|
|
fi
|
|
|
|
if [ ! -f /data/config/auto/styles.csv ]; then
|
|
touch /data/config/auto/styles.csv
|
|
fi
|
|
|
|
# copy models from original models folder
|
|
mkdir -p /data/models/VAE-approx/ /data/models/karlo/
|
|
|
|
rsync "$RSYNC_FLAGS" --info=NAME ${ROOT}/models/VAE-approx/ /data/models/VAE-approx/
|
|
rsync "$RSYNC_FLAGS" --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/
|
|
|
|
declare -A MOUNTS
|
|
|
|
MOUNTS["${USER_HOME}/.cache"]="/data/.cache"
|
|
MOUNTS["${ROOT}/models"]="/data/models"
|
|
|
|
MOUNTS["${ROOT}/embeddings"]="/data/embeddings"
|
|
MOUNTS["${ROOT}/config.json"]="/data/config/auto/config.json"
|
|
MOUNTS["${ROOT}/ui-config.json"]="/data/config/auto/ui-config.json"
|
|
MOUNTS["${ROOT}/styles.csv"]="/data/config/auto/styles.csv"
|
|
MOUNTS["${ROOT}/extensions"]="/data/config/auto/extensions"
|
|
MOUNTS["${ROOT}/config_states"]="/data/config/auto/config_states"
|
|
|
|
# extra hacks
|
|
MOUNTS["${ROOT}/repositories/CodeFormer/weights/facelib"]="/data/.cache"
|
|
|
|
for to_path in "${!MOUNTS[@]}"; do
|
|
set -Eeuo pipefail
|
|
from_path="${MOUNTS[${to_path}]}"
|
|
rm -rf "${to_path}"
|
|
if [ ! -f "$from_path" ]; then
|
|
mkdir -vp "$from_path"
|
|
fi
|
|
mkdir -vp "$(dirname "${to_path}")"
|
|
ln -sT "${from_path}" "${to_path}"
|
|
echo Mounted $(basename "${from_path}")
|
|
done
|
|
|
|
echo "Installing extension dependencies (if any)"
|
|
|
|
# because we build our container as root:
|
|
chown -R $PUID:$PGID ~/.cache/
|
|
chmod 776 ~/.cache/
|
|
|
|
shopt -s nullglob
|
|
# For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy
|
|
list=(./extensions/*/install.py)
|
|
for installscript in "${list[@]}"; do
|
|
PYTHONPATH=${ROOT} python "$installscript"
|
|
done
|
|
|
|
if [ -f "/data/config/auto/startup.sh" ]; then
|
|
pushd ${ROOT}
|
|
echo "Running startup script"
|
|
. /data/config/auto/startup.sh
|
|
popd
|
|
fi
|
|
|
|
exec "$@"
|