--- name: ship-static description: Deploy a static site to a ship VPS. Rsyncs a local dist folder to the server and configures Caddy to serve it. Use when deploying a built frontend, docs site, or any folder of static files. argument-hint: " [host-nickname]" --- # ship-static Deploy a static site by rsyncing a local directory to the server and configuring Caddy. ## Read Config ```bash python3 -c " import json, os cfg = json.load(open(os.path.expanduser('~/.config/ship/config.json'))) nick = '' h = cfg['hosts'].get(nick, cfg['hosts'][cfg['default']]) print(h['host']) print(h['domain']) " ``` ## Inputs - **Dist path** — local directory containing the built static files (e.g. `./dist`, `./out`) - **App name** — short lowercase name, becomes the subdomain (e.g. `mysite`) - **Domain** — defaults to `.`, ask if different - **Host** — use default unless specified ## Steps ### 1. Validate local path Check that the dist directory exists and contains an `index.html`: ```bash ls /index.html ``` If not found, tell the user — they may need to build first. ### 2. Create remote directory ```bash ssh "sudo mkdir -p /var/www/ && sudo chown $USER:$USER /var/www/" ``` ### 3. Sync files ```bash rsync -avz --delete / :/var/www// ``` The `--delete` flag removes files on the server that no longer exist locally, keeping the deployment clean. Tell the user how many files were transferred. ### 4. Fix ownership After rsync, ensure Caddy can read the files: ```bash ssh "sudo chown -R www-data:www-data /var/www/" ``` ### 5. Write Caddy config Check if a config already exists: ```bash ssh "cat /etc/caddy/sites-enabled/.caddy 2>/dev/null" ``` Write (or overwrite) the config: ```bash ssh "sudo tee /etc/caddy/sites-enabled/.caddy > /dev/null << 'EOF' { root * /var/www/ file_server encode gzip } EOF" ``` ### 6. Validate and reload Caddy ```bash ssh "sudo caddy validate --config /etc/caddy/Caddyfile 2>&1" ``` If valid: ```bash ssh "sudo systemctl reload caddy" ``` If invalid, show the error and do not reload. ### 7. Confirm Tell the user: - URL the site is live at - Number of files synced - Whether this was a new deployment or an update ## Notes - Build before deploying — this skill does not run build commands - `--delete` in rsync means files removed locally will be removed from the server too - If the user wants a custom domain, use ship-caddy to update the config after deploying - For SPAs with client-side routing, the Caddy config may need a `try_files` directive: ``` { root * /var/www/ try_files {path} /index.html file_server encode gzip } ``` Ask the user if their site uses client-side routing. - Use default host unless another is specified