forked from ruvnet/sparc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add non-interactive mode support and deployment scripts for SPA…
…RC CLI on Fly.io
- Loading branch information
Showing
10 changed files
with
714 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Non-interactive mode handler for SPARC CLI""" | ||
|
||
from rich.console import Console | ||
from rich.panel import Panel | ||
|
||
console = Console() | ||
|
||
def handle_non_interactive(): | ||
"""Handle non-interactive mode by displaying help and status""" | ||
console.print(Panel( | ||
"[bold green]SPARC CLI Server[/bold green]\n\n" | ||
"Running in non-interactive mode.\n" | ||
"Use SSH to connect for interactive access:\n" | ||
" flyctl ssh console\n\n" | ||
"For logs:\n" | ||
" flyctl logs\n\n" | ||
"Status: Ready", | ||
title="🚀 SPARC CLI", | ||
border_style="green" | ||
)) | ||
|
||
# Keep the process running | ||
try: | ||
import time | ||
while True: | ||
time.sleep(3600) # Sleep for an hour | ||
except KeyboardInterrupt: | ||
console.print("\nShutting down...") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
config.sh | ||
.env | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
FROM python:3.10-slim | ||
|
||
# Environment variables will be provided at runtime | ||
ENV PYTHONPATH=/opt/sparc | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV TERM=xterm | ||
|
||
# Install system dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
wget \ | ||
curl \ | ||
gnupg \ | ||
git \ | ||
build-essential \ | ||
python3-dev \ | ||
sudo \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Create SPARC directory | ||
WORKDIR /opt/sparc | ||
|
||
# Copy project files | ||
COPY . . | ||
|
||
# Install dependencies | ||
RUN pip install --no-cache-dir hatchling sympy numpy | ||
RUN pip install --no-cache-dir langchain langchain-core | ||
RUN pip install --no-cache-dir -r requirements-dev.txt | ||
RUN pip install --no-cache-dir -e . | ||
|
||
# Install Playwright browsers | ||
RUN python scripts/install_playwright.py | ||
|
||
# Create a non-root user for SSH access | ||
RUN useradd -m -s /bin/bash sparc_user && \ | ||
echo "sparc_user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/sparc_user | ||
|
||
# Copy and set up startup script | ||
COPY sparc_cli/scripts/fly/startup.sh /usr/local/bin/sparc-startup | ||
RUN chmod +x /usr/local/bin/sparc-startup | ||
|
||
# Switch to the non-root user | ||
USER sparc_user | ||
WORKDIR /home/sparc_user | ||
|
||
# Keep container running | ||
CMD ["tail", "-f", "/dev/null"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# SPARC CLI Fly.io Deployment | ||
|
||
This directory contains scripts for deploying SPARC CLI to Fly.io. The deployment creates a dedicated VM with SPARC CLI installed and accessible via SSH. | ||
|
||
## Prerequisites | ||
|
||
- Git installed on your system | ||
- Linux or macOS (Windows users should use WSL) | ||
- For macOS users: Homebrew installed | ||
- A Fly.io account (sign up at https://fly.io) | ||
|
||
## Quick Start | ||
|
||
1. Copy and edit configuration: | ||
```bash | ||
cp config.template.sh config.sh | ||
# Edit config.sh with your settings | ||
``` | ||
|
||
2. Run the installation script: | ||
```bash | ||
./install.sh | ||
``` | ||
This will: | ||
- Install the Fly.io CLI | ||
- Log you into Fly.io | ||
- Create your application | ||
- Set up environment variables | ||
|
||
3. Deploy your application: | ||
```bash | ||
./deploy.sh | ||
``` | ||
This will: | ||
- Create a VM with SPARC CLI installed | ||
- Configure SSH access | ||
- Set up environment variables | ||
|
||
4. Access your deployment: | ||
```bash | ||
./access.sh | ||
``` | ||
Choose from multiple access options: | ||
- Chat Mode: Interactive chat with SPARC CLI | ||
- Research Mode: Research-only mode for information gathering | ||
- Cowboy Mode: Skip command confirmations for faster execution | ||
- Manual Console: Direct SSH access for custom commands | ||
- View Logs: Monitor application logs | ||
|
||
## Configuration | ||
|
||
The `config.sh` file (created from `config.template.sh`) contains all deployment settings: | ||
|
||
- `FLY_APP_NAME`: Your Fly.io application name | ||
- `FLY_REGION`: Deployment region (e.g., "lax", "sfo", "iad") | ||
- `FLY_ORG`: Your Fly.io organization | ||
- `GIT_REPO_URL`: GitHub repository URL (optional, can be entered during deployment) | ||
- `GIT_BRANCH`: Repository branch (defaults to "main") | ||
- API keys for SPARC CLI (ANTHROPIC_API_KEY required) | ||
- Deployment machine configuration | ||
|
||
## Scripts | ||
|
||
### install.sh | ||
- Installs Fly.io CLI | ||
- Sets up your application | ||
- Configures environment variables | ||
|
||
### deploy.sh | ||
- Prompts for GitHub repository if not configured | ||
- Clones and deploys your application | ||
- Creates Fly.io configuration | ||
|
||
### access.sh | ||
- Provides interactive access to your deployment | ||
- Shows logs and application status | ||
- Opens web interface | ||
|
||
## Security Notes | ||
|
||
- `config.sh` contains sensitive information and is excluded from git | ||
- API keys are stored securely as Fly.io secrets | ||
- Each deployment creates a fresh clone of your repository | ||
|
||
## Troubleshooting | ||
|
||
1. If installation fails: | ||
- Check your Fly.io credentials | ||
- Ensure you have necessary permissions | ||
- Verify your API keys | ||
|
||
2. If deployment fails: | ||
- Check the GitHub repository URL and branch | ||
- Verify the repository contains sparc_cli directory | ||
- Check Fly.io resource limits | ||
|
||
3. If access fails: | ||
- Ensure the application is deployed | ||
- Check Fly.io status | ||
- Verify your network connection | ||
|
||
For more help, visit: | ||
- Fly.io Documentation: https://fly.io/docs/ | ||
- SPARC CLI Documentation: https://github.com/yourusername/sparc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
|
||
set -e # Exit on error | ||
|
||
# Setup flyctl environment | ||
export FLYCTL_INSTALL="/home/$USER/.fly" | ||
export PATH="$FLYCTL_INSTALL/bin:$PATH" | ||
|
||
# Verify flyctl is available | ||
if ! command -v flyctl &> /dev/null; then | ||
echo "Error: flyctl not found. Please run ./install.sh first" | ||
exit 1 | ||
fi | ||
|
||
echo "Accessing SPARC CLI on Fly.io..." | ||
echo "================================" | ||
|
||
# Check if config exists | ||
if [ ! -f "$(dirname "$0")/config.sh" ]; then | ||
echo "Error: config.sh not found. Please run install.sh first." | ||
exit 1 | ||
fi | ||
|
||
# Source configuration | ||
source "$(dirname "$0")/config.sh" | ||
|
||
# Check if app exists | ||
if ! flyctl apps list | grep -q "^$FLY_APP_NAME"; then | ||
echo "Error: Application $FLY_APP_NAME not found" | ||
echo "Please run install.sh and deploy.sh first" | ||
exit 1 | ||
fi | ||
|
||
# Function to run SPARC CLI command | ||
run_sparc() { | ||
local mode=$1 | ||
|
||
echo "Connecting to SPARC CLI..." | ||
echo "Note: Use Ctrl+C to exit" | ||
echo | ||
flyctl ssh console --app "$FLY_APP_NAME" --command "sparc-startup $mode" | ||
} | ||
|
||
# Provide options for access | ||
echo | ||
echo "Access Options:" | ||
echo "1) Start SPARC CLI in Chat Mode" | ||
echo "2) Start SPARC CLI in Research Mode" | ||
echo "3) Start SPARC CLI in Cowboy Mode (no command confirmations)" | ||
echo "4) Connect to Console (manual mode)" | ||
echo "5) View Logs" | ||
echo "6) Exit" | ||
echo | ||
|
||
read -p "Choose an option [1-6]: " choice | ||
|
||
case $choice in | ||
1) | ||
echo "Starting SPARC CLI in Chat Mode..." | ||
run_sparc "chat" | ||
;; | ||
2) | ||
echo "Starting SPARC CLI in Research Mode..." | ||
run_sparc "research" | ||
;; | ||
3) | ||
echo "Starting SPARC CLI in Cowboy Mode..." | ||
run_sparc "cowboy" | ||
;; | ||
4) | ||
echo "Connecting to console..." | ||
echo "You can run SPARC CLI manually with:" | ||
echo " sparc-startup [mode]" | ||
echo | ||
echo "Available modes:" | ||
echo " chat : Start in chat mode" | ||
echo " research : Start in research mode" | ||
echo " cowboy : Start in cowboy mode" | ||
echo | ||
echo "For help, run: sparc-startup --help" | ||
echo | ||
flyctl ssh console --app "$FLY_APP_NAME" | ||
;; | ||
5) | ||
echo "Showing logs..." | ||
flyctl logs --app "$FLY_APP_NAME" | ||
;; | ||
6) | ||
echo "Exiting..." | ||
exit 0 | ||
;; | ||
*) | ||
echo "Invalid option" | ||
exit 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# Fly.io Configuration | ||
export FLY_APP_NAME="your-app-name" # The name of your fly.io application | ||
export FLY_REGION="lax" # Your preferred fly.io region | ||
export FLY_ORG="personal" # Your fly.io organization | ||
|
||
# Git Repository Configuration | ||
export GIT_REPO_URL="https://github.com/yourusername/sparc.git" | ||
export GIT_BRANCH="main" | ||
|
||
# API Keys (same as local .sparc_exports) | ||
export ANTHROPIC_API_KEY="" # Required | ||
export OPENAI_API_KEY="" # Optional | ||
export OPENROUTER_KEY="" # Optional | ||
export ENCRYPTION_KEY="" # Optional | ||
export GEMINI_API_KEY="" # Optional | ||
export VERTEXAI_PROJECT="" # Optional | ||
export VERTEXAI_LOCATION="" # Optional | ||
|
||
# Deployment Configuration | ||
export DEPLOY_MACHINE_SIZE="shared-cpu-1x" # Fly.io machine size | ||
export DEPLOY_MEMORY="256" # Memory in MB |
Oops, something went wrong.