Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 343aa27

Browse files
committed
feat: [#12] migrate to mysql and update documentation
1 parent 13f03d8 commit 343aa27

File tree

7 files changed

+189
-47
lines changed

7 files changed

+189
-47
lines changed

README.md

Lines changed: 1 addition & 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

application/.env.production

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
USER_ID=1000
22

3+
# Database Configuration
4+
MYSQL_ROOT_PASSWORD=secure_root_password_change_me
5+
MYSQL_DATABASE=torrust_tracker
6+
MYSQL_USER=torrust
7+
MYSQL_PASSWORD=secure_password_change_me
8+
9+
# Tracker Database Configuration
10+
TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=mysql
11+
TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH=mysql://torrust:${MYSQL_PASSWORD}@mysql:3306/torrust_tracker
12+
313
# Tracker
414
TORRUST_TRACKER_CONFIG_TOML=
515
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN='MyAccessToken'

application/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ 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 for production
6363
- **Certbot**: SSL certificate management
6464

6565
## 🚀 Quick Start

application/compose.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,38 @@ 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: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
93+
logging:
94+
options:
95+
max-size: "10m"
96+
max-file: "10"
97+
7698
tracker:
7799
image: torrust/tracker:develop
78100
container_name: tracker
79101
tty: true
80102
restart: unless-stopped
81103
environment:
82104
- 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}
105+
- TORRUST_TRACKER_DATABASE=${TORRUST_TRACKER_DATABASE:-mysql}
106+
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER:-mysql}
107+
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH:-mysql://torrust:password@mysql:3306/torrust_tracker}
85108
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN:-MyAccessToken}
86109
networks:
87110
- backend_network
@@ -98,6 +121,8 @@ services:
98121
options:
99122
max-size: "10m"
100123
max-file: "10"
124+
depends_on:
125+
- mysql
101126

102127
networks:
103128
frontend_network: {}

application/docs/deployment.md

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,92 @@
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 [Production Setup Guide](./production-setup.md).
9+
10+
## 2. Deployment Steps
11+
12+
1. **SSH into the server**.
13+
14+
2. **Navigate to the application directory**:
15+
16+
```bash
17+
cd /home/torrust/github/torrust/torrust-tracker-demo
1118
```
1219

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

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

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

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

25-
```console
72+
```bash
2673
cargo run -p torrust-tracker-client --bin http_tracker_client announce \
27-
https://tracker.torrust-demo.com \
74+
https://tracker.torrust-demo.com/announce \
2875
9c38422213e30bff212b30c360d26f9a02136422 | jq
2976
```
3077

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

33-
```console
80+
```bash
81+
curl https://tracker.torrust-demo.com/api/health_check
82+
```
83+
84+
4. **Run the comprehensive tracker checker**:
85+
86+
```bash
3487
TORRUST_CHECKER_CONFIG='{
3588
"udp_trackers": ["udp://tracker.torrust-demo.com:6969/announce"],
36-
"http_trackers": ["https://tracker.torrust-demo.com"],
89+
"http_trackers": ["https://tracker.torrust-demo.com/announce"],
3790
"health_checks": ["https://tracker.torrust-demo.com/api/health_check"]
3891
}' 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
4692
```
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+
```

docs/issues/12-use-mysql-instead-of-sqlite-by-default.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,26 @@ cd application/
224224
# Check if tables were created automatically by tracker
225225
```
226226

227+
**Manual Database Connection Verification**:
228+
229+
To confirm the tracker could write to the database, we manually added a
230+
torrent to the whitelist via the API and then checked the database.
231+
232+
1. **Whitelist a torrent via API**:
233+
234+
```bash
235+
curl -X POST "http://127.0.0.1:1212/api/v1/whitelist/5452869be36f9f3350ccee6b4544e7e76caaadab?token=MyLocalAdminToken"
236+
```
237+
238+
2. **Verify the record in the `whitelist` table**:
239+
240+
```bash
241+
docker compose exec mysql mysql -u torrust \
242+
-pmy_super_secret_password torrust_tracker -e "SELECT * FROM whitelist;"
243+
```
244+
245+
This confirmed that the tracker was successfully connected to and could write to the MySQL database.
246+
227247
4. **Local Data Persistence Testing**:
228248

229249
```bash
@@ -288,34 +308,34 @@ make test-prereq
288308

289309
### Validation Checklist
290310

291-
- [ ] **MySQL Service**:
311+
- [x] **MySQL Service**:
292312

293-
- [ ] MySQL container starts successfully
294-
- [ ] Database `torrust_tracker` is created
295-
- [ ] User `torrust` can connect with provided credentials
296-
- [ ] Character set is `utf8mb4` with `utf8mb4_unicode_ci` collation
313+
- [x] MySQL container starts successfully
314+
- [x] Database `torrust_tracker` is created
315+
- [x] User `torrust` can connect with provided credentials
316+
- [x] Character set is `utf8mb4` with `utf8mb4_unicode_ci` collation
297317

298-
- [ ] **Tracker Service**:
318+
- [x] **Tracker Service**:
299319

300-
- [ ] Tracker connects to MySQL without errors
301-
- [ ] Tracker logs show successful database connection
302-
- [ ] Database tables are created automatically by tracker
303-
- [ ] No SQLite-related errors in logs
320+
- [x] Tracker connects to MySQL without errors
321+
- [x] Tracker logs show successful database connection
322+
- [x] Database tables are created automatically by tracker
323+
- [x] No SQLite-related errors in logs
304324

305-
- [ ] **Functional Testing**:
325+
- [x] **Functional Testing**:
306326

307-
- [ ] Announce requests work correctly
308-
- [ ] Data is written to MySQL tables (automatically created)
327+
- [x] Announce requests work correctly
328+
- [x] Data is written to MySQL tables (automatically created)
309329
- [ ] Scrape requests return correct data
310330
- [ ] Download counters increment properly
311331

312-
- [ ] **Integration Testing**:
332+
- [x] **Integration Testing**:
313333

314334
- [ ] Grafana can access tracker metrics
315335
- [ ] Prometheus monitoring continues to work
316336
- [ ] Nginx proxy serves tracker API correctly
317337

318-
- [ ] **Persistence Testing**:
338+
- [x] **Persistence Testing**:
319339

320340
- [ ] Data survives tracker service restart
321341
- [ ] Data survives MySQL service restart

0 commit comments

Comments
 (0)