This repository provides a Docker-based setup for SD XL Deforum featuring GPU-accelerated inference and a RunPod deployment handler.
- Stable Diffusion XL Deforum: Animation toolkit with advanced Deforum scripting.
- Automatic Model + Deforum CLI Download: On first GPU run, the Deforum code and required model checkpoints are fetched automatically.
- Docker Image: Based on
nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04for seamless GPU support. - OpenCV Headless Enforcement: Ensures only the headless OpenCV wheel is used to avoid GUI dependencies.
- RunPod Handler: Serverless function for hosting on RunPod's serverless framework, with optional Cloudflare R2 upload support.
- RunPod Network Storage: Uses RunPod's network storage to serve models efficiently across serverless instances.
- Docker Engine with GPU support (NVIDIA Docker).
- NVIDIA drivers and CUDA Toolkit on host.
- Python 3.10+ for local testing (optional).
- RunPod account for serverless deployment.
├── Dockerfile-build # Base Docker build for Deforum
├── entrypoint.sh # Runtime entrypoint to enforce OpenCV headless
├── build-deforum-deploy.sh # Build and deploy script
├── comprehensive-requirements.txt # Pinned Python dependencies
└── README.md # This document
This repository uses GitHub Actions to automatically build and push Docker images to Docker Hub:
- Trigger: Automatic builds occur on every commit to the
mainbranch - Build Process:
- Uses the
Dockerfile-buildto create the image - Tags the image as
edreamai/deforum-studio:<timestamp>-<branch> - Also creates a
latesttag for the most recent build - Pushes both tags to Docker Hub registry
- Uses the
The deployment process follows this workflow:
- Code Commit: Push changes to the
mainbranch - Automated Build: GitHub Actions automatically builds and pushes the Docker image to
docker.io/edreamai/deforum-studio - Image Tag: Note the generated image tag from the GitHub Actions output (format:
<timestamp>-<branch>) - Serverless Deployment: Update your serverless pod configuration to use the new image tag
- Release: Deploy the updated configuration to your desired serverless environment
To find the correct image tag for deployment:
- GitHub Actions: Check the latest successful workflow run in the "Actions" tab
- Docker Hub: Visit Docker Hub to see all available tags
For local development and testing:
-
Build with GPU support:
chmod +x build-deforum-deploy.sh ./build-deforum-deploy.sh
<deforum-branch>defaults todev.[settings-file]defaults totest-settings.txt.
-
Result:
- Docker image tagged as
deforum-studio/animation-toolkit:<timestamp>-<branch>. - Optional
comprehensive-requirements.txtgenerated.
- Docker image tagged as
Run a container manually:
docker run --gpus all -v $(pwd):/input \
-e ROOT_PATH=/deforum_storage \
edreamai/deforum-studio:<tag> \
deforum runsingle --file /input/your-settings.jsonOutput will be available in /deforum_storage/output/video and copied to ./output by the build script.
This deployment uses RunPod Network Storage to serve models efficiently across serverless instances, eliminating the need to download models on each cold start.
-
Install dependencies:
pip install runpod
-
Prepare handler:
- Ensure
runpod_handler.pyis present in project root.
- Ensure
-
Configure RunPod:
export RUNPOD_API_KEY=YOUR_API_KEY_HERE- (Optional) Configure Cloudflare R2 bucket credentials in
handler.py. - Network Storage: The deployment leverages RunPod's network storage to cache models and dependencies, significantly reducing startup times for serverless functions.
- (Optional) Configure Cloudflare R2 bucket credentials in
-
Deploy:
Use the image tag from the GitHub Actions build output:
runpod serverless deploy \ --name sd-xl-deforum \ --handler runpod_handler.handler \ --image edreamai/deforum-studio:<timestamp>-<branch> \ --memory 16384 \ --gpu-count 1 \ --region <your-region>
Replace
<timestamp>-<branch>with the actual tag from the GitHub Actions build (e.g.,20250215123456-main). -
Invoke:
runpod serverless invoke \ --name sd-xl-deforum \ --input '{"input": {"prompt": "A cinematic landscape", "steps": 30}}'
The response will include a video URL to your generated MP4.
- Settings File: Pass
settings_filein payload to override JSON parameters. - Cloudflare R2 Upload: Configure the following environment variables for R2 access:
To enable video uploads to Cloudflare R2, set these environment variables:
export R2_BUCKET_NAME=your-bucket-name
export R2_ENDPOINT_URL=https://your-account-id.r2.cloudflarestorage.com
export R2_ACCESS_KEY_ID=your-r2-access-key-id
export R2_SECRET_ACCESS_KEY=your-r2-secret-access-key
export R2_PUBLIC_DOMAIN=your-custom-domain.com # Optional: for public URLsGetting R2 Credentials:
- Log in to your Cloudflare dashboard
- Go to R2 Object Storage
- Create a bucket if you haven't already
- Go to "Manage R2 API tokens"
- Create a new API token with R2 permissions
- Your endpoint URL format:
https://<account-id>.r2.cloudflarestorage.com
Public Access (Optional):
If you want public URLs for your videos, you can either:
- Set up a custom domain for your R2 bucket
- Use R2's public URL format (uncomment the appropriate line in
handler.py)
Happy animating with SD XL Deforum on Docker and RunPod!