diff --git a/launchtools/AMDGPU-StandardDockerfile.docker b/launchtools/AMDGPU-StandardDockerfile.docker new file mode 100644 index 000000000..fcc3589db --- /dev/null +++ b/launchtools/AMDGPU-StandardDockerfile.docker @@ -0,0 +1,49 @@ +FROM rocm/dev-ubuntu-24.04:7.2.2-complete + +ARG UID=1000 + +# Install python3.12 +RUN apt update +RUN apt install -y git wget build-essential python3.12 python3.12-venv python3.12-dev python3-pip ffmpeg + +# Install dependencies for controlnet preprocessors +RUN apt install -y libglib2.0-0 libgl1 + +# Install ROCm +RUN apt install -y rocm amdgpu-dkms amdgpu-dkms-firmware +RUN apt install -y rocm-hip rocm-hip-sdk hipblas hipblas-dev +RUN apt install -y hipfft-dev hipfft +RUN apt install -y hipsolver hipsolver-dev +RUN apt install -y ocl-icd-libopencl1 ocl-icd-opencl-dev opencl-c-headers opencl-clhpp-headers rocm-opencl rocm-opencl-dev + +# Set ROCm access +RUN wget https://repo.radeon.com/amdgpu/30.30.1/ubuntu/pool/main/a/amdgpu-insecure-instinct-udev-rules/amdgpu-insecure-instinct-udev-rules_30.30.1.0-2303411.22.04_all.deb +RUN apt install -y ./amdgpu-insecure-instinct-udev-rules_30.30.1.0-2303411.22.04_all.deb + +# Install DotNET8 and SDK +RUN apt install -y dotnet8 dotnet-sdk-8.0 + +# Copy swarm's files into the docker container +COPY . ./SwarmUI + +RUN chown -R $UID:$UID ./SwarmUI + +# Stupidproofing on git calls from inside docker +RUN git config --global --add safe.directory '*' + +# Ensure a user exists within docker for the given uid +RUN deluser ubuntu +RUN useradd -u $UID swarmui + +# Add user to groups +RUN usermod -aG video,render swarmui + +# If built binaries were copied in, discard them, they are likely bad. +# Build inside the container later (so eg extensions are included properly). +RUN rm -rf ./SwarmUI/src/bin ./SwarmUI/src/obj + +# Expose the port for other containers (to use Swarm as an API if you want) +EXPOSE 7801 + +# Set the run file to the launch script +ENTRYPOINT ["bash", "/SwarmUI/launchtools/docker-standard-inner.sh"] diff --git a/launchtools/launch-standard-docker.sh b/launchtools/launch-standard-docker.sh index 5853ea47d..c95df3cc3 100755 --- a/launchtools/launch-standard-docker.sh +++ b/launchtools/launch-standard-docker.sh @@ -7,18 +7,29 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd "$SCRIPT_DIR/.." -docker build --build-arg UID=$UID -f launchtools/StandardDockerfile.docker -t swarmui . +# Set default GPU +GPU="nvidia" +if [[ $1 == "amd" ]] +then + GPU="rocm" + docker build --build-arg UID=$UID -f launchtools/AMDGPU-StandardDockerfile.docker -t swarmui-rocm . +else + docker build --build-arg UID=$UID -f launchtools/StandardDockerfile.docker -t swarmui-nvidia . +fi + +if [[ $1 != "fixch" ]] +then + shift # Remove the GPU ID arg to prevent bugs +fi # Run this script with 'fixch' to run as root in the container and chown to the correct user SETUSER="--user $UID:$(id -g) --cap-drop=ALL" -# TODO: Validate arg spacing handling -POSTARG="--forward_restart $@" +POSTARG=("--forward_restart" "$@") if [[ "$1" == "fixch" ]] then SETUSER="" - POSTARG="fixch $UID" + POSTARG=("fixch" "$UID") fi - # add "--network=host" if you want to access other services on the host network (eg a separated comfy instance) docker run -it \ --rm \ @@ -31,7 +42,7 @@ docker run -it \ -v "$PWD/Models:/SwarmUI/Models" \ -v "$PWD/Output:/SwarmUI/Output" \ -v "$PWD/src/BuiltinExtensions/ComfyUIBackend/CustomWorkflows:/SwarmUI/src/BuiltinExtensions/ComfyUIBackend/CustomWorkflows" \ - --gpus=all -p 7801:7801 swarmui "$POSTARG" + --gpus=all -p 7801:7801 swarmui-"$GPU" "${POSTARG[@]}" if [ $? == 42 ]; then exec "$SCRIPT_DIR/launch-standard-docker.sh" "$@"