Skip to content

Commit 458546a

Browse files
committed
fix: [#14] resolve tracker database driver configuration issue
- Add TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER to compose.yaml - Update docker-compose.env.tpl to include tracker database environment variables - Update tracker.toml.tpl comments to reflect both driver and path env overrides - Update tracker.toml.tpl example to show mysql instead of sqlite3 This fixes the issue where the tracker container was using sqlite3 driver with mysql connection string, causing database connection errors. Changes: - application/compose.yaml: Add mysql driver environment variable - infrastructure/config/templates/docker-compose.env.tpl: Add tracker DB config vars - infrastructure/config/templates/tracker.toml.tpl: Update comments and examples - infrastructure/tests/test-integration.sh: Previous improvements to use local repo
1 parent 0c9d081 commit 458546a

File tree

4 files changed

+69
-20
lines changed

4 files changed

+69
-20
lines changed

application/compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ services:
110110
environment:
111111
- USER_ID=${USER_ID:-1000}
112112
# Database connection for tracker (using Figment override pattern)
113+
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=mysql
113114
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@mysql:3306/${MYSQL_DATABASE}
114115
# Admin API token for tracker (using Figment override pattern)
115116
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TRACKER_ADMIN_TOKEN}

infrastructure/config/templates/docker-compose.env.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ MYSQL_DATABASE=${MYSQL_DATABASE}
1010
MYSQL_USER=${MYSQL_USER}
1111
MYSQL_PASSWORD=${MYSQL_PASSWORD}
1212

13+
# Tracker Database Configuration
14+
TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TRACKER_DATABASE_DRIVER}
15+
TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH=${TRACKER_DATABASE_URL}
16+
1317
# Tracker API Token
1418
TRACKER_ADMIN_TOKEN=${TRACKER_ADMIN_TOKEN}
1519

infrastructure/config/templates/tracker.toml.tpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
# interval_min = 120
4343
#
4444
# [core.database]
45-
# driver = "sqlite3"
46-
# path = "./storage/tracker/lib/database/sqlite3.db"
45+
# driver = "mysql"
46+
# path = "mysql://torrust:password@mysql:3306/torrust_tracker"
4747
#
4848
# [core.net]
4949
# external_ip = "0.0.0.0"
@@ -108,9 +108,10 @@ interval = 120
108108
interval_min = 120
109109

110110
[core.database]
111-
driver = "mysql"
112-
# Path will be overridden via environment variable:
111+
# Driver and path will be overridden via environment variables:
112+
# TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER
113113
# TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH
114+
driver = "mysql"
114115
path = ""
115116

116117
[core.net]

infrastructure/tests/test-integration.sh

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/bin/bash
22
# Integration test script for Torrust Tracker deployment
33
# Tests the complete deployment workflow in the VM
4+
#
5+
# IMPORTANT: This script copies the current local repository to the VM
6+
# to test exactly the changes being developed. This ensures we test our
7+
# modifications rather than the published main branch.
8+
#
9+
# For testing against the published repository (e.g., for E2E tests of
10+
# released versions), consider creating a separate script that clones
11+
# from GitHub instead of copying local files.
412

513
set -euo pipefail
614

@@ -122,25 +130,60 @@ test_docker() {
122130
return 0
123131
}
124132

125-
# Clone and setup Torrust Tracker Demo
133+
# Copy and setup local Torrust Tracker Demo repository
134+
# NOTE: This copies the current local repository to test our exact changes.
135+
# For testing against the published main branch, consider creating a separate
136+
# test script that clones from GitHub instead of copying local files.
126137
setup_torrust_tracker() {
127-
log_info "Setting up Torrust Tracker Demo..."
138+
log_info "Setting up Torrust Tracker Demo (copying local repository)..."
128139

129140
local vm_ip
130141
vm_ip=$(get_vm_ip)
131142

132-
# Check if already cloned
133-
if vm_exec "${vm_ip}" "test -d /home/torrust/github/torrust/torrust-tracker-demo" "Checking if repo exists"; then
134-
log_info "Repository already exists, updating..."
135-
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo && git pull" "Updating repository"
143+
# Create target directory structure
144+
vm_exec "${vm_ip}" "mkdir -p /home/torrust/github/torrust" "Creating directory structure"
145+
146+
# Remove existing directory if it exists
147+
if vm_exec "${vm_ip}" "test -d /home/torrust/github/torrust/torrust-tracker-demo" ""; then
148+
log_info "Removing existing repository directory..."
149+
vm_exec "${vm_ip}" "rm -rf /home/torrust/github/torrust/torrust-tracker-demo" "Removing old directory"
150+
fi
151+
152+
# Copy current local repository to VM (excluding .git and build artifacts)
153+
log_info "Copying local repository to VM..."
154+
rsync -av --progress \
155+
--exclude='.git' \
156+
--exclude='target' \
157+
--exclude='node_modules' \
158+
--exclude='*.log' \
159+
--exclude='infrastructure/terraform/terraform.tfstate*' \
160+
--exclude='infrastructure/terraform/.terraform' \
161+
--exclude='application/storage/*/data' \
162+
-e "ssh -o StrictHostKeyChecking=no" \
163+
"${PROJECT_ROOT}/" \
164+
"torrust@${vm_ip}:/home/torrust/github/torrust/torrust-tracker-demo/"
165+
166+
# Verify copy was successful
167+
if vm_exec "${vm_ip}" "test -f /home/torrust/github/torrust/torrust-tracker-demo/Makefile" "Verifying repository copy"; then
168+
log_success "Local repository copied successfully"
136169
else
137-
log_info "Cloning repository..."
138-
vm_exec "${vm_ip}" "mkdir -p /home/torrust/github/torrust" "Creating directory structure"
139-
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust && git clone https://github.com/torrust/torrust-tracker-demo.git" "Cloning repository"
170+
log_error "Failed to copy local repository"
171+
return 1
140172
fi
141173

142-
# Setup environment file
143-
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo && cp .env.production .env" "Setting up environment file"
174+
# Setup environment file using the new configuration system
175+
# The VM should already have the generated configuration from make configure-local
176+
log_info "Verifying configuration files..."
177+
if vm_exec "${vm_ip}" "test -f /home/torrust/github/torrust/torrust-tracker-demo/application/.env" "Checking .env file"; then
178+
log_success "Environment configuration already available"
179+
else
180+
log_warning ".env file not found, this might indicate configuration generation issues"
181+
# Fallback: copy from .env.production if it exists
182+
if vm_exec "${vm_ip}" "test -f /home/torrust/github/torrust/torrust-tracker-demo/.env.production" ""; then
183+
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo && cp .env.production application/.env" "Creating fallback .env"
184+
log_info "Created fallback .env from .env.production"
185+
fi
186+
fi
144187

145188
log_success "Torrust Tracker Demo setup completed"
146189
return 0
@@ -165,17 +208,17 @@ start_tracker_services() {
165208
log_info "Using Docker Compose command: ${compose_cmd}"
166209

167210
# Pull latest images
168-
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo && ${compose_cmd} pull" "Pulling Docker images"
211+
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && ${compose_cmd} pull" "Pulling Docker images"
169212

170213
# Start services
171-
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo && ${compose_cmd} up -d" "Starting services"
214+
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && ${compose_cmd} up -d" "Starting services"
172215

173216
# Wait for services to be ready
174217
log_info "Waiting for services to be ready..."
175218
sleep 30
176219

177220
# Check service status
178-
if vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo && ${compose_cmd} ps" "Checking service status"; then
221+
if vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && ${compose_cmd} ps" "Checking service status"; then
179222
log_success "Services started successfully"
180223
else
181224
log_error "Services failed to start properly"
@@ -257,7 +300,7 @@ collect_logs() {
257300
vm_ip=$(get_vm_ip)
258301

259302
# Docker logs
260-
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo && docker compose logs --tail=50" "Collecting Docker logs"
303+
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose logs --tail=50" "Collecting Docker logs"
261304

262305
# System logs
263306
vm_exec "${vm_ip}" "sudo journalctl --since='1 hour ago' --no-pager | tail -50" "Collecting system logs"
@@ -277,7 +320,7 @@ stop_services() {
277320
compose_cmd=$(get_docker_compose_cmd "${vm_ip}")
278321

279322
if [ -n "${compose_cmd}" ]; then
280-
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo && ${compose_cmd} down" "Stopping services"
323+
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && ${compose_cmd} down" "Stopping services"
281324
else
282325
log_warning "Docker Compose not available, cannot stop services"
283326
fi

0 commit comments

Comments
 (0)