Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions launchtools/AMDGPU-StandardDockerfile.docker
Original file line number Diff line number Diff line change
@@ -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"]
23 changes: 17 additions & 6 deletions launchtools/launch-standard-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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" "$@"
Expand Down