| Philip Zeyliger | a7e7fb6 | 2025-06-17 19:28:12 -0700 | [diff] [blame] | 1 | # Sketch Testing Itself |
| 2 | |
| 3 | NOTE: This is an idea the Sketch developers are developing. We don't know if it works yet! |
| 4 | |
| 5 | Sketch can test itself, but it can be a bit tricky, especially when Sketch |
| 6 | depends on Docker: |
| 7 | |
| 8 | # Manual Steps |
| 9 | |
| Philip Zeyliger | e0a9f72 | 2025-06-18 13:11:24 -0700 | [diff] [blame] | 10 | ## 1. Create VM and SSH Setup |
| 11 | |
| 12 | ```bash |
| Philip Zeyliger | a7e7fb6 | 2025-06-17 19:28:12 -0700 | [diff] [blame] | 13 | # Create a throwaway SSH key |
| 14 | ssh-keygen -t ed25519 -f ~/.ssh/sketch_test_key -P "" |
| 15 | |
| 16 | # Create a VM for Sketch to run Docker in |
| 17 | limactl start --name=dockerhost --cpus=$(nproc) --memory=8 --plain --set='.ssh.localPort=2222' template://ubuntu |
| 18 | |
| 19 | # Add the key to the VM |
| 20 | ssh -F "/Users/philip/.lima/dockerhost/ssh.config" lima-dockerhost tee -a .ssh/authorized_keys < /Users/philip/.ssh/sketch_test_key.pub |
| Philip Zeyliger | e0a9f72 | 2025-06-18 13:11:24 -0700 | [diff] [blame] | 21 | |
| 22 | # Create a consistent 'sketch' user for testing |
| 23 | ssh -F "/Users/philip/.lima/dockerhost/ssh.config" lima-dockerhost 'sudo useradd -m -s /bin/bash sketch 2>/dev/null || true && sudo mkdir -p /home/sketch/.ssh && sudo cp ~/.ssh/authorized_keys /home/sketch/.ssh/ && sudo chown -R sketch:sketch /home/sketch/.ssh && sudo usermod -aG sudo sketch && sudo usermod -aG docker sketch' |
| Philip Zeyliger | a7e7fb6 | 2025-06-17 19:28:12 -0700 | [diff] [blame] | 24 | ``` |
| 25 | |
| Philip Zeyliger | e0a9f72 | 2025-06-18 13:11:24 -0700 | [diff] [blame] | 26 | # Steps that Sketch can do for you! |
| 27 | |
| 28 | Once you have SSH access to your host (via `ssh -i ~/.ssh/sketch_test_key -p 2222 sketch@host.docker.internal`), |
| 29 | Sketch can do these "need to happen once" steps. |
| 30 | |
| 31 | ## 2. Install Docker and gvisor on the SSH Host |
| 32 | |
| 33 | |
| 34 | ### Install Docker |
| 35 | |
| 36 | ```bash |
| 37 | # Update package lists and install Ubuntu's native Docker package |
| 38 | sudo apt update |
| 39 | sudo apt install -y docker.io docker-compose |
| 40 | |
| 41 | # Add your user to the docker group |
| 42 | sudo usermod -aG docker sketch |
| 43 | ``` |
| 44 | |
| 45 | ### Install gvisor |
| 46 | |
| 47 | ```bash |
| 48 | # Add gvisor GPG key |
| 49 | curl -fsSL https://gvisor.dev/archive.key | sudo gpg --dearmor -o /usr/share/keyrings/gvisor-archive-keyring.gpg |
| 50 | |
| 51 | # Add gvisor repository |
| 52 | echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/gvisor-archive-keyring.gpg] https://storage.googleapis.com/gvisor/releases release main" | sudo tee /etc/apt/sources.list.d/gvisor.list > /dev/null |
| 53 | |
| 54 | # Install runsc (gvisor runtime) |
| 55 | sudo apt update |
| 56 | sudo apt install -y runsc |
| 57 | ``` |
| 58 | |
| 59 | ### Configure Docker to use gvisor |
| 60 | |
| 61 | ```bash |
| 62 | # Create Docker daemon configuration |
| 63 | sudo mkdir -p /etc/docker |
| 64 | echo '{ |
| 65 | "runtimes": { |
| 66 | "runsc": { |
| 67 | "path": "/usr/bin/runsc" |
| 68 | } |
| 69 | } |
| 70 | }' | sudo tee /etc/docker/daemon.json > /dev/null |
| 71 | |
| 72 | # Restart Docker to pick up the new configuration |
| 73 | sudo systemctl restart docker |
| 74 | ``` |
| 75 | |
| 76 | ### Test the Installation |
| 77 | |
| 78 | ```bash |
| 79 | # Check that both runtimes are available |
| 80 | docker info | grep -A5 'Runtimes' |
| 81 | |
| 82 | # Test default runtime (runc) |
| 83 | docker run --rm hello-world |
| 84 | |
| 85 | # Test gvisor runtime (runsc) |
| 86 | docker run --runtime=runsc --rm hello-world |
| 87 | ``` |
| 88 | |
| 89 | Both commands should successfully run the hello-world container. The gvisor version provides additional security isolation. |
| 90 | |
| Philip Zeyliger | a7e7fb6 | 2025-06-17 19:28:12 -0700 | [diff] [blame] | 91 | # What to tell Sketch |
| 92 | |
| 93 | * Mount your key with "-mount $HOME/.ssh/sketch_test_key:/sketch_test_key" |
| 94 | * Configure DOCKER_HOST to host.docker.internal:2222 with the key above. |
| Philip Zeyliger | e0a9f72 | 2025-06-18 13:11:24 -0700 | [diff] [blame] | 95 | * SSH into the host as user "sketch" (e.g., `ssh -i /sketch_test_key -p 2222 sketch@host.docker.internal`) |
| 96 | * Pass in an ANTHROPIC_API_KEY as well |
| 97 | |
| 98 | ## Testing Sketch with Docker over SSH |
| 99 | |
| 100 | Once everything is set up, configure SSH and test sketch: |
| 101 | |
| 102 | ```bash |
| 103 | # Configure SSH for Docker remote access |
| 104 | mkdir -p ~/.ssh && chmod 700 ~/.ssh |
| 105 | cp /sketch_test_key ~/.ssh/ && chmod 600 ~/.ssh/sketch_test_key |
| 106 | |
| 107 | # Create SSH configuration |
| 108 | cat > ~/.ssh/config << EOF |
| 109 | Host dockerhost |
| 110 | HostName host.docker.internal |
| 111 | Port 2222 |
| 112 | User sketch |
| 113 | IdentityFile ~/.ssh/sketch_test_key |
| 114 | StrictHostKeyChecking no |
| 115 | UserKnownHostsFile /dev/null |
| 116 | EOF |
| 117 | |
| 118 | # Test Docker over SSH |
| 119 | DOCKER_HOST=ssh://dockerhost docker info |
| 120 | |
| 121 | # Test sketch with one-shot command (requires ANTHROPIC_API_KEY) |
| 122 | DOCKER_HOST=ssh://dockerhost ANTHROPIC_API_KEY="your-key-here" go run ./cmd/sketch -one-shot -prompt "what is the date" -verbose -unsafe -skaband-addr="" |
| 123 | ``` |
| 124 | |
| 125 | The `-skaband-addr=""` flag bypasses authentication for testing, and `-unsafe` allows running without sketch.dev login. |