blob: 35af38dfb7123d0cba7ead1f353ff4cad63536bd [file] [log] [blame] [view]
Philip Zeyligera7e7fb62025-06-17 19:28:12 -07001# Sketch Testing Itself
2
3NOTE: This is an idea the Sketch developers are developing. We don't know if it works yet!
4
5Sketch can test itself, but it can be a bit tricky, especially when Sketch
6depends on Docker:
7
8# Manual Steps
9
Philip Zeyligere0a9f722025-06-18 13:11:24 -070010## 1. Create VM and SSH Setup
11
12```bash
Philip Zeyligera7e7fb62025-06-17 19:28:12 -070013# Create a throwaway SSH key
14ssh-keygen -t ed25519 -f ~/.ssh/sketch_test_key -P ""
15
16# Create a VM for Sketch to run Docker in
17limactl start --name=dockerhost --cpus=$(nproc) --memory=8 --plain --set='.ssh.localPort=2222' template://ubuntu
18
19# Add the key to the VM
20ssh -F "/Users/philip/.lima/dockerhost/ssh.config" lima-dockerhost tee -a .ssh/authorized_keys < /Users/philip/.ssh/sketch_test_key.pub
Philip Zeyligere0a9f722025-06-18 13:11:24 -070021
22# Create a consistent 'sketch' user for testing
23ssh -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 Zeyligera7e7fb62025-06-17 19:28:12 -070024```
25
Philip Zeyligere0a9f722025-06-18 13:11:24 -070026# Steps that Sketch can do for you!
27
28Once you have SSH access to your host (via `ssh -i ~/.ssh/sketch_test_key -p 2222 sketch@host.docker.internal`),
29Sketch 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
38sudo apt update
39sudo apt install -y docker.io docker-compose
40
41# Add your user to the docker group
42sudo usermod -aG docker sketch
43```
44
45### Install gvisor
46
47```bash
48# Add gvisor GPG key
49curl -fsSL https://gvisor.dev/archive.key | sudo gpg --dearmor -o /usr/share/keyrings/gvisor-archive-keyring.gpg
50
51# Add gvisor repository
52echo "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)
55sudo apt update
56sudo apt install -y runsc
57```
58
59### Configure Docker to use gvisor
60
61```bash
62# Create Docker daemon configuration
63sudo mkdir -p /etc/docker
64echo '{
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
73sudo systemctl restart docker
74```
75
76### Test the Installation
77
78```bash
79# Check that both runtimes are available
80docker info | grep -A5 'Runtimes'
81
82# Test default runtime (runc)
83docker run --rm hello-world
84
85# Test gvisor runtime (runsc)
86docker run --runtime=runsc --rm hello-world
87```
88
89Both commands should successfully run the hello-world container. The gvisor version provides additional security isolation.
90
Philip Zeyligera7e7fb62025-06-17 19:28:12 -070091# 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 Zeyligere0a9f722025-06-18 13:11:24 -070095* 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
100Once everything is set up, configure SSH and test sketch:
101
102```bash
103# Configure SSH for Docker remote access
104mkdir -p ~/.ssh && chmod 700 ~/.ssh
105cp /sketch_test_key ~/.ssh/ && chmod 600 ~/.ssh/sketch_test_key
106
107# Create SSH configuration
108cat > ~/.ssh/config << EOF
109Host 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
116EOF
117
118# Test Docker over SSH
119DOCKER_HOST=ssh://dockerhost docker info
120
121# Test sketch with one-shot command (requires ANTHROPIC_API_KEY)
122DOCKER_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
125The `-skaband-addr=""` flag bypasses authentication for testing, and `-unsafe` allows running without sketch.dev login.