|
| 1 | +--- |
| 2 | +sidebar_position: 4 |
| 3 | +--- |
| 4 | + |
| 5 | +# Scripts |
| 6 | + |
| 7 | +Run custom scripts after workspace starts. Scripts execute after file sync, so they can reference synced resources. |
| 8 | + |
| 9 | +## Configuration |
| 10 | + |
| 11 | +### Via config.json |
| 12 | + |
| 13 | +```json |
| 14 | +{ |
| 15 | + "scripts": { |
| 16 | + "post_start": [ |
| 17 | + "~/.perry/userscripts", |
| 18 | + "~/scripts/setup.sh" |
| 19 | + ], |
| 20 | + "fail_on_error": false |
| 21 | + } |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +### Via Web UI |
| 26 | + |
| 27 | +1. Open http://localhost:7391 |
| 28 | +2. Go to Settings > Scripts |
| 29 | +3. Add script paths or directories |
| 30 | +4. Toggle "Stop on script error" if needed |
| 31 | +5. Save |
| 32 | + |
| 33 | +## Default Configuration |
| 34 | + |
| 35 | +New installations include: |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "scripts": { |
| 40 | + "post_start": ["~/.perry/userscripts"], |
| 41 | + "fail_on_error": false |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +Create `~/.perry/userscripts/` directory on your host to add startup scripts. |
| 47 | + |
| 48 | +## Script Types |
| 49 | + |
| 50 | +### Single Scripts |
| 51 | + |
| 52 | +Point to a shell script file: |
| 53 | + |
| 54 | +```json |
| 55 | +{ |
| 56 | + "scripts": { |
| 57 | + "post_start": ["~/scripts/setup.sh"] |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +The script must be executable (`chmod +x`). |
| 63 | + |
| 64 | +### Script Directories |
| 65 | + |
| 66 | +Point to a directory containing `.sh` files: |
| 67 | + |
| 68 | +```json |
| 69 | +{ |
| 70 | + "scripts": { |
| 71 | + "post_start": ["~/.perry/userscripts"] |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +All `.sh` files in the directory execute in **sorted order** (alphabetical). Use numeric prefixes to control order: |
| 77 | + |
| 78 | +``` |
| 79 | +~/.perry/userscripts/ |
| 80 | + 01-install-tools.sh |
| 81 | + 02-configure-git.sh |
| 82 | + 10-setup-project.sh |
| 83 | +``` |
| 84 | + |
| 85 | +Non-`.sh` files are ignored. |
| 86 | + |
| 87 | +## Multiple Sources |
| 88 | + |
| 89 | +Combine scripts and directories: |
| 90 | + |
| 91 | +```json |
| 92 | +{ |
| 93 | + "scripts": { |
| 94 | + "post_start": [ |
| 95 | + "~/.perry/userscripts", |
| 96 | + "~/work/company-setup.sh", |
| 97 | + "~/projects/tools" |
| 98 | + ] |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +Scripts execute in array order. |
| 104 | + |
| 105 | +## Error Handling |
| 106 | + |
| 107 | +### Default: Continue on Error |
| 108 | + |
| 109 | +```json |
| 110 | +{ |
| 111 | + "scripts": { |
| 112 | + "post_start": ["~/scripts/setup.sh"], |
| 113 | + "fail_on_error": false |
| 114 | + } |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +If a script fails, Perry logs a warning and continues with remaining scripts. Workspace starts normally. |
| 119 | + |
| 120 | +### Strict Mode |
| 121 | + |
| 122 | +```json |
| 123 | +{ |
| 124 | + "scripts": { |
| 125 | + "post_start": ["~/scripts/setup.sh"], |
| 126 | + "fail_on_error": true |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +If any script exits with non-zero status, workspace startup fails. |
| 132 | + |
| 133 | +## Execution Environment |
| 134 | + |
| 135 | +Scripts run: |
| 136 | +- As the `workspace` user |
| 137 | +- In the container's home directory (`/home/workspace`) |
| 138 | +- After file sync completes (synced files are available) |
| 139 | +- With access to configured environment variables |
| 140 | + |
| 141 | +## Common Use Cases |
| 142 | + |
| 143 | +### Install Project Tools |
| 144 | + |
| 145 | +```bash |
| 146 | +#!/bin/bash |
| 147 | +# ~/.perry/userscripts/01-install-tools.sh |
| 148 | + |
| 149 | +# Install global npm packages |
| 150 | +npm install -g typescript tsx |
| 151 | + |
| 152 | +# Install rust tools |
| 153 | +cargo install just |
| 154 | +``` |
| 155 | + |
| 156 | +### Configure Git |
| 157 | + |
| 158 | +```bash |
| 159 | +#!/bin/bash |
| 160 | +# ~/.perry/userscripts/02-git-config.sh |
| 161 | + |
| 162 | +# Set up git aliases not in .gitconfig |
| 163 | +git config --global alias.st status |
| 164 | +git config --global alias.co checkout |
| 165 | +``` |
| 166 | + |
| 167 | +### Create Symlinks |
| 168 | + |
| 169 | +```bash |
| 170 | +#!/bin/bash |
| 171 | +# ~/.perry/userscripts/03-symlinks.sh |
| 172 | + |
| 173 | +# Link synced config directories |
| 174 | +ln -sf ~/.synced-nvim ~/.config/nvim |
| 175 | +ln -sf ~/.synced-tmux/.tmux.conf ~/.tmux.conf |
| 176 | +``` |
| 177 | + |
| 178 | +### Start Background Services |
| 179 | + |
| 180 | +```bash |
| 181 | +#!/bin/bash |
| 182 | +# ~/.perry/userscripts/99-services.sh |
| 183 | + |
| 184 | +# Start any background services needed |
| 185 | +# (Note: prefer using Docker services when possible) |
| 186 | +``` |
| 187 | + |
| 188 | +## Path Expansion |
| 189 | + |
| 190 | +- `~` expands to home directory on host |
| 191 | +- Scripts are copied to container and executed there |
| 192 | +- Absolute paths work as-is |
| 193 | + |
| 194 | +## Apply Changes |
| 195 | + |
| 196 | +Scripts run: |
| 197 | +- When creating new workspaces |
| 198 | +- When starting stopped workspaces |
| 199 | + |
| 200 | +Scripts do **not** run when syncing (`perry sync`) - only file sync occurs. |
| 201 | + |
| 202 | +## Debugging |
| 203 | + |
| 204 | +Check script output in workspace logs: |
| 205 | + |
| 206 | +```bash |
| 207 | +perry logs myworkspace |
| 208 | +``` |
| 209 | + |
| 210 | +Or connect to the workspace and check manually: |
| 211 | + |
| 212 | +```bash |
| 213 | +perry ssh myworkspace |
| 214 | +``` |
0 commit comments