torrust-tracker-deployer 0.1.0

Torrust Tracker Deployer - Deployment Infrastructure with Ansible and OpenTofu
Documentation
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# AI Agent Training Materials

This directory contains resources to help AI agents guide users through creating Torrust Tracker environment configurations.

## Contents

- **[questionnaire.md]questionnaire.md** - Structured decision tree for gathering user requirements
- **[dataset/environment-configs/]dataset/environment-configs/** - 15 pre-configured environment examples demonstrating common deployment scenarios
- **[dataset/rendered-templates/]dataset/rendered-templates/** - Rendered deployment artifacts for all examples (complete input/output pairs)

## Purpose

These materials enable AI agents to:

1. **Guide users through configuration decisions** using the questionnaire's structured approach
2. **Recommend appropriate starting configurations** based on user requirements
3. **Explain configuration tradeoffs** between different deployment options
4. **Help users customize** example configurations for their specific needs

## Dataset Structure: Input/Output Pairs

This directory contains a **complete AI training dataset** with both inputs and outputs:

### Input: Environment Configurations

- Location: [`dataset/environment-configs/`]dataset/environment-configs/
- Format: JSON configuration files
- Content: High-level deployment requirements (provider, database, domains, etc.)

### Output: Rendered Deployment Artifacts

- Location: [`dataset/rendered-templates/`]dataset/rendered-templates/
- Format: Rendered templates (Ansible, Docker Compose, configuration files)
- Content: Concrete artifacts ready for deployment

### The Deployer as a Function

```text
config.json → [Deployer] → Rendered Templates
   (IN)                         (OUT)
```

The deployer transforms:

- **FROM**: Desired infrastructure state in custom domain language
- **TO**: Executable deployment artifacts

### Example Mapping

| Input (Config)                                                                                       | Output (Artifacts)                                                                         |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| [`dataset/environment-configs/01-minimal-lxd.json`]dataset/environment-configs/01-minimal-lxd.json | [`dataset/rendered-templates/01-minimal-lxd/`]dataset/rendered-templates/01-minimal-lxd/ |
| SQLite + UDP + HTTP + LXD                                                                            | Ansible playbooks, tracker.toml, docker-compose, etc.                                      |

**Benefits for AI Agents:**

- **Few-shot learning**: Full input/output examples show transformation patterns
- **Pattern recognition**: See how config changes affect rendered templates
- **Diff analysis**: Compare outputs to understand configuration impact
- **Template understanding**: Learn the structure of deployment artifacts

**Regenerating Outputs**: Run `./scripts/generate-ai-training-outputs.sh` to update artifacts when templates change.

## Using the Questionnaire

The [questionnaire.md](questionnaire.md) provides a systematic approach to gather user requirements across 14 key areas:

1. **Deployment Goal** - Understand use case (production, development, testing)
2. **Provider Selection** - Choose between LXD (local) or Hetzner (cloud)
3. **Database Configuration** - Select SQLite3 or MySQL based on needs
4. **Tracker Protocol** - Configure UDP, HTTP, or both
5. **HTTPS/TLS** - Determine if encryption is needed
6. **Monitoring** - Decide on Prometheus + Grafana integration
7. **Backup Strategy** - Configure automated backups if needed
8. **Advanced Features** - Private tracker mode, custom domains, etc.

### Questionnaire Workflow

```mermaid
graph TD
    A[Start] --> B[Understand Deployment Goal]
    B --> C[Select Provider]
    C --> D[Choose Database]
    D --> E[Configure Protocols]
    E --> F[HTTPS Requirements?]
    F --> G[Monitoring Needed?]
    G --> H[Backup Strategy?]
    H --> I[Review Configuration]
    I --> J[Recommend Example]
    J --> K[Guide Customization]
```

**AI Agent Instructions:**

1. Work through sections sequentially
2. Ask clarifying questions when user needs are unclear
3. Explain tradeoffs (e.g., SQLite vs MySQL, LXD vs Hetzner)
4. Recommend specific examples based on collected requirements
5. Help users customize the example for their specific needs

## Example Configurations

### Core Examples (01-05)

Fundamental deployment patterns demonstrating basic configurations:

| Example | Name                                                                         | Provider | Database | HTTPS | Monitoring | Backups | Use Case                                   |
| ------- | ---------------------------------------------------------------------------- | -------- | -------- | ----- | ---------- | ------- | ------------------------------------------ |
| 01      | [minimal-lxd]dataset/environment-configs/01-minimal-lxd.json               | LXD      | SQLite3  | ✗     | ✗          | ✗       | Quick local testing, learning basics       |
| 02      | [full-stack-lxd]dataset/environment-configs/02-full-stack-lxd.json         | LXD      | MySQL    | ✓     | ✓          | ✓       | Complete local setup, testing all features |
| 03      | [minimal-hetzner]dataset/environment-configs/03-minimal-hetzner.json       | Hetzner  | SQLite3  | ✗     | ✗          | ✗       | Simple cloud deployment, proof of concept  |
| 04      | [full-stack-hetzner]dataset/environment-configs/04-full-stack-hetzner.json | Hetzner  | MySQL    | ✓     | ✓          | ✓       | Production-ready cloud deployment          |
| 05      | [mysql-development]dataset/environment-configs/05-mysql-development.json   | LXD      | MySQL    | ✗     | ✗          | ✗       | Database-focused development               |

### Extended Examples (06-15)

Specialized configurations for specific requirements:

| Example | Name                                                                                 | Provider | Database | HTTPS | Monitoring | Backups | Use Case                                    |
| ------- | ------------------------------------------------------------------------------------ | -------- | -------- | ----- | ---------- | ------- | ------------------------------------------- |
| 06      | [production-https]dataset/environment-configs/06-production-https.json             | LXD      | MySQL    | ✓     | ✓          | ✗       | Secure production without backup complexity |
| 07      | [udp-only]dataset/environment-configs/07-udp-only.json                             | LXD      | SQLite3  | ✗     | ✗          | ✗       | UDP tracker testing, minimal footprint      |
| 08      | [http-only-https]dataset/environment-configs/08-http-only-https.json               | LXD      | MySQL    | ✓     | ✓          | ✗       | HTTP API-focused, secure web interface      |
| 09      | [monitoring-stack]dataset/environment-configs/09-monitoring-stack.json             | LXD      | MySQL    | ✗     | ✓          | ✗       | Monitoring development, dashboard testing   |
| 10      | [multi-domain]dataset/environment-configs/10-multi-domain.json                     | LXD      | MySQL    | ✓     | ✓          | ✗       | Multiple domain architecture                |
| 11      | [private-tracker]dataset/environment-configs/11-private-tracker.json               | LXD      | MySQL    | ✓     | ✓          | ✗       | Private tracker with user whitelisting      |
| 12      | [high-availability]dataset/environment-configs/12-high-availability.json           | Hetzner  | MySQL    | ✓     | ✓          | ✓       | Mission-critical production                 |
| 13      | [backup-focused]dataset/environment-configs/13-backup-focused.json                 | LXD      | MySQL    | ✗     | ✓          | ✓       | Data protection priority (4hr backups)      |
| 14      | [lightweight-production]dataset/environment-configs/14-lightweight-production.json | Hetzner  | SQLite3  | ✓     | ✗          | ✗       | Cost-effective production                   |
| 15      | [sqlite-monitoring]dataset/environment-configs/15-sqlite-monitoring.json           | LXD      | SQLite3  | ✗     | ✓          | ✗       | Simple database + full monitoring           |

## Scenario-to-Example Mapping

Use this guide to recommend examples based on user scenarios:

### "I want to quickly test the tracker locally"

→ **Example 01** (minimal-lxd): Fastest setup, minimal dependencies

### "I need a production tracker in the cloud"

→ **Example 04** (full-stack-hetzner): Complete production features
→ **Example 12** (high-availability): Mission-critical with backups

### "I'm developing monitoring dashboards"

→ **Example 09** (monitoring-stack): Full Prometheus + Grafana without HTTPS complexity

### "I need HTTPS for my tracker API"

→ **Example 06** (production-https): HTTPS-focused without backup overhead
→ **Example 08** (http-only-https): HTTP API-only with TLS

### "I want to test only UDP tracker functionality"

→ **Example 07** (udp-only): Isolated UDP tracker testing

### "I need a private tracker with user control"

→ **Example 11** (private-tracker): Private mode with user whitelisting

### "I'm on a tight budget but need cloud hosting"

→ **Example 14** (lightweight-production): Smallest Hetzner server, minimal features

### "Data backups are my top priority"

→ **Example 13** (backup-focused): Aggressive backup strategy (every 4 hours, 14-day retention)

### "I want to learn all features locally"

→ **Example 02** (full-stack-lxd): Complete feature set on LXD

### "I need to serve multiple domains"

→ **Example 10** (multi-domain): Separate domains for tracker and Grafana

## Configuration Customization Guide

After selecting an example, guide users through common customizations:

### 1. Environment Name

```json
{
  "environment": {
    "name": "my-custom-tracker", // Change this
    "description": "My production tracker"
  }
}
```

### 2. SSH Credentials

```json
{
  "ssh_credentials": {
    "private_key_path": "/home/username/.ssh/id_rsa", // User's actual key path
    "public_key_path": "/home/username/.ssh/id_rsa.pub"
  }
}
```

### 3. Provider Configuration

**For LXD:**

```json
{
  "provider": {
    "provider": "lxd",
    "profile_name": "torrust-profile-custom" // Customize profile name
  }
}
```

**For Hetzner:**

```json
{
  "provider": {
    "provider": "hetzner",
    "api_token": "$HETZNER_API_TOKEN", // Environment variable or actual token
    "server_type": "cx21", // Adjust size: cx11, cx21, cx31, cx41
    "location": "nbg1", // Or: fsn1, hel1, ash
    "image": "ubuntu-24.04"
  }
}
```

### 4. Database Configuration

**SQLite3:**

```json
{
  "database": {
    "driver": "sqlite3",
    "database_name": "tracker.db" // Filename only
  }
}
```

**MySQL:**

```json
{
  "database": {
    "driver": "mysql",
    "host": "mysql",
    "port": 3306,
    "database_name": "tracker",
    "username": "tracker_user",
    "password": "ChangeThisPassword!" // Use strong password
  }
}
```

### 5. Tracker Protocols

**Enable/Disable UDP:**

```json
{
  "udp_trackers": [
    {
      "bind_address": "0.0.0.0:6969" // Standard BitTorrent port
    }
  ]
}
```

**Enable/Disable HTTP:**

```json
{
  "http_trackers": [
    {
      "bind_address": "0.0.0.0:7070" // Custom HTTP port
    }
  ]
}
```

### 6. HTTPS/TLS Configuration

**Enable HTTPS with Caddy:**

```json
{
  "caddy": {
    "domain": "tracker.yourdomain.com", // Your domain
    "email": "admin@yourdomain.com", // Let's Encrypt email
    "grafana_domain": "grafana.yourdomain.com" // Optional: separate Grafana domain
  }
}
```

**Requirements:**

- Domain must point to the server's public IP
- Ports 80 and 443 must be accessible
- Valid email for Let's Encrypt certificate notifications

### 7. Monitoring Configuration

**Prometheus:**

```json
{
  "prometheus": {
    "scrape_interval_in_secs": 15 // 15-30 recommended, higher for less load
  }
}
```

**Grafana:**

```json
{
  "grafana": {
    "admin_user": "admin",
    "admin_password": "ChangeThisPassword!" // Use strong password
  }
}
```

### 8. Backup Configuration

```json
{
  "backup": {
    "schedule": "0 2 * * *", // Cron format: daily at 2 AM
    "retention_days": 7 // Keep backups for 7 days
  }
}
```

**Common schedules:**

- `"0 */4 * * *"` - Every 4 hours
- `"0 2 * * *"` - Daily at 2 AM
- `"0 3 * * 0"` - Weekly on Sunday at 3 AM

### 9. Private Tracker Mode

```json
{
  "tracker": {
    "core": {
      "private": true // Enable private mode (requires user whitelisting)
    }
  }
}
```

## Validation

All examples have been validated with the `validate` command:

```bash
cargo run -- validate --env-file docs/ai-training/dataset/environment-configs/01-minimal-lxd.json
```

Expected output:

```text
✅ Configuration file 'docs/ai-training/dataset/environment-configs/01-minimal-lxd.json' is valid
```

## Creating Custom Configurations

Guide users through creating custom configurations:

1. **Start with the closest example** from the tables above
2. **Copy and rename** the file (e.g., `my-tracker.json`)
3. **Customize** required fields (name, SSH keys, domain, passwords)
4. **Validate** the configuration:

   ```bash
   cargo run -- validate --env-file my-tracker.json
   ```

5. **Create environment**:

   ```bash
   cargo run -- create environment --env-file my-tracker.json
   ```

## Common Decision Points

Help users make informed choices:

### Provider: LXD vs Hetzner

**Choose LXD when:**

- Testing locally before cloud deployment
- Learning the system
- No public IP needed
- Free local resources available

**Choose Hetzner when:**

- Need public internet access
- Production deployment
- Want managed infrastructure
- Budget allows (~€4-20/month)

### Database: SQLite3 vs MySQL

**Choose SQLite3 when:**

- Single-server deployment
- Low to medium traffic
- Simplicity is priority
- Development/testing

**Choose MySQL when:**

- High traffic expected
- Need advanced database features
- Plan to scale horizontally (future)
- Production deployment

### HTTPS: Yes or No

**Enable HTTPS when:**

- Public internet deployment
- Security/privacy requirements
- Using HTTP API in production

**Skip HTTPS when:**

- Local testing only
- Behind VPN or private network
- Development environment

### Monitoring: Yes or No

**Enable Monitoring when:**

- Production deployment
- Need performance insights
- Troubleshooting issues
- Learning system behavior

**Skip Monitoring when:**

- Minimal testing
- Resource-constrained
- Simple UDP-only tracker

## Next Steps

After configuration is created and validated:

1. **Provision infrastructure**: `cargo run -- provision --env <name>`
2. **Configure services**: `cargo run -- configure --env <name>`
3. **Release software**: `cargo run -- release --env <name>`
4. **Start services**: `cargo run -- run --env <name>`

See the [user guide](../user-guide/README.md) for complete workflow documentation.

## AI Agent Best Practices

1. **Be conversational** - Ask natural questions, not just read checklist items
2. **Explain tradeoffs** - Help users understand implications of choices
3. **Recommend examples** - Point to specific examples that match requirements
4. **Validate understanding** - Summarize choices before recommending configuration
5. **Offer customization help** - Guide users through modifying example configs
6. **Check prerequisites** - Ensure users have required SSH keys, domain names, API tokens
7. **Suggest validation** - Always recommend validating before deployment

## Troubleshooting

Common issues when helping users create configurations:

### "I don't have SSH keys"

Guide them to generate keys:

```bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```

### "What's my Hetzner API token?"

Guide them to: Hetzner Cloud Console → Security → API Tokens → Generate API Token

### "My domain isn't working with HTTPS"

Check:

- Domain DNS points to server public IP
- Ports 80 and 443 are accessible
- Domain propagation complete (can take hours)

### "Which server size should I use?"

Recommend based on expected load:

- **cx11** (2GB RAM): Testing, low traffic (<100 peers)
- **cx21** (4GB RAM): Light production, medium traffic
- **cx31** (8GB RAM): Production, high traffic
- **cx41+**: Very high traffic or future scaling

## Related Documentation

- [User Guide]../user-guide/README.md - Complete deployment workflow
- [Commands Reference]../user-guide/commands/ - Detailed command documentation
- [Environment Config Schema]../../schemas/environment-config.json - JSON schema for validation
- [Quick Start Guide]../user-guide/quick-start/ - Step-by-step deployment tutorial