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
513set -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.
126137setup_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