aboutsummaryrefslogtreecommitdiffstats
path: root/skills/ship-setup
diff options
context:
space:
mode:
Diffstat (limited to 'skills/ship-setup')
-rw-r--r--skills/ship-setup/SKILL.md122
1 files changed, 122 insertions, 0 deletions
diff --git a/skills/ship-setup/SKILL.md b/skills/ship-setup/SKILL.md
new file mode 100644
index 0000000..e3d08ee
--- /dev/null
+++ b/skills/ship-setup/SKILL.md
@@ -0,0 +1,122 @@
1---
2name: ship-setup
3description: Set up ship for the first time or add a new VPS host. Saves host config to ~/.config/ship/config.json and installs server dependencies. Use when configuring ship for the first time, or adding/changing a host.
4argument-hint: "[host-nickname]"
5---
6
7# ship-setup
8
9Configure ship and prepare a VPS for deployments.
10
11## Config File
12
13All ship skills read from `~/.config/ship/config.json`. This skill creates or updates it.
14
15Structure:
16```json
17{
18 "default": "prod",
19 "hosts": {
20 "prod": {
21 "host": "ubuntu@1.2.3.4",
22 "domain": "example.com"
23 },
24 "staging": {
25 "host": "ubuntu@5.6.7.8",
26 "domain": "staging.example.com"
27 }
28 }
29}
30```
31
32## Steps
33
34### 1. Read existing config
35
36Check if `~/.config/ship/config.json` exists:
37
38```bash
39cat ~/.config/ship/config.json 2>/dev/null
40```
41
42If it exists, show the user the current hosts so they know what's already configured.
43
44### 2. Get host details
45
46If no nickname was provided as an argument, ask the user:
47- **Nickname** — a short name for this host (e.g. `prod`, `staging`, `vps`)
48- **SSH connection string** — e.g. `ubuntu@1.2.3.4` or an SSH config alias like `alaskav6`
49- **Base domain** — the domain pointing to this server (e.g. `example.com`)
50
51If this is the first host, ask if it should be the default. If hosts already exist, ask if this should replace the current default.
52
53### 3. Test SSH connection
54
55Verify the connection works before saving anything:
56
57```bash
58ssh -o ConnectTimeout=5 <host> "echo ok"
59```
60
61If it fails, tell the user and stop. Don't save config for an unreachable host.
62
63### 4. Save config
64
65Write 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
68python3 -c "
69import json, os
70path = os.path.expanduser('~/.config/ship/config.json')
71os.makedirs(os.path.dirname(path), exist_ok=True)
72cfg = json.load(open(path)) if os.path.exists(path) else {'default': None, 'hosts': {}}
73cfg['hosts']['<nickname>'] = {'host': '<ssh-host>', 'domain': '<domain>'}
74if not cfg['default']:
75 cfg['default'] = '<nickname>'
76json.dump(cfg, open(path, 'w'), indent=2)
77print('saved')
78"
79```
80
81### 5. Install server dependencies
82
83SSH 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
87ssh <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
90**Create directory structure:**
91```bash
92ssh <host> "sudo mkdir -p /etc/ship/env /etc/ship/ports /etc/caddy/sites-enabled /var/www && sudo chmod 755 /etc/ship"
93```
94
95**Configure main Caddyfile** (only if not already set up):
96```bash
97ssh <host> "sudo test -f /etc/caddy/Caddyfile && echo exists || echo '{
98}
99
100import /etc/caddy/sites-enabled/*' | sudo tee /etc/caddy/Caddyfile"
101```
102
103**Enable and start Caddy:**
104```bash
105ssh <host> "sudo systemctl enable caddy && sudo systemctl start caddy"
106```
107
108### 6. Confirm
109
110Tell the user:
111- Host nickname and SSH target saved
112- Whether it's the default host
113- That the server is ready for deployments
114- How to add another host: `/ship-setup <nickname>`
115- How to deploy: `/ship-deploy`
116
117## Notes
118
119- Never overwrite the entire config file — always merge
120- If a nickname already exists in config, confirm before overwriting it
121- The SSH host can be an alias from `~/.ssh/config` — no need to require raw IP
122- Default host is used by all other ship skills when no host is specified