senti-beta / scripts /vm_setup.sh
joseph njoroge kariuki
Deploy Senti AI to Hugging Face Spaces
021e065
#!/bin/bash
# ==============================================================================
# Senti AI — Debian VM Lightweight Setup Script
# ==============================================================================
# Run this script on the target Compute Engine Debian VM.
# ==============================================================================
set -e # exit on error
echo "====== [SENTI VM SETUP] ======"
# 1. Update Packages
echo "--> 1. Updating packages..."
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y git python3 python3-pip python3-venv nginx curl gcc g++ pkg-config build-essential tesseract-ocr
# 2. Install Rust (for cargo/senti_calc maturin compilation)
if ! command -v cargo &> /dev/null; then
echo "--> 2. Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
fi
# 3. Setup Node.js & NPM (for frontend build)
if ! command -v node &> /dev/null; then
echo "--> 3. Installing Node.js..."
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
# 4. Build Frontend
echo "--> 4. Building React Frontend..."
cd /app/frontend || cd ~/senti_ai/frontend || cd "$(pwd)/frontend"
npm ci
npm run build
# 5. Configure Nginx
echo "--> 5. Configuring Nginx..."
FRONTEND_DIST_PATH=$(pwd)/dist
sudo tee /etc/nginx/sites-available/senti <<EOF
server {
listen 80;
server_name _;
# Frontend Static Files
location / {
root $FRONTEND_DIST_PATH;
index index.html;
try_files \$uri \$uri/ /index.html;
}
# API Proxy to Uvicorn Gateway
location /api/ {
proxy_pass http://127.0.0.1:8000/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
# Websocket support
location /ws/ {
proxy_pass http://127.0.0.1:8000/ws/;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host \$host;
}
}
EOF
sudo ln -sf /etc/nginx/sites-available/senti /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
# 6. Build Backend
echo "--> 6. Building Python Backend Virtual Environment..."
cd ..
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r senti/requirements.txt
# Compile Rust engine
echo "--> 7. Building Rust engine extensions..."
cd senti/senti_calc
pip install maturin
maturin build --release
pip install .
cd ../..
# 7. Create Systemd Service for Gateway
echo "--> 8. Creating systemd service for Senti Gateway..."
PROJECT_DIR=$(pwd)
sudo tee /etc/systemd/system/senti-gateway.service <<EOF
[Unit]
Description=Senti AI API Gateway Daemon
After=network.target
[Service]
User=$USER
WorkingDirectory=$PROJECT_DIR/senti
ExecStart=$PROJECT_DIR/venv/bin/uvicorn backend.api.main:app --host 127.0.0.1 --port 8000 --workers 1
Restart=always
Environment=SENTI_ENV=production
Environment=USE_LM=false
Environment=DATABASE_URL=sqlite:///senti_db.sqlite
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable senti-gateway
sudo systemctl start senti-gateway
# 8. Verify status
echo "--> 9. Checking status of services..."
sudo systemctl status nginx --no-pager
sudo systemctl status senti-gateway --no-pager
echo "====== [VM SETUP AND DEPLOYMENT COMPLETED] ======"
echo "Access Senti AI on http://<VM-External-IP>"