# Dobby Admin Guide

Server: `dobby-hub` / `45.77.219.240`
Domain: `dobby-orchestrator.uk`
Compose: `/mnt/data/dobby/deploy/multi-tenant/`

## Add a New Tenant

When someone sends you their Slack credentials, do these 3 things:

### 1. Create env file

```bash
ssh dobby-hub
cd /mnt/data/dobby/deploy/multi-tenant

cat > tenantN.env << 'EOF'
DOBBY_PORT=842N
DOBBY_HUB_URL=https://tN.dobby-orchestrator.uk
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
SLACK_CHANNEL=C...
SLACK_REPORT_CHANNEL=C...
EOF
```

Port mapping: tenant1=8420, tenant2=8421, tenant3=8422, tenant4=8423, ...

### 2. Create data dirs + start container

```bash
mkdir -p /mnt/data/tenants/tenantN/{data,claude}
docker compose up -d tenantN
```

### 3. Auth Claude Code inside the container

```bash
docker exec -it dobby-tenantN claude
# Follow OAuth in browser, then exit
```

Done. Tell the user their URL is `https://tN.dobby-orchestrator.uk`.

---

## Add Tenant Beyond 3

The default compose has tenant1-3. To add tenant4+:

### a. Add to docker-compose.yml

```yaml
  tenant4:
    image: dobby:latest
    container_name: dobby-tenant4
    ports:
      - "8423:8423"
    volumes:
      - /mnt/data/tenants/tenant4/data:/data
      - /mnt/data/tenants/tenant4/claude:/root/.claude
    env_file:
      - tenant4.env
    environment:
      - DOBBY_PORT=8423
    restart: unless-stopped
```

### b. Add DNS + tunnel route

```bash
# Add DNS record
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/ZONE_ID/dns_records" \
  -H "X-Auth-Key: CF_KEY" -H "X-Auth-Email: CF_EMAIL" \
  -H "Content-Type: application/json" \
  -d '{"type":"CNAME","name":"t4.dobby-orchestrator.uk","content":"TUNNEL_ID.cfargotunnel.com","proxied":true}'

# Update tunnel config (add new ingress before the catch-all)
curl -s -X PUT "https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/cfd_tunnel/TUNNEL_ID/configurations" \
  -H "X-Auth-Key: CF_KEY" -H "X-Auth-Email: CF_EMAIL" \
  -H "Content-Type: application/json" \
  -d '{"config":{"ingress":[
    {"hostname":"t1.dobby-orchestrator.uk","service":"http://localhost:8420"},
    {"hostname":"t2.dobby-orchestrator.uk","service":"http://localhost:8421"},
    {"hostname":"t3.dobby-orchestrator.uk","service":"http://localhost:8422"},
    {"hostname":"t4.dobby-orchestrator.uk","service":"http://localhost:8423"},
    {"service":"http_status:404"}
  ]}}'
```

Then follow steps 1-3 above.

---

## Credentials Reference

```
Cloudflare API Key:  cfk_Bwb9XKB7raqlnPCiUYOi25O84KzhPSCg8mnLuQfBef19e600
Cloudflare Email:    simon011130@gmail.com
Account ID:          dfe72835782582bc7a964e6d110355ff
Zone ID:             8ce8cd454144fd9c190621b88cd34676
Tunnel ID:           4e6441ef-7a98-480c-a70c-f94d3c2c394b
Vultr API Key:       MWJUH62EQ7U7ZI6EWE6ZNLSO7HCDWYP756VQ
```

---

## Common Operations

### Check all tenants
```bash
ssh dobby-hub "docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'"
```

### View logs
```bash
ssh dobby-hub "docker logs dobby-tenantN --tail 30"
ssh dobby-hub "docker exec dobby-tenantN cat /data/logs/daemon.log"
```

### Restart a tenant
```bash
ssh dobby-hub "cd /mnt/data/dobby/deploy/multi-tenant && docker compose restart tenantN"
```

### Update Dobby (all tenants)
```bash
# From local machine — push new code and rebuild
scp -r dobby/ dobby-hub:/mnt/data/dobby/
scp pyproject.toml dobby-hub:/mnt/data/dobby/
ssh dobby-hub "cd /mnt/data/dobby && docker build -t dobby:latest -f deploy/multi-tenant/Dockerfile . && cd deploy/multi-tenant && docker compose down && docker compose up -d"
```

### Remove a tenant
```bash
ssh dobby-hub "cd /mnt/data/dobby/deploy/multi-tenant && docker compose stop tenantN && docker compose rm -f tenantN"
# Data persists in /mnt/data/tenants/tenantN/ — delete manually if desired
```

### Disk usage
```bash
ssh dobby-hub "df -h / && du -sh /mnt/data/tenants/*"
```

### Server info
```bash
ssh dobby-hub "docker ps -a && echo '---' && df -h / && echo '---' && free -h"
```
