From cc08ed6a109881f95b41ad6adc6f5a7b7a351969 Mon Sep 17 00:00:00 2001 From: simonmcnair <101189766+simonmcnair@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:23:04 +0000 Subject: [PATCH] Update Dockerfile remove root user requirement --- services/AUTOMATIC1111/Dockerfile | 45 +++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/services/AUTOMATIC1111/Dockerfile b/services/AUTOMATIC1111/Dockerfile index 54d41ba..a33fb1d 100644 --- a/services/AUTOMATIC1111/Dockerfile +++ b/services/AUTOMATIC1111/Dockerfile @@ -24,8 +24,45 @@ RUN --mount=type=cache,target=/var/cache/apt \ # we need those apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ # extensions needs those - ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential + ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential \ + apt-get clean +ARG PUID=0 +ARG PGID=0 +ARG USER_HOME=/root +# set build args as container environment variables for entrypoint reference +ENV PUID=$PUID +ENV PGID=$PGID +ENV USER_HOME=$USER_HOME + +# if user home does not exist, create it +RUN mkdir -p "$USER_HOME" + +# home already exists, chown it +RUN chown -R "${PUID}:${PGID}" "$USER_HOME" + +# Only groupadd if we're non root +RUN if [ "$PGID" -ne "0" ]; then \ + echo non root group detected; \ + groupadd \ + --gid "$PGID" \ + stablediffusion ;\ + else \ + echo "root group detected" ; \ + fi + +# Only useradd if we're non root +RUN if [ "$PUID" -ne "0" ]; then \ + echo non root user detected; \ + useradd \ + --gid="$PGID" \ + --no-user-group \ + -M \ + --home "$USER_HOME" \ + stablediffusion ; \ + else \ + echo "root group detected" ; \ + fi WORKDIR / RUN --mount=type=cache,target=/root/.cache/pip \ @@ -36,9 +73,13 @@ RUN --mount=type=cache,target=/root/.cache/pip \ RUN pip install --upgrade typing-extensions +RUN chown -R "$PUID:$PGID" /stable-diffusion-webui + +# drop permissions (if build targets non root) +USER $PUID:$PGID ENV ROOT=/stable-diffusion-webui -COPY --from=download /repositories/ ${ROOT}/repositories/ +COPY --from=download --chown=${PUID}:${PGID} /repositories/ ${ROOT}/repositories/ RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate RUN --mount=type=cache,target=/root/.cache/pip \