mirror of
https://github.com/kodxana/madiator-docker-runpod.git
synced 2024-11-21 10:20:12 +01:00
Better A1111 template
This commit is contained in:
parent
df79a6d19d
commit
0759ba95cb
7 changed files with 287 additions and 0 deletions
100
official-templates/better-a1111/Dockerfile
Normal file
100
official-templates/better-a1111/Dockerfile
Normal file
|
@ -0,0 +1,100 @@
|
|||
# Stage 1: Base Image
|
||||
FROM madiator2011/better-base:cuda12.1 as base
|
||||
|
||||
ARG PYTHON_VERSION1=3.11
|
||||
|
||||
# Install additional packages including zstd
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update && \
|
||||
apt-get install -y pv git rsync libtcmalloc-minimal4 bc zstd && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Stage 2: A1111 Installation
|
||||
FROM base as a1111-install
|
||||
|
||||
# Create virtual environment with the correct path
|
||||
RUN mkdir -p /workspace && python -m venv /workspace/ba1111
|
||||
|
||||
# Set environment variables for the virtual environment
|
||||
ENV VIRTUAL_ENV="/workspace/ba1111"
|
||||
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||
|
||||
# Clone AUTOMATIC1111 Stable Diffusion WebUI and additional repositories
|
||||
RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git /stable-diffusion-webui && \
|
||||
mkdir -p /stable-diffusion-webui/repositories && \
|
||||
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git /stable-diffusion-webui/repositories/stable-diffusion-webui-assets && \
|
||||
git clone https://github.com/Stability-AI/stablediffusion.git /stable-diffusion-webui/repositories/stable-diffusion && \
|
||||
git clone https://github.com/Stability-AI/stablediffusion.git /stable-diffusion-webui/repositories/stable-diffusion-stability-ai && \
|
||||
git clone https://github.com/Stability-AI/generative-models.git /stable-diffusion-webui/repositories/generative-models && \
|
||||
git clone https://github.com/crowsonkb/k-diffusion.git /stable-diffusion-webui/repositories/k-diffusion && \
|
||||
git clone https://github.com/salesforce/BLIP.git /stable-diffusion-webui/repositories/BLIP && \
|
||||
rm /stable-diffusion-webui/webui-user.sh
|
||||
|
||||
# Activate the virtual environment and install packages
|
||||
RUN $VIRTUAL_ENV/bin/pip install --upgrade pip setuptools wheel && \
|
||||
$VIRTUAL_ENV/bin/pip install -r /stable-diffusion-webui/requirements_versions.txt && \
|
||||
$VIRTUAL_ENV/bin/pip install accelerate wheel && \
|
||||
$VIRTUAL_ENV/bin/pip install ipykernel ipywidgets && \
|
||||
$VIRTUAL_ENV/bin/pip install "https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip" && \
|
||||
$VIRTUAL_ENV/bin/pip install "https://github.com/mlfoundations/open_clip/archive/bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip" && \
|
||||
$VIRTUAL_ENV/bin/pip install bitsandbytes==0.43.3 && \
|
||||
$VIRTUAL_ENV/bin/python -m ipykernel install --name "python3" --display-name "Python 3 (Better A1111 Venv)" && \
|
||||
$VIRTUAL_ENV/bin/pip install -U xformers --index-url https://download.pytorch.org/whl/cu121
|
||||
|
||||
# Create tar archive and compress with zstd
|
||||
RUN tar -cf - -C /workspace ba1111 | zstd -T0 -f -o /ba1111.tar.zst
|
||||
|
||||
# Remove the original venv to save space in the image
|
||||
RUN rm -rf /workspace/ba1111
|
||||
|
||||
# New stage for uploading ba1111.tar.zst to MinIO
|
||||
FROM a1111-install as uploader
|
||||
|
||||
# Install boto3
|
||||
RUN pip install boto3
|
||||
|
||||
# Set MinIO configuration using environment variables
|
||||
ENV MINIO_ENDPOINT=https://s3.madiator.com
|
||||
ENV MINIO_ACCESS_KEY=""
|
||||
ENV MINIO_SECRET_KEY=""
|
||||
ENV MINIO_BUCKET="better"
|
||||
|
||||
# Copy the upload script
|
||||
COPY upload_to_minio.py /upload_to_minio.py
|
||||
|
||||
# Set the entrypoint to the upload script
|
||||
ENTRYPOINT ["python", "/upload_to_minio.py"]
|
||||
|
||||
# Stage 3: Final Image
|
||||
FROM a1111-install as final
|
||||
|
||||
# Set environment variables for runtime
|
||||
ENV VIRTUAL_ENV="/workspace/ba1111"
|
||||
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||
|
||||
# Copy the README.md
|
||||
COPY README.md /usr/share/nginx/html/README.md
|
||||
|
||||
# NGINX Proxy
|
||||
COPY --from=proxy nginx.conf /etc/nginx/nginx.conf
|
||||
COPY --from=proxy readme.html /usr/share/nginx/html/readme.html
|
||||
|
||||
# Copy all necessary scripts
|
||||
COPY --from=scripts start.sh /
|
||||
COPY pre_start.sh /pre_start.sh
|
||||
COPY webui-user.sh /stable-diffusion-webui/webui-user.sh
|
||||
RUN chmod +x /start.sh /pre_start.sh /stable-diffusion-webui/webui-user.sh
|
||||
COPY settings.json /root/.local/share/code-server/User/settings.json
|
||||
|
||||
# Copy the tar.zst archive and Stable Diffusion WebUI
|
||||
COPY --from=a1111-install /ba1111.tar.zst /ba1111.tar.zst
|
||||
COPY --from=a1111-install /stable-diffusion-webui /stable-diffusion-webui
|
||||
|
||||
# Welcome Message
|
||||
COPY --from=logo runpod.txt /etc/runpod.txt
|
||||
RUN echo 'cat /etc/runpod.txt' >> /root/.bashrc && \
|
||||
echo 'echo -e "\nFor detailed documentation and guides, please visit:\n\033[1;34mhttps://docs.runpod.io/\033[0m and \033[1;34mhttps://blog.runpod.io/\033[0m\n\n"' >> /root/.bashrc
|
||||
|
||||
# CMD
|
||||
CMD [ "/start.sh" ]
|
7
official-templates/better-a1111/README.md
Normal file
7
official-templates/better-a1111/README.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
## Build Options
|
||||
|
||||
To build with default options, run `docker buildx bake`, to build a specific target, run `docker buildx bake <target>`.
|
||||
|
||||
## Ports
|
||||
|
||||
- 22/tcp (SSH)
|
17
official-templates/better-a1111/docker-bake.hcl
Normal file
17
official-templates/better-a1111/docker-bake.hcl
Normal file
|
@ -0,0 +1,17 @@
|
|||
group "default" {
|
||||
targets = ["light"]
|
||||
}
|
||||
|
||||
target "light" {
|
||||
contexts = {
|
||||
scripts = "../../container-template"
|
||||
proxy = "../../container-template/proxy"
|
||||
logo = "../../container-template"
|
||||
}
|
||||
dockerfile = "Dockerfile"
|
||||
args = {
|
||||
BASE_IMAGE = "madiator2011/better-base:cuda12.1",
|
||||
PYTHON_VERSION = "3.11"
|
||||
}
|
||||
tags = ["madiator2011/better-a1111:light"]
|
||||
}
|
64
official-templates/better-a1111/pre_start.sh
Normal file
64
official-templates/better-a1111/pre_start.sh
Normal file
|
@ -0,0 +1,64 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
|
||||
# Function to print colorized feedback
|
||||
print_feedback() {
|
||||
GREEN='\033[0;32m'
|
||||
NC='\033[0m' # No Color
|
||||
echo -e "${GREEN}[Forge Startup]:${NC} $1"
|
||||
}
|
||||
|
||||
# Function to run rsync with progress bar and optimizations
|
||||
rsync_with_progress() {
|
||||
rsync -aHvx --info=progress2 --ignore-existing --update --stats "$@"
|
||||
}
|
||||
|
||||
# Check if the NO_SYNC variable is set to true
|
||||
if [ "${NO_SYNC}" == "true" ]; then
|
||||
print_feedback "Skipping sync and startup as per environment variable setting."
|
||||
exec bash -c 'sleep infinity'
|
||||
fi
|
||||
|
||||
print_feedback "Starting A1111 setup..."
|
||||
|
||||
# Extract the virtual environment if it doesn't exist
|
||||
if [ ! -d "/workspace/ba1111" ]; then
|
||||
print_feedback "Extracting virtual environment..."
|
||||
mkdir -p /workspace/ba1111
|
||||
tar -xzf /ba1111.tar.gz -C /workspace/ba1111
|
||||
else
|
||||
print_feedback "Virtual environment already exists, skipping extraction..."
|
||||
fi
|
||||
|
||||
# Activate the virtual environment
|
||||
source /workspace/ba1111/bin/activate
|
||||
|
||||
# Check if Stable Diffusion WebUI a111 exists in the workspace
|
||||
if [ ! -d "/workspace/stable-diffusion-webui" ] || [ -z "$(ls -A /workspace/stable-diffusion-webui)" ]; then
|
||||
print_feedback "Stable Diffusion WebUI A1111 not found or empty. Syncing all files..."
|
||||
rsync_with_progress /stable-diffusion-webui/ /workspace/stable-diffusion-webui/
|
||||
print_feedback "Initial sync completed."
|
||||
else
|
||||
print_feedback "Stable Diffusion WebUI A1111 found. Skipping sync to preserve user modifications."
|
||||
fi
|
||||
|
||||
# Change to the a111 directory
|
||||
cd /workspace/stable-diffusion-webui
|
||||
|
||||
# Modify webui.sh to allow running as root, only if needed
|
||||
print_feedback "Checking webui.sh configuration..."
|
||||
if grep -q "can_run_as_root=0" webui.sh; then
|
||||
print_feedback "Modifying webui.sh to allow running as root..."
|
||||
sed -i 's/can_run_as_root=0/can_run_as_root=1/' webui.sh
|
||||
else
|
||||
print_feedback "webui.sh already configured to run as root or configuration not found."
|
||||
fi
|
||||
|
||||
# Create logs directory if it doesn't exist
|
||||
mkdir -p /workspace/logs
|
||||
|
||||
# Start webui-user.sh and log output
|
||||
print_feedback "Starting webui-user.sh..."
|
||||
./webui.sh -f > >(tee /workspace/logs/a1111.log) 2>&1 &
|
21
official-templates/better-a1111/settings.json
Normal file
21
official-templates/better-a1111/settings.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"workbench.colorTheme": "Default Dark Modern",
|
||||
"workbench.startupEditor": "none",
|
||||
"workbench.enableExperiments": false,
|
||||
"telemetry.enableTelemetry": false,
|
||||
"telemetry.enableCrashReporter": false,
|
||||
"security.workspace.trust.enabled": false,
|
||||
"update.mode": "manual",
|
||||
"extensions.autoUpdate": false,
|
||||
"python.showStartPage": false,
|
||||
"jupyter.experiments.enabled": false,
|
||||
"jupyter.askForKernelRestart": false,
|
||||
"jupyter.askForKernelSource": false,
|
||||
"jupyter.alwaysTrustNotebooks": true,
|
||||
"extensions.ignoreRecommendations": true,
|
||||
"files.autoSave": "afterDelay",
|
||||
"files.autoSaveDelay": 1000,
|
||||
"python.defaultInterpreterPath": "/workspace/ba1111/bin/python",
|
||||
"python.analysis.extraPaths": ["/workspace/ba1111/lib/python3.11/site-packages"],
|
||||
"jupyter.notebookFileRoot": "/workspace"
|
||||
}
|
32
official-templates/better-a1111/upload_to_minio.py
Normal file
32
official-templates/better-a1111/upload_to_minio.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import os
|
||||
import boto3
|
||||
from botocore.client import Config
|
||||
|
||||
# MinIO configuration
|
||||
minio_endpoint = os.environ.get('MINIO_ENDPOINT', 'https://s3.madiator.com')
|
||||
minio_access_key = os.environ.get('MINIO_ACCESS_KEY', '')
|
||||
minio_secret_key = os.environ.get('MINIO_SECRET_KEY', '')
|
||||
minio_bucket = os.environ.get('MINIO_BUCKET', 'better')
|
||||
|
||||
# File to upload
|
||||
file_path = '/ba1111.tar.zst'
|
||||
object_name = 'ba1111/ba1111.tar.zst'
|
||||
|
||||
# Get file size
|
||||
file_size = os.path.getsize(file_path)
|
||||
|
||||
# Create a client with the MinIO configuration
|
||||
s3_client = boto3.client('s3',
|
||||
endpoint_url=minio_endpoint,
|
||||
aws_access_key_id=minio_access_key,
|
||||
aws_secret_access_key=minio_secret_key,
|
||||
config=Config(signature_version='s3v4'),
|
||||
region_name='us-east-1')
|
||||
|
||||
# Upload the file
|
||||
try:
|
||||
s3_client.upload_file(file_path, minio_bucket, object_name)
|
||||
print(f"File {file_path} uploaded successfully to {minio_bucket}/{object_name}")
|
||||
print(f"File size: {file_size} bytes")
|
||||
except Exception as e:
|
||||
print(f"Error uploading file: {str(e)}")
|
46
official-templates/better-a1111/webui-user.sh
Normal file
46
official-templates/better-a1111/webui-user.sh
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
#########################################################
|
||||
# Uncomment and change the variables below to your need:#
|
||||
#########################################################
|
||||
|
||||
# Install directory without trailing slash
|
||||
export install_dir="/workspace"
|
||||
|
||||
# Name of the subdirectory
|
||||
export clone_dir="stable-diffusion-webui"
|
||||
|
||||
# Commandline arguments for webui.py, for example:
|
||||
export COMMANDLINE_ARGS="--listen --port 7860 --enable-insecure-extension-access --api --xformers"
|
||||
|
||||
# python3 executable
|
||||
export python_cmd="python3"
|
||||
|
||||
# git executable
|
||||
export GIT="git"
|
||||
|
||||
# python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv)
|
||||
export venv_dir="/workspace/ba1111"
|
||||
|
||||
# script to launch to start the app
|
||||
#export LAUNCH_SCRIPT="launch.py"
|
||||
|
||||
# install command for torch
|
||||
#export TORCH_COMMAND="pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113"
|
||||
|
||||
# Requirements file to use for stable-diffusion-webui
|
||||
#export REQS_FILE="requirements_versions.txt"
|
||||
|
||||
# Fixed git repos
|
||||
#export K_DIFFUSION_PACKAGE=""
|
||||
#export GFPGAN_PACKAGE=""
|
||||
|
||||
# Fixed git commits
|
||||
#export STABLE_DIFFUSION_COMMIT_HASH=""
|
||||
#export CODEFORMER_COMMIT_HASH=""
|
||||
#export BLIP_COMMIT_HASH=""
|
||||
|
||||
# Uncomment to enable accelerated launch
|
||||
#export ACCELERATE="True"
|
||||
|
||||
# Uncomment to disable TCMalloc
|
||||
#export NO_TCMALLOC="True"
|
Loading…
Reference in a new issue