From 2a08f4e91d267c656726d0c5625c9d45380aeb89 Mon Sep 17 00:00:00 2001 From: xnullzz Date: Sat, 16 Aug 2025 19:18:43 +0300 Subject: [PATCH] Add deploy --- deploy.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 deploy.sh diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..d6bbe48 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +set -euo pipefail + +# === Config === +INSTALL_DIR="${INSTALL_DIR:-/workspace/ai-toolkit}" +UI_PORT="${UI_PORT:-8675}" # AI-Toolkit UI default port per docs +AUTH_TOKEN="${AI_TOOLKIT_AUTH:-}" # Must be provided via environment +NODE_MAJOR="${NODE_MAJOR:-20}" # Install Node.js 20 LTS +PYTHON_BIN="${PYTHON_BIN:-python3}" # Use the system Python to create venv + +if [[ -z "${AUTH_TOKEN}" ]]; then + echo "ERROR: AI_TOOLKIT_AUTH environment variable is not set." + echo "Set it in your RunPod environment (e.g., AI_TOOLKIT_AUTH=someStrongPassword) and re-run." + exit 1 +fi + +echo "==> Updating apt and installing dependencies..." +apt-get update -y +DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + git curl ca-certificates build-essential pkg-config \ + python3-venv python3-dev \ + ffmpeg libgl1 libglib2.0-0 + +echo "==> Installing Node.js ${NODE_MAJOR} (required: Node >=18)..." +curl -fsSL https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash - +DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs + +echo "==> Cloning AI-Toolkit into ${INSTALL_DIR}..." +mkdir -p "$(dirname "${INSTALL_DIR}")" +if [[ ! -d "${INSTALL_DIR}" ]]; then + git clone https://github.com/ostris/ai-toolkit.git "${INSTALL_DIR}" +else + echo " Repo already exists, pulling latest..." + git -C "${INSTALL_DIR}" pull --rebase +fi +git -C "${INSTALL_DIR}" submodule update --init --recursive + +echo "==> Creating Python venv and upgrading pip..." +cd "${INSTALL_DIR}" +${PYTHON_BIN} -m venv venv +# shellcheck disable=SC1091 +source venv/bin/activate +python -m pip install --upgrade pip wheel setuptools + +echo "==> Installing PyTorch 2.8.0 + CUDA 12.8 wheels (torch/vision/audio)..." +# Keep versions aligned; use cu128 wheel index. +pip install --no-cache-dir \ + torch==2.8.0 torchvision==0.23.0 torchaudio==2.8.0 \ + --index-url https://download.pytorch.org/whl/cu128 + +echo "==> Installing AI-Toolkit Python requirements..." +pip install --no-cache-dir -r requirements.txt + +echo "==> Building and starting the AI-Toolkit UI on port ${UI_PORT}..." +# The UI script uses port 8675 by default; we enforce our env and expose host binding. +export AI_TOOLKIT_AUTH="${AUTH_TOKEN}" +export PORT="${UI_PORT}" +export HOST="0.0.0.0" + +cd ui +# Use npm to install/build and then start the UI. This blocks (good for container foreground). +npm install +npm run build_and_start +