Spaces:
Running
Running
| # Senti AI GCP Free Tier (e2-micro) Deployment Script | |
| # Run this on your Ubuntu 22.04 LTS instance. | |
| set -e | |
| echo "=== SENTI AI GCP VM DEPLOYMENT CONFIGURATOR ===" | |
| # 1. Check and Configure Swap Space (Crucial for 1GB RAM) | |
| if [ ! -f /swapfile ]; then | |
| echo "[SYSTEM] Allocating 2GB swap space..." | |
| sudo fallocate -l 2G /swapfile | |
| sudo chmod 600 /swapfile | |
| sudo mkswap /swapfile | |
| sudo swapon /swapfile | |
| echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab | |
| echo "[SYSTEM] Swap space successfully enabled!" | |
| else | |
| echo "[SYSTEM] Swap file already exists." | |
| fi | |
| # 2. Update System Package Repository | |
| echo "[SYSTEM] Updating apt repositories..." | |
| sudo apt-get update -y | |
| sudo apt-get upgrade -y | |
| # 3. Install System Dependencies | |
| echo "[SYSTEM] Installing Redis, Nginx, Python3, and Git..." | |
| sudo apt-get install -y git python3-pip python3-venv redis-server nginx curl | |
| # 4. Install Node.js & PM2 (Process Manager) | |
| if ! command -v pm2 &> /dev/null; then | |
| echo "[SYSTEM] Installing Node.js and PM2..." | |
| curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - | |
| sudo apt-get install -y nodejs | |
| sudo npm install -p -g pm2 | |
| else | |
| echo "[SYSTEM] PM2 already installed." | |
| fi | |
| # 5. Configure Redis Server | |
| echo "[SYSTEM] Configuring Redis..." | |
| sudo systemctl enable redis-server | |
| sudo systemctl start redis-server | |
| # 6. Set Up Nginx Web Server Configurations | |
| echo "[SYSTEM] Writing Nginx proxy configuration..." | |
| sudo tee /etc/nginx/sites-available/senti << 'EOF' | |
| server { | |
| listen 80; | |
| server_name localhost; | |
| location / { | |
| root /var/www/senti/frontend/dist; | |
| index index.html; | |
| try_files $uri $uri/ /index.html; | |
| } | |
| location /api { | |
| proxy_pass http://127.0.0.1:8000; | |
| proxy_set_header Host $host; | |
| 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; | |
| } | |
| location /api/ws/ { | |
| proxy_pass http://127.0.0.1:8000; | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "upgrade"; | |
| proxy_set_header Host $host; | |
| } | |
| } | |
| EOF | |
| # Enable Senti Nginx configuration | |
| if [ -f /etc/nginx/sites-enabled/default ]; then | |
| sudo rm /etc/nginx/sites-enabled/default | |
| fi | |
| if [ ! -f /etc/nginx/sites-enabled/senti ]; then | |
| sudo ln -s /etc/nginx/sites-available/senti /etc/nginx/sites-enabled/senti | |
| fi | |
| echo "[SYSTEM] Restarting Nginx server..." | |
| sudo systemctl restart nginx | |
| # 7. Setup Application Workspace | |
| echo "[SYSTEM] Preparing directories..." | |
| sudo mkdir -p /var/www/senti | |
| sudo chown -R $USER:$USER /var/www/senti | |
| echo "=== GCP CONFIGURATION COMPLETED ===" | |
| echo "Next Steps:" | |
| echo "1. Clone the project or copy build files to: /var/www/senti" | |
| echo "2. Navigate to your app directory, create a virtual environment, and install requirements:" | |
| echo " python3 -m venv .venv" | |
| echo " source .venv/bin/activate" | |
| echo " pip install -r requirements.txt maturin" | |
| echo "3. Compile the Rust math library inside the virtual environment:" | |
| echo " cd senti_calc && maturin build --release && pip install --force-reinstall target/wheels/*.whl" | |
| echo "4. Use PM2 to run the Python backend in the background:" | |
| echo " pm2 start ecosystem.config.js" | |