Files
bdi_podman_serverconf/containers/vibevoice/build-container.sh
T
2026-07-04 14:41:42 +02:00

170 строки
4.6 KiB
Bash

#!/bin/bash
# Build vibevoice.cpp with Vulkan support and create container image
# This script compiles vibevoice.cpp locally and creates a Podman image
# Usage: ./build-container.sh [--no-cache]
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TMP_BUILD_DIR="${SCRIPT_DIR}/.tmp"
BUILD_DIR="${TMP_BUILD_DIR}/vibevoice"
BIN_DIR="${TMP_BUILD_DIR}/bin-vulkan"
NO_CACHE=""
# Cleanup function - always runs on exit
cleanup() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo
echo "⚠ Build failed (exit code: $exit_code). Cleaning up temporary files..."
fi
rm -rf "$TMP_BUILD_DIR" "${SCRIPT_DIR}/bin-vulkan" 2>/dev/null || true
if [ $exit_code -eq 0 ]; then
echo "✓ Cleanup complete"
fi
return $exit_code
}
# Set trap to cleanup on exit (success or failure)
trap cleanup EXIT
# Parse arguments
if [[ "$1" == "--no-cache" ]]; then
NO_CACHE="--no-cache"
echo "Build mode: NO CACHE (clean rebuild)"
fi
echo "=== Vibevoice.cpp Vulkan Build ==="
echo "Temporary build directory: $TMP_BUILD_DIR"
echo "Output directory: $BIN_DIR"
if [ -n "$NO_CACHE" ]; then
echo "Cache mode: DISABLED"
fi
echo
# Create temporary build directory
mkdir -p "$TMP_BUILD_DIR"
echo
# Install dependencies
echo "[1/5] Installing dependencies..."
REQUIRED_PACKAGES="build-essential cmake git libvulkan-dev vulkan-tools glslc spirv-headers spirv-tools python3"
MISSING_PACKAGES=""
for pkg in $REQUIRED_PACKAGES; do
if ! dpkg -l | grep -q "^ii $pkg"; then
MISSING_PACKAGES="$MISSING_PACKAGES $pkg"
fi
done
if [ -n "$MISSING_PACKAGES" ]; then
echo " Installing missing packages:$MISSING_PACKAGES"
sudo apt-get update
sudo apt-get install -y $MISSING_PACKAGES
echo "✓ Dependencies installed"
else
echo "✓ All dependencies already installed"
fi
# Verify dependencies
echo " Verifying dependencies..."
for cmd in git cmake make gcc g++; do
if ! command -v $cmd &> /dev/null; then
echo "ERROR: $cmd is still not available after installation."
exit 1
fi
done
# Check Vulkan
if ! pkg-config --exists vulkan; then
echo "ERROR: Vulkan development files not found."
exit 1
fi
echo "✓ All dependencies verified"
echo
# Clone vibevoice.cpp with submodules
echo "[2/5] Cloning vibevoice.cpp repository (with submodules)..."
cd "$TMP_BUILD_DIR"
git clone --recursive https://github.com/localai-org/vibevoice.cpp "$BUILD_DIR"
cd "$BUILD_DIR"
echo "✓ Repository cloned"
echo
# Build vibevoice.cpp with Vulkan
echo "[3/5] Building vibevoice.cpp with Vulkan support..."
mkdir -p build
cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DVIBEVOICE_VULKAN=ON \
-DVIBEVOICE_BUILD_TESTS=OFF \
-DCMAKE_CXX_FLAGS="-march=native -O3"
cmake --build . -j $(nproc)
echo "✓ Build complete"
echo
# Copy binaries to output directory
echo "[4/5] Copying binaries..."
mkdir -p "$BIN_DIR"
if [ -f ./bin/vibevoice-cli ]; then
cp ./bin/vibevoice-cli "$BIN_DIR/"
echo " ✓ vibevoice-cli copied"
fi
# Copy all vibevoice-* executables if they exist
if ls ./bin/vibevoice-* >/dev/null 2>&1; then
cp ./bin/vibevoice-* "$BIN_DIR/" 2>/dev/null || true
echo " ✓ Additional vibevoice binaries copied"
fi
# Copy required libraries if they exist
if ls ./lib/* >/dev/null 2>&1; then
mkdir -p "$BIN_DIR/lib"
cp ./lib/* "$BIN_DIR/lib/" 2>/dev/null || true
echo " ✓ Libraries copied"
fi
echo "✓ Binaries copied to $BIN_DIR"
echo
# Create simple entrypoint
echo "[5/5] Creating entrypoint script..."
cat > "${SCRIPT_DIR}/entrypoint.sh" << 'EOF'
#!/bin/bash
# Vibevoice.cpp entrypoint for HTTP server or CLI
set -e
# If models directory exists and has files, run HTTP server
if [ -d "/app/models" ] && [ "$(ls -A /app/models)" ]; then
echo "=== Vibevoice Server ==="
echo "Models directory: /app/models"
exec /app/vibevoice-cli "$@"
else
echo "⚠ Models directory not found or empty at /app/models"
echo "Please mount your models directory when running the container:"
echo " -v /path/to/models:/app/models"
exec /app/vibevoice-cli "$@"
fi
EOF
chmod +x "${SCRIPT_DIR}/entrypoint.sh"
echo "✓ Entrypoint script created"
echo
echo "=== Build Summary ==="
echo "✓ Vibevoice.cpp compiled with Vulkan support"
echo "✓ Binaries location: $BIN_DIR"
echo "✓ Containerfile: vibevoice-vulkan.Containerfile"
echo
echo "Next steps:"
echo " 1. podman build -t vibevoice:vulkan-amd64 -f vibevoice-vulkan.Containerfile ."
echo " 2. podman run -it -v /srv/containers/vibevoice/models:/app/models \\"
echo " vibevoice:vulkan-amd64 tts --model models/vibevoice-realtime-0.5B-q8_0.gguf ..."
echo