aboutsummaryrefslogtreecommitdiffstats
path: root/skills/ship-env
diff options
context:
space:
mode:
Diffstat (limited to 'skills/ship-env')
-rw-r--r--skills/ship-env/SKILL.md84
1 files changed, 84 insertions, 0 deletions
diff --git a/skills/ship-env/SKILL.md b/skills/ship-env/SKILL.md
new file mode 100644
index 0000000..692904d
--- /dev/null
+++ b/skills/ship-env/SKILL.md
@@ -0,0 +1,84 @@
1---
2name: ship-env
3description: Read or write environment variables for a deployed app. Always merges — never overwrites existing vars. Use when you need to set, update, or view env vars for an app without redeploying.
4argument-hint: "<app-name> [KEY=VALUE ...]"
5---
6
7# ship-env
8
9Read and write environment variables for a deployed app on a ship VPS.
10Always merges new values into the existing file — existing vars are never lost.
11
12## Read Config
13
14Load the host from `~/.config/ship/config.json`:
15
16```bash
17python3 -c "
18import json, os
19cfg = json.load(open(os.path.expanduser('~/.config/ship/config.json')))
20nick = '<nickname-or-default>'
21h = cfg['hosts'].get(nick, cfg['hosts'][cfg['default']])
22print(h['host'])
23"
24```
25
26## Usage Patterns
27
28### View current env vars for an app
29
30```bash
31ssh <host> "sudo cat /etc/ship/env/<app-name>.env"
32```
33
34Show them to the user clearly. Remind them that PORT, SHIP_NAME, and SHIP_URL are
35managed by ship and shouldn't be manually changed.
36
37### Set or update one or more vars
38
39Given vars like `FOO=bar BAZ=qux`, merge them into the existing env file:
40
41```bash
42# Read current env
43ssh <host> "sudo cat /etc/ship/env/<app-name>.env 2>/dev/null"
44```
45
46Then write the merged result back:
47
48```bash
49ssh <host> "sudo tee /etc/ship/env/<app-name>.env > /dev/null << 'EOF'
50PORT=9013
51SHIP_NAME=myapp
52SHIP_URL=https://myapp.example.com
53FOO=bar
54BAZ=qux
55EOF"
56```
57
58**Merge rules:**
59- Start with all existing vars
60- Overwrite any keys that appear in the new set
61- Add any new keys that didn't exist before
62- Never remove existing keys unless explicitly asked
63
64### Delete a var
65
66Only delete a var if the user explicitly asks to remove it by name. Show them the
67current value and confirm before removing.
68
69### Restart after changes
70
71After writing new env vars, ask the user if they want to restart the service to apply
72them. If yes, use ship-service to restart:
73
74```bash
75ssh <host> "sudo systemctl restart <app-name>"
76```
77
78## Notes
79
80- Env file lives at `/etc/ship/env/<app-name>.env`
81- PORT, SHIP_NAME, and SHIP_URL are written by ship-binary/ship-deploy — don't remove them
82- If the env file doesn't exist, the app probably isn't deployed yet — say so
83- Use the default host unless a host nickname was specified (e.g. "set FOO=bar on staging")
84- After updating, remind the user the service needs a restart to pick up changes