Skip to content

Commit 5b91b30

Browse files
committed
Merge #13: Use MYSQL instead of SQLite by default
fa296f1 docs: [#12] complete Phase 2 documentation updates for MySQL migration (Jose Celano) 46ac92a feat: [#12] complete VM integration testing with MySQL x86-64-v2 CPU fix (Jose Celano) 69090dc feat: [#12] complete local functionality and persistence tests for mysql (Jose Celano) 4b5dc4e feat: [#12] add healthcheck to mysql service (Jose Celano) 343aa27 feat: [#12] migrate to mysql and update documentation (Jose Celano) 13f03d8 docs: [#12] add ADR-003 for MySQL vs MariaDB decision (Jose Celano) b0b779b docs: [#12] add MySQL migration implementation plan (Jose Celano) Pull request description: Relates to: torrust#66 Use MYSQL instead of SQLite by default. ### Subtasks - [x] Create a plan to implement the issue - [x] Add MYSQL service to Docker Compose config, and make necessary changes to tracker config or env variables to make MySQL the default DB driver. ACKs for top commit: josecelano: ACK fa296f1 Tree-SHA512: c4181d589e0ca83d8e8208bc866f3a2a752600582f73d17125e66062d2d7445a32b1c5920febc18280af9fd11c664fd6a33c5fbdd8c443ac2d11f471694237c7
2 parents 621382c + fa296f1 commit 5b91b30

File tree

16 files changed

+747
-42
lines changed

16 files changed

+747
-42
lines changed

.github/copilot-instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ The project includes a comprehensive linting script that validates all file type
232232
- **No secrets**: Never commit SSH keys, passwords, or tokens
233233
- **Documentation**: Update docs for any infrastructure changes
234234

235+
#### End-to-End Smoke Testing
236+
237+
For verifying the functionality of the tracker from an end-user's perspective (e.g., simulating announce/scrape requests), refer to the **Smoke Testing Guide**. This guide explains how to use the official `torrust-tracker-client` tools to perform black-box testing against a running tracker instance without needing a full BitTorrent client.
238+
239+
- **Guide**: [Smoke Testing Guide](../docs/guides/smoke-testing-guide.md)
240+
- **When to use**: After a deployment (`make apply`) or to validate that all services are working together correctly.
241+
235242
### Security Guidelines
236243

237244
#### Secrets Management

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ make destroy # Clean up
9696
- [Application Overview](application/README.md) - Application components and
9797
deployment
9898
- [Production Setup](application/docs/production-setup.md) - Production
99-
deployment
99+
deployment with MySQL
100100
- [Deployment Guide](application/docs/deployment.md) - Deployment procedures
101101
- [Backup Procedures](application/docs/backups.md) - Data backup and recovery
102102
- [Rollback Guide](application/docs/rollbacks.md) - Application rollbacks
@@ -112,6 +112,8 @@ make destroy # Clean up
112112
main Makefile is at repository root
113113
- [ADR-002: Docker for All Services](docs/adr/002-docker-for-all-services.md) -
114114
Why we use Docker for all services including UDP tracker
115+
- [ADR-003: Use MySQL Over MariaDB](docs/adr/003-use-mysql-over-mariadb.md) -
116+
Why we chose MySQL instead of MariaDB for the database backend
115117

116118
## 🛠️ Development
117119

application/.env.production

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
# Torrust Tracker Demo - Production Environment Configuration
2+
#
3+
# This configuration uses MySQL as the default database backend.
4+
# Make sure to change the default passwords before deployment!
5+
16
USER_ID=1000
27

8+
# Database Configuration (MySQL)
9+
MYSQL_ROOT_PASSWORD=secure_root_password_change_me
10+
MYSQL_DATABASE=torrust_tracker
11+
MYSQL_USER=torrust
12+
MYSQL_PASSWORD=secure_password_change_me
13+
14+
# Tracker Database Configuration
15+
TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=mysql
16+
TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH=mysql://torrust:${MYSQL_PASSWORD}@mysql:3306/torrust_tracker
17+
318
# Tracker
419
TORRUST_TRACKER_CONFIG_TOML=
520
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN='MyAccessToken'

application/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,30 @@ application/
5959
- **Nginx**: Reverse proxy and SSL termination
6060
- **Prometheus**: Metrics collection and storage
6161
- **Grafana**: Metrics visualization and dashboards
62-
- **MySQL**: Database (migrating from SQLite)
62+
- **MySQL**: Default database backend for production
6363
- **Certbot**: SSL certificate management
6464

65+
### Database Configuration
66+
67+
The Torrust Tracker Demo uses **MySQL as the default database backend** for
68+
production deployments. This provides:
69+
70+
- **Reliability**: Production-grade database with ACID compliance
71+
- **Scalability**: Support for high-throughput tracking operations
72+
- **Data Integrity**: Consistent data storage and retrieval
73+
- **Performance**: Optimized for concurrent tracker operations
74+
75+
**Database Service**: The MySQL service is automatically configured with:
76+
77+
- Database initialization scripts
78+
- Proper networking and security
79+
- Data persistence across container restarts
80+
- Health checks and monitoring
81+
82+
For development and testing environments, you can optionally configure SQLite
83+
by modifying the tracker configuration, though MySQL is recommended for all
84+
production use cases.
85+
6586
## 🚀 Quick Start
6687

6788
### Application Deployment

application/compose.yaml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ services:
6363
networks:
6464
- backend_network
6565
ports:
66-
- "9090:9090" # This port should not be exposed to the internet
66+
- "9090:9090" # This port should not be exposed to the internet
6767
volumes:
6868
- ./storage/prometheus/etc:/etc/prometheus:Z
6969
logging:
@@ -73,15 +73,45 @@ services:
7373
depends_on:
7474
- tracker
7575

76+
mysql:
77+
image: mysql:8.0
78+
container_name: mysql
79+
restart: unless-stopped
80+
environment:
81+
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
82+
- MYSQL_DATABASE=${MYSQL_DATABASE}
83+
- MYSQL_USER=${MYSQL_USER}
84+
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
85+
networks:
86+
- backend_network
87+
ports:
88+
- "3306:3306" # Only for debugging, remove in production
89+
volumes:
90+
- mysql_data:/var/lib/mysql
91+
- ./storage/mysql/init:/docker-entrypoint-initdb.d:ro
92+
command: >
93+
--character-set-server=utf8mb4
94+
--collation-server=utf8mb4_unicode_ci
95+
healthcheck:
96+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-p${MYSQL_PASSWORD}"]
97+
interval: 10s
98+
timeout: 5s
99+
retries: 5
100+
logging:
101+
options:
102+
max-size: "10m"
103+
max-file: "10"
104+
76105
tracker:
77106
image: torrust/tracker:develop
78107
container_name: tracker
79108
tty: true
80109
restart: unless-stopped
81110
environment:
82111
- USER_ID=${USER_ID}
83-
- TORRUST_TRACKER_DATABASE=${TORRUST_TRACKER_DATABASE:-sqlite3}
84-
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER:-sqlite3}
112+
- TORRUST_TRACKER_DATABASE=${TORRUST_TRACKER_DATABASE:-mysql}
113+
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER:-mysql}
114+
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH:-mysql://torrust:password@mysql:3306/torrust_tracker}
85115
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN:-MyAccessToken}
86116
networks:
87117
- backend_network
@@ -98,6 +128,8 @@ services:
98128
options:
99129
max-size: "10m"
100130
max-file: "10"
131+
depends_on:
132+
- mysql
101133

102134
networks:
103135
frontend_network: {}

application/docs/deployment.md

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,93 @@
11
# Deployment
22

3-
1. SSH into the server.
4-
2. Execute the deployment script: `./bin/deploy-torrust-tracker-demo.com.sh`.
5-
3. Execute the smoke tests:
6-
7-
```console
8-
# Clone Torrust Tracker
9-
[email protected]:torrust/torrust-tracker.git
10-
cd torrust-tracker
3+
This document outlines the deployment process for the Torrust Tracker demo application.
4+
5+
## 1. Prerequisites
6+
7+
- Ensure you have SSH access to the production server.
8+
- The server should be provisioned and configured according to the
9+
[Production Setup Guide](./production-setup.md).
10+
11+
## 2. Deployment Steps
12+
13+
1. **SSH into the server**.
14+
15+
2. **Navigate to the application directory**:
16+
17+
```bash
18+
cd /home/torrust/github/torrust/torrust-tracker-demo
1119
```
1220

13-
Execute the following commands to run the tracker client and checker.
21+
3. **Pull the latest changes** from the repository:
22+
23+
```bash
24+
git pull
25+
```
26+
27+
4. **Run the deployment script**:
28+
29+
```bash
30+
./share/bin/deploy-torrust-tracker-demo.com.sh
31+
```
32+
33+
This script handles:
34+
35+
- Stopping services
36+
- Rebuilding containers
37+
- Starting services
38+
39+
## 3. Verification and Smoke Testing
40+
41+
After deployment, verify that all services are running correctly.
1442

15-
Simulate a torrent announce to the tracker using UDP:
43+
### Service Status
1644

17-
```console
45+
Check the status of all Docker containers:
46+
47+
```bash
48+
docker compose ps
49+
```
50+
51+
### Application Logs
52+
53+
Check the logs for the tracker container to ensure it started without errors:
54+
55+
```bash
56+
./share/bin/tracker-filtered-logs.sh
57+
```
58+
59+
### Smoke Tests
60+
61+
Execute the following smoke tests from a machine with the `torrust-tracker` repository cloned.
62+
63+
1. **UDP Announce**:
64+
65+
```bash
1866
cargo run -p torrust-tracker-client --bin udp_tracker_client announce \
1967
udp://tracker.torrust-demo.com:6969/announce \
2068
9c38422213e30bff212b30c360d26f9a02136422 | jq
2169
```
2270

23-
Simulate a torrent scrape to the tracker using HTTP:
71+
2. **HTTP Announce**:
2472

25-
```console
73+
```bash
2674
cargo run -p torrust-tracker-client --bin http_tracker_client announce \
27-
https://tracker.torrust-demo.com \
75+
https://tracker.torrust-demo.com/announce \
2876
9c38422213e30bff212b30c360d26f9a02136422 | jq
2977
```
3078

31-
Make a request to the health check endpoint:
79+
3. **Health Check Endpoint**:
3280

33-
```console
81+
```bash
82+
curl https://tracker.torrust-demo.com/api/health_check
83+
```
84+
85+
4. **Run the comprehensive tracker checker**:
86+
87+
```bash
3488
TORRUST_CHECKER_CONFIG='{
3589
"udp_trackers": ["udp://tracker.torrust-demo.com:6969/announce"],
36-
"http_trackers": ["https://tracker.torrust-demo.com"],
90+
"http_trackers": ["https://tracker.torrust-demo.com/announce"],
3791
"health_checks": ["https://tracker.torrust-demo.com/api/health_check"]
3892
}' cargo run -p torrust-tracker-client --bin tracker_checker
39-
40-
```
41-
42-
4. Check the logs of the tracker container to see if everything is working:
43-
44-
```console
45-
./share/bin/tracker-filtered-logs.sh
4693
```

application/docs/firewall-requirements.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ The tracker uses four main ports, each serving a specific purpose:
109109
- `/api/v1/metrics` - Prometheus metrics
110110
- Used by Prometheus for monitoring and Grafana dashboards
111111

112-
### Application Service Mapping
113-
114112
### Torrust Tracker
115113

116114
- **UDP ports 6868, 6969**: BitTorrent announce endpoints

application/docs/production-setup.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,54 @@
1-
# Setup
1+
# Production Environment Setup
22

3-
Follow instructions on [Deploying Torrust To Production](https://torrust.com/blog/deploying-torrust-to-production).
3+
This guide details the steps required to configure the production environment
4+
for the Torrust Tracker demo.
45

5-
You need to also enable a [firewall](./firewall-requirements.md).
6+
## 1. Initial Setup
7+
8+
For the initial server setup, follow the instructions on [Deploying Torrust To Production](https://torrust.com/blog/deploying-torrust-to-production).
9+
10+
You also need to enable a [firewall](./firewall-requirements.md).
611

712
The application is located in the directory: `/home/torrust/github/torrust/torrust-tracker-demo`.
813

9-
To run docker compose commands you need to cd to the app dir:
14+
To run Docker Compose commands, you need to be in the application directory:
1015

1116
```console
1217
cd /home/torrust/github/torrust/torrust-tracker-demo
1318
```
19+
20+
## 2. Database Configuration
21+
22+
The production environment uses MySQL as the database backend.
23+
24+
### Environment Variables
25+
26+
Create a `.env` file by copying the production template:
27+
28+
```bash
29+
cp .env.production .env
30+
```
31+
32+
**Crucially, you must edit the `.env` file and set secure passwords** for the following variables:
33+
34+
- `MYSQL_ROOT_PASSWORD`: The root password for the MySQL server.
35+
- `MYSQL_PASSWORD`: The password for the `torrust` user.
36+
- `TRACKER_ADMIN_TOKEN`: The admin token for the tracker API.
37+
38+
### Database Initialization
39+
40+
The MySQL service automatically initializes the database and creates the necessary tables on first startup.
41+
42+
## 3. Running the Application
43+
44+
Once the `.env` file is configured, you can start all services:
45+
46+
```bash
47+
docker compose up -d
48+
```
49+
50+
You can check the status of the services with:
51+
52+
```bash
53+
docker compose ps
54+
```

application/share/container/default/config/prometheus.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
global:
23
scrape_interval: 15s # How often to scrape metrics
34

docs/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ This directory currently contains cross-cutting documentation:
1818

1919
- [ADR-001: Makefile Location](adr/001-makefile-location.md) - Decision to keep
2020
Makefile at repository root level
21+
- [ADR-002: Docker for All Services](adr/002-docker-for-all-services.md) - Decision
22+
to use Docker for all services including UDP tracker
23+
- [ADR-003: Use MySQL Over MariaDB](adr/003-use-mysql-over-mariadb.md) - Decision
24+
to use MySQL instead of MariaDB for database backend
2125

2226
### 📅 [`plans/`](plans/) (Ongoing Plans and Roadmaps)
2327

@@ -26,6 +30,13 @@ This directory currently contains cross-cutting documentation:
2630
- [Hetzner Migration Plan](plans/hetzner-migration-plan.md) - Comprehensive plan
2731
for migrating from Digital Ocean to Hetzner infrastructure
2832

33+
### 🎯 [`issues/`](issues/) (Implementation Plans)
34+
35+
**Issue Implementation Plans:**
36+
37+
- [Phase 1: MySQL Migration](issues/12-use-mysql-instead-of-sqlite-by-default.md) -
38+
Detailed implementation plan for database migration from SQLite to MySQL
39+
2940
### Future Categories
3041

3142
The following directories can be created as needed:

0 commit comments

Comments
 (0)