diff options
Diffstat (limited to 'skills/ship-setup/SKILL.md')
| -rw-r--r-- | skills/ship-setup/SKILL.md | 93 |
1 files changed, 31 insertions, 62 deletions
diff --git a/skills/ship-setup/SKILL.md b/skills/ship-setup/SKILL.md index e3d08ee..73297b6 100644 --- a/skills/ship-setup/SKILL.md +++ b/skills/ship-setup/SKILL.md | |||
| @@ -8,11 +8,21 @@ argument-hint: "[host-nickname]" | |||
| 8 | 8 | ||
| 9 | Configure ship and prepare a VPS for deployments. | 9 | Configure ship and prepare a VPS for deployments. |
| 10 | 10 | ||
| 11 | ## Companion Script | ||
| 12 | |||
| 13 | Server setup is handled by `setup.sh` in this skill's directory. It is idempotent, | ||
| 14 | handles all branching logic, and mirrors the behavior of the original `ship host init` | ||
| 15 | Go CLI command. | ||
| 16 | |||
| 17 | ``` | ||
| 18 | skills/ship-setup/setup.sh <ssh-host> <base-domain> <nickname> [--default] | ||
| 19 | ``` | ||
| 20 | |||
| 11 | ## Config File | 21 | ## Config File |
| 12 | 22 | ||
| 13 | All ship skills read from `~/.config/ship/config.json`. This skill creates or updates it. | 23 | All ship skills read from `~/.config/ship/config.json`. The setup script creates or |
| 24 | updates it — never overwrites the whole file. | ||
| 14 | 25 | ||
| 15 | Structure: | ||
| 16 | ```json | 26 | ```json |
| 17 | { | 27 | { |
| 18 | "default": "prod", | 28 | "default": "prod", |
| @@ -43,80 +53,39 @@ If it exists, show the user the current hosts so they know what's already config | |||
| 43 | 53 | ||
| 44 | ### 2. Get host details | 54 | ### 2. Get host details |
| 45 | 55 | ||
| 46 | If no nickname was provided as an argument, ask the user: | 56 | If not already known, ask the user: |
| 47 | - **Nickname** — a short name for this host (e.g. `prod`, `staging`, `vps`) | 57 | - **Nickname** — short name for this host (e.g. `prod`, `staging`) |
| 48 | - **SSH connection string** — e.g. `ubuntu@1.2.3.4` or an SSH config alias like `alaskav6` | 58 | - **SSH connection string** — e.g. `ubuntu@1.2.3.4` or an alias from `~/.ssh/config` |
| 49 | - **Base domain** — the domain pointing to this server (e.g. `example.com`) | 59 | - **Base domain** — the domain pointing to this server (e.g. `example.com`) |
| 60 | - **Default?** — if this is the first host, make it default. Otherwise ask. | ||
| 50 | 61 | ||
| 51 | If this is the first host, ask if it should be the default. If hosts already exist, ask if this should replace the current default. | 62 | ### 3. Run the setup script |
| 52 | |||
| 53 | ### 3. Test SSH connection | ||
| 54 | |||
| 55 | Verify the connection works before saving anything: | ||
| 56 | |||
| 57 | ```bash | ||
| 58 | ssh -o ConnectTimeout=5 <host> "echo ok" | ||
| 59 | ``` | ||
| 60 | |||
| 61 | If it fails, tell the user and stop. Don't save config for an unreachable host. | ||
| 62 | |||
| 63 | ### 4. Save config | ||
| 64 | |||
| 65 | Write or update `~/.config/ship/config.json` with the new host. Merge with existing hosts — never overwrite the whole file. Use Python to safely read/write JSON: | ||
| 66 | |||
| 67 | ```bash | ||
| 68 | python3 -c " | ||
| 69 | import json, os | ||
| 70 | path = os.path.expanduser('~/.config/ship/config.json') | ||
| 71 | os.makedirs(os.path.dirname(path), exist_ok=True) | ||
| 72 | cfg = json.load(open(path)) if os.path.exists(path) else {'default': None, 'hosts': {}} | ||
| 73 | cfg['hosts']['<nickname>'] = {'host': '<ssh-host>', 'domain': '<domain>'} | ||
| 74 | if not cfg['default']: | ||
| 75 | cfg['default'] = '<nickname>' | ||
| 76 | json.dump(cfg, open(path, 'w'), indent=2) | ||
| 77 | print('saved') | ||
| 78 | " | ||
| 79 | ``` | ||
| 80 | |||
| 81 | ### 5. Install server dependencies | ||
| 82 | |||
| 83 | SSH in and ensure the required directories and software exist. This is idempotent — safe to run multiple times. | ||
| 84 | |||
| 85 | **Install Caddy** (if not present): | ||
| 86 | ```bash | ||
| 87 | ssh <host> "which caddy || (sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list && sudo apt-get update && sudo apt-get install -y caddy)" | ||
| 88 | ``` | ||
| 89 | 63 | ||
| 90 | **Create directory structure:** | ||
| 91 | ```bash | 64 | ```bash |
| 92 | ssh <host> "sudo mkdir -p /etc/ship/env /etc/ship/ports /etc/caddy/sites-enabled /var/www && sudo chmod 755 /etc/ship" | 65 | bash ~/.claude/skills/ship-setup/setup.sh <ssh-host> <domain> <nickname> [--default] |
| 93 | ``` | 66 | ``` |
| 94 | 67 | ||
| 95 | **Configure main Caddyfile** (only if not already set up): | 68 | The script will: |
| 96 | ```bash | 69 | 1. Test the SSH connection — stops early if it fails |
| 97 | ssh <host> "sudo test -f /etc/caddy/Caddyfile && echo exists || echo '{ | 70 | 2. Detect OS (Ubuntu/Debian only) |
| 98 | } | 71 | 3. Install Caddy if not present |
| 99 | 72 | 4. Configure the main Caddyfile if not already set up | |
| 100 | import /etc/caddy/sites-enabled/*' | sudo tee /etc/caddy/Caddyfile" | 73 | 5. Create required directories (`/etc/ship/env`, `/etc/ship/ports`, `/etc/caddy/sites-enabled`, `/var/www`) |
| 101 | ``` | 74 | 6. Enable and start Caddy |
| 102 | 75 | 7. Save the host to `~/.config/ship/config.json` | |
| 103 | **Enable and start Caddy:** | ||
| 104 | ```bash | ||
| 105 | ssh <host> "sudo systemctl enable caddy && sudo systemctl start caddy" | ||
| 106 | ``` | ||
| 107 | 76 | ||
| 108 | ### 6. Confirm | 77 | ### 4. Confirm |
| 109 | 78 | ||
| 110 | Tell the user: | 79 | Tell the user: |
| 111 | - Host nickname and SSH target saved | 80 | - Host nickname and SSH target saved |
| 112 | - Whether it's the default host | 81 | - Whether it's the default host |
| 113 | - That the server is ready for deployments | 82 | - That the server is ready for deployments |
| 114 | - How to add another host: `/ship-setup <nickname>` | 83 | - How to add another host: `/ship-setup` |
| 115 | - How to deploy: `/ship-deploy` | 84 | - How to deploy: `/ship-deploy` |
| 116 | 85 | ||
| 117 | ## Notes | 86 | ## Notes |
| 118 | 87 | ||
| 119 | - Never overwrite the entire config file — always merge | 88 | - Safe to run multiple times — all steps are idempotent |
| 120 | - If a nickname already exists in config, confirm before overwriting it | 89 | - The SSH host can be an alias from `~/.ssh/config` |
| 121 | - The SSH host can be an alias from `~/.ssh/config` — no need to require raw IP | 90 | - If a nickname already exists in config, the script overwrites it — confirm with the user first |
| 122 | - Default host is used by all other ship skills when no host is specified | 91 | - Default host is used by all other ship skills when no host is specified |
