aboutsummaryrefslogtreecommitdiffstats
path: root/skills/ship-env/SKILL.md
blob: 692904df186b5e1b03df4fefae67c4eeaf71989c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
name: ship-env
description: 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.
argument-hint: "<app-name> [KEY=VALUE ...]"
---

# ship-env

Read and write environment variables for a deployed app on a ship VPS.
Always merges new values into the existing file — existing vars are never lost.

## Read Config

Load the host from `~/.config/ship/config.json`:

```bash
python3 -c "
import json, os
cfg = json.load(open(os.path.expanduser('~/.config/ship/config.json')))
nick = '<nickname-or-default>'
h = cfg['hosts'].get(nick, cfg['hosts'][cfg['default']])
print(h['host'])
"
```

## Usage Patterns

### View current env vars for an app

```bash
ssh <host> "sudo cat /etc/ship/env/<app-name>.env"
```

Show them to the user clearly. Remind them that PORT, SHIP_NAME, and SHIP_URL are
managed by ship and shouldn't be manually changed.

### Set or update one or more vars

Given vars like `FOO=bar BAZ=qux`, merge them into the existing env file:

```bash
# Read current env
ssh <host> "sudo cat /etc/ship/env/<app-name>.env 2>/dev/null"
```

Then write the merged result back:

```bash
ssh <host> "sudo tee /etc/ship/env/<app-name>.env > /dev/null << 'EOF'
PORT=9013
SHIP_NAME=myapp
SHIP_URL=https://myapp.example.com
FOO=bar
BAZ=qux
EOF"
```

**Merge rules:**
- Start with all existing vars
- Overwrite any keys that appear in the new set
- Add any new keys that didn't exist before
- Never remove existing keys unless explicitly asked

### Delete a var

Only delete a var if the user explicitly asks to remove it by name. Show them the
current value and confirm before removing.

### Restart after changes

After writing new env vars, ask the user if they want to restart the service to apply
them. If yes, use ship-service to restart:

```bash
ssh <host> "sudo systemctl restart <app-name>"
```

## Notes

- Env file lives at `/etc/ship/env/<app-name>.env`
- PORT, SHIP_NAME, and SHIP_URL are written by ship-binary/ship-deploy — don't remove them
- If the env file doesn't exist, the app probably isn't deployed yet — say so
- Use the default host unless a host nickname was specified (e.g. "set FOO=bar on staging")
- After updating, remind the user the service needs a restart to pick up changes