1
1
#! /bin/bash
2
2
# Integration test script for Torrust Tracker deployment
3
3
# 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.
4
12
5
13
set -euo pipefail
6
14
@@ -122,25 +130,60 @@ test_docker() {
122
130
return 0
123
131
}
124
132
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.
126
137
setup_torrust_tracker () {
127
- log_info " Setting up Torrust Tracker Demo..."
138
+ log_info " Setting up Torrust Tracker Demo (copying local repository) ..."
128
139
129
140
local vm_ip
130
141
vm_ip=$( get_vm_ip)
131
142
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"
136
169
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
140
172
fi
141
173
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
144
187
145
188
log_success " Torrust Tracker Demo setup completed"
146
189
return 0
@@ -165,17 +208,17 @@ start_tracker_services() {
165
208
log_info " Using Docker Compose command: ${compose_cmd} "
166
209
167
210
# 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"
169
212
170
213
# 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"
172
215
173
216
# Wait for services to be ready
174
217
log_info " Waiting for services to be ready..."
175
218
sleep 30
176
219
177
220
# 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
179
222
log_success " Services started successfully"
180
223
else
181
224
log_error " Services failed to start properly"
@@ -257,7 +300,7 @@ collect_logs() {
257
300
vm_ip=$( get_vm_ip)
258
301
259
302
# 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"
261
304
262
305
# System logs
263
306
vm_exec " ${vm_ip} " " sudo journalctl --since='1 hour ago' --no-pager | tail -50" " Collecting system logs"
@@ -277,7 +320,7 @@ stop_services() {
277
320
compose_cmd=$( get_docker_compose_cmd " ${vm_ip} " )
278
321
279
322
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"
281
324
else
282
325
log_warning " Docker Compose not available, cannot stop services"
283
326
fi
0 commit comments