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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# Torrust Tracker Deployer - User Guide

Welcome to the Torrust Tracker Deployer user guide! This guide will help you get started with deploying and managing Torrust Tracker environments.

## 📋 Table of Contents

- [Overview]#overview
- [Current Status]#current-status
- [Quick Start]#quick-start
- [Available Commands]#available-commands
- [Basic Workflows]#basic-workflows
- [Configuration]#configuration
- [Services]#services
- [Security]#security
- [Troubleshooting]#troubleshooting
- [Additional Resources]#additional-resources

## Overview

The Torrust Tracker Deployer is a command-line tool for managing deployment environments for Torrust Tracker applications. It provides automated infrastructure provisioning, configuration management, and deployment orchestration.

### What Can You Do?

Currently, you can:

- ✅ **Create environments** - Initialize new deployment environments with configuration
- ✅ **Generate templates** - Create configuration templates for new environments
- ✅ **Destroy environments** - Clean up infrastructure and resources

Coming soon:

- 🔄 **Deploy applications** - Full deployment workflow (provision → configure → release)
- 🔄 **Run applications** - Start deployed applications
- 🔄 **Check status** - View environment health and state

## Current Status

**Implementation Status**: MVP Development Phase

The Torrust Tracker Deployer is currently in active development. The following features are implemented:

- ✅ **Environment Creation** - Create and manage environment configurations
- ✅ **Template Generation** - Generate configuration templates
- ✅ **Environment Destruction** - Clean up environments and infrastructure
- ❌ **Provisioning** - Infrastructure creation (in development)
- ❌ **Configuration** - System setup (planned)
- ❌ **Deployment** - Application deployment (planned)
- ❌ **Runtime Management** - Service control (planned)

**Target Platform**: Currently supports local development using LXD virtual machines. Cloud provider support (Hetzner, AWS, GCP, Azure) is planned for future releases.

## Quick Start

> **📖 For complete step-by-step guides**, see the [Quick Start Guides]quick-start/README.md:
>
> - [Docker Deployment]quick-start/docker.md - Fast setup for Hetzner Cloud
> - [Native Installation]quick-start/native.md - Full provider support including LXD

### Prerequisites

Before using the Torrust Tracker Deployer, ensure you have:

- SSH key pair for VM access
- For **Docker** (cloud providers only): Docker installed
- For **native installation**: Rust toolchain, LXD (for local), OpenTofu, Ansible

### Installation Options

#### Option 1: GitHub Codespaces (Easiest - No Installation)

The fastest way to get started **without installing anything** is using GitHub Codespaces:

- ✅ No local installation required
- ✅ All dependencies pre-configured
- ✅ Works from your browser
- ✅ Supports all cloud providers
- ❌ Cannot use local LXD provider (nested virtualization limitation)

**[📖 Full Codespaces guide →](codespaces-deployment.md)**

#### Option 2: Docker (Recommended for Cloud Providers)

The easiest way to get started with **cloud provider deployments** (Hetzner) is using Docker:

```bash
# Pull the image
docker pull torrust/tracker-deployer:latest

# Create working directories
mkdir -p data build envs

# Generate a configuration template
docker run --rm \
  -v $(pwd)/envs:/var/lib/torrust/deployer/envs \
  torrust/tracker-deployer:latest \
  create template --provider hetzner /var/lib/torrust/deployer/envs/my-env.json
```

> ⚠️ **Limitation**: Docker only supports **cloud providers** (Hetzner). For LXD local development, use native installation.

**[📖 Full Docker documentation →](../../docker/deployer/README.md)**

#### Option 3: Native Installation

Build from source for full provider support (including LXD):

```bash
git clone https://github.com/torrust/torrust-tracker-deployer.git
cd torrust-tracker-deployer
cargo build --release
```

The binary will be available at `./target/release/torrust-tracker-deployer`.

### Your First Environment

Here's how to create your first environment:

#### Step 1: Generate Configuration Template

```bash
torrust-tracker-deployer create template my-config.json
```

This creates a template file with placeholder values.

#### Step 2: Edit Configuration

Edit `my-config.json` and replace the placeholder values:

```json
{
  "environment": {
    "name": "dev-local"
  },
  "ssh_credentials": {
    "private_key_path": "~/.ssh/id_rsa",
    "public_key_path": "~/.ssh/id_rsa.pub",
    "username": "torrust",
    "port": 22
  }
}
```

**Required Changes**:

- `name` - Choose a unique environment name (e.g., `dev-local`, `staging`, `prod`)
- `private_key_path` - Path to your SSH private key
- `public_key_path` - Path to your SSH public key

#### Step 3: Create Environment

```bash
torrust-tracker-deployer create environment --env-file my-config.json
```

Success output:

```text
✅ Environment 'dev-local' created successfully
Instance name: torrust-tracker-vm-dev-local
Data directory: data/dev-local
Build directory: build/dev-local
```

#### Step 4: Verify Creation

Check that the environment was created:

```bash
# View environment state file
cat dev-local/environment.json

# Check the data directory structure
ls -la data/
```

#### Step 5: Clean Up (When Finished)

When you're done with the environment:

```bash
torrust-tracker-deployer destroy dev-local
```

## Available Commands

The deployer provides the following commands:

### Environment Management

- **[`create environment`]commands/create-environment.md** - Create a new deployment environment from configuration
- **`create template`** - Generate configuration template file
- **[`destroy`]commands/destroy.md** - Remove environment and clean up resources

### Future Commands

These commands are planned for future releases:

- **`deploy`** - Intelligent deployment orchestration (provision → configure → release)
- **`run`** - Start application services
- **`status`** - Check environment status and health
- **`test`** - Run validation tests

See the [Command Reference](commands.md) for complete documentation.

## Basic Workflows

### Development Workflow

Typical workflow for local development:

```bash
# 1. Generate and configure environment
torrust-tracker-deployer create template dev-config.json
# Edit dev-config.json with your values

# 2. Create the environment
torrust-tracker-deployer create environment --env-file dev-config.json

# 3. (Future) Deploy infrastructure
# torrust-tracker-deployer deploy dev-local

# 4. (Future) Start services
# torrust-tracker-deployer run dev-local

# 5. Clean up when done
torrust-tracker-deployer destroy dev-local
```

### Testing Workflow

Workflow for testing environments:

```bash
# Create test environment
torrust-tracker-deployer create template test-config.json
# Configure for test environment
torrust-tracker-deployer create environment --env-file test-config.json

# Run your tests...

# Clean up
torrust-tracker-deployer destroy test-env
```

### Multiple Environments

Managing multiple environments:

```bash
# Create development environment
torrust-tracker-deployer create environment --env-file dev-config.json

# Create staging environment
torrust-tracker-deployer create environment --env-file staging-config.json

# Work with either environment independently

# Clean up specific environment
torrust-tracker-deployer destroy dev-local
```

## Configuration

### Environment Configuration File

The environment configuration file is in JSON format:

```json
{
  "environment": {
    "name": "environment-name"
  },
  "ssh_credentials": {
    "private_key_path": "/path/to/private/key",
    "public_key_path": "/path/to/public/key",
    "username": "ssh-username",
    "port": 22
  }
}
```

#### Configuration Fields

**environment.name** (required):

- Unique identifier for the environment
- Must be lowercase alphanumeric with hyphens
- Used for directory names and resource identification
- Examples: `dev-local`, `staging`, `production-01`

**ssh_credentials.private_key_path** (required):

- Path to SSH private key file
- Supports `~` for home directory
- File must exist and be readable

**ssh_credentials.public_key_path** (required):

- Path to SSH public key file
- Supports `~` for home directory
- File must exist and be readable

**ssh_credentials.username** (required):

- SSH username for VM access
- Default: `torrust`

**ssh_credentials.port** (optional):

- SSH port number
- Default: `22`

For service-specific configuration (Prometheus, MySQL, etc.), see the [Services](#services) section below.

## Services

The Torrust Tracker Deployer supports optional services that can be enabled in your deployment:

### Available Services

- **[Backup Management]backup.md** - Automatic database and configuration backups with retention policies (enabled by default)
  - Automatic scheduled backups at configurable intervals
  - Retention-based cleanup of old backups
  - Support for both SQLite and MySQL databases
  - Compressed backup files for storage efficiency
  - Manual backup execution anytime on-demand

- **[HTTPS Support]services/https.md** - Automatic TLS/SSL with Let's Encrypt (disabled by default)
  - Automatic certificate management via Caddy reverse proxy
  - Per-service TLS configuration (API, HTTP trackers, Health Check API, Grafana)
  - HTTP/2 and HTTP/3 support
  - Enabled by adding `domain` and `use_tls_proxy: true` to individual services

- **[Prometheus Monitoring]services/prometheus.md** - Metrics collection and monitoring (enabled by default)
  - Automatic metrics scraping from tracker API
  - Web UI on port 9090
  - Configurable scrape intervals
  - Can be disabled by removing from configuration

- **[Grafana Visualization]services/grafana.md** - Metrics visualization and dashboards (enabled by default)
  - Web UI on port 3000 for dashboard access
  - Requires Prometheus to be enabled
  - Configurable admin credentials
  - Pre-built tracker dashboards available for import
  - Can be disabled by removing from configuration

For detailed configuration, setup instructions, and troubleshooting, see the individual service guides linked above.

### Adding or Removing Services

Services are configured in your environment JSON file. To enable a service, include its configuration section. To disable it, remove the section.

**Example with Prometheus**:

```json
{
  "environment": { "name": "my-env" },
  "ssh_credentials": { ... },
  "prometheus": {
    "scrape_interval": 15
  }
}
```

**Example without Prometheus**:

```json
{
  "environment": { "name": "my-env" },
  "ssh_credentials": { ... }
}
```

See individual service guides for detailed configuration options and verification steps.

## Security

**🔒 CRITICAL**: The deployer automatically configures firewall protection during the `configure` command to secure internal services (Prometheus, MySQL) while keeping tracker services publicly accessible.

**For complete security information**, see the **[Security Guide](security.md)** which covers:

- Automatic firewall configuration (UFW)
- Why firewall protection is critical for production
- SSH security best practices
- Docker and network security
- Production security checklist
- Security incident response

### SSH Keys

The deployer uses SSH for all remote operations (`provision`, `configure`, `release`, `run`).
Automated deployments (Docker, CI/CD) require a passphrase-free key or SSH agent forwarding.

**[📖 SSH Keys Guide →](ssh-keys.md)**

### Logging Configuration

Control logging output with command-line options:

```bash
# Development mode - logs to both file and stderr
torrust-tracker-deployer create environment --env-file config.json \
  --log-output file-and-stderr

# Production mode - logs to file only (default)
torrust-tracker-deployer create environment --env-file config.json \
  --log-output file-only

# Change log format
torrust-tracker-deployer create environment --env-file config.json \
  --log-file-format json \
  --log-stderr-format pretty

# Custom log directory
torrust-tracker-deployer create environment --env-file config.json \
  --log-dir ./logs
```

**Logging Options**:

- `--log-output` - Where logs are written (`file-only`, `file-and-stderr`)
- `--log-file-format` - Format for file logs (`pretty`, `json`, `compact`)
- `--log-stderr-format` - Format for stderr logs (`pretty`, `json`, `compact`)
- `--log-dir` - Directory for log files (default: `./data/logs`)

See [Logging Guide](logging.md) for detailed information.

### Working Directory

By default, the deployer uses the current directory for all operations. You can specify a different working directory:

```bash
torrust-tracker-deployer create environment --env-file config.json \
  --working-dir /path/to/workspace
```

This affects:

- Environment state file location
- Data directory location
- Build directory location
- Log directory location (unless overridden with `--log-dir`)

## Troubleshooting

### Common Issues

#### Environment Already Exists

**Error**: `Environment 'name' already exists`

**Solution**: Choose a different name or destroy the existing environment first:

```bash
torrust-tracker-deployer destroy existing-name
torrust-tracker-deployer create environment --env-file config.json
```

#### SSH Key Not Found

**Error**: `SSH key not found at path`

**Solution**: Verify the key paths in your configuration file:

```bash
# Check if keys exist
ls -la ~/.ssh/id_rsa ~/.ssh/id_rsa.pub

# Generate new keys if needed
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
```

#### Invalid Environment Name

**Error**: `Invalid environment name`

**Solution**: Environment names must:

- Be lowercase
- Use alphanumeric characters and hyphens only
- Not start or end with a hyphen

Valid examples: `dev-local`, `staging-01`, `prod`

Invalid examples: `Dev-Local`, `staging_01`, `-dev`

#### Permission Denied

**Error**: `Permission denied when accessing directory`

**Solution**: Ensure you have write permissions for the working directory:

```bash
# Check permissions
ls -la .

# Fix permissions if needed
chmod 755 .
```

### Getting Help

For additional help:

1. **Check Command Documentation**: See the [Command Reference]commands.md
2. **View Logs**: Check logs in `./data/logs/` for detailed error information
3. **Enable Verbose Logging**: Use `--log-output file-and-stderr` to see real-time logs
4. **Report Issues**: [GitHub Issues]https://github.com/torrust/torrust-tracker-deployer/issues

### Verbose Logging

Enable verbose logging for troubleshooting:

```bash
torrust-tracker-deployer create environment --env-file config.json \
  --log-output file-and-stderr \
  --log-stderr-format pretty
```

This shows real-time progress and detailed error information.

## Additional Resources

### Documentation

- **[Quick Start Guides]quick-start/README.md** - Docker and native installation guides
- **[Command Reference]commands/README.md** - Detailed documentation for all commands
- **[Logging Guide]logging.md** - Logging configuration and best practices
- **[Template Customization]template-customization.md** - Advanced configuration options
- **[Advanced: Manual Commands]advanced-manual-commands.md** - Manual OpenTofu and Ansible commands (advanced users)

### Development Documentation

For contributors and developers:

- **[Architecture Overview]../codebase-architecture.md** - System design and architecture
- **[Contributing Guidelines]../contributing/README.md** - How to contribute
- **[Development Principles]../development-principles.md** - Code quality standards

### Project Resources

- **[GitHub Repository]https://github.com/torrust/torrust-tracker-deployer** - Source code and issues
- **[Roadmap]../roadmap.md** - Future plans and features
- **[Changelog]../../CHANGELOG.md** - Version history and changes

## Next Steps

Now that you understand the basics:

1. **Follow the [Quick Start Guides]quick-start/README.md** - Choose Docker or native installation
2. **Explore Commands** - Read the detailed [Command Reference]commands/README.md
3. **Configure Logging** - Set up logging that fits your workflow
4. **Report Feedback** - Share your experience on GitHub

Happy deploying! 🚀