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

Commit 2cc9fb8

Browse files
committed
refactor: [#14] standardize environment file path structure
- Use consistent 'application' subdirectory in persistent volume - Change from /var/lib/torrust/compose/.env to /var/lib/torrust/application/.env - Update all deployment script references to use new path structure - Update application tests to reflect new persistent volume architecture - Maintain consistency between local (application/.env) and VM paths Benefits: - Consistent directory structure inside and outside VM - Cleaner path organization aligned with project structure - Better maintainability and understanding for developers All tests pass after refactoring.
1 parent ed2c45a commit 2cc9fb8

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

application/tests/test-unit-application.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ test_application_structure() {
118118
"compose.yaml"
119119
"config"
120120
"share"
121-
"storage"
122121
"docs"
123122
)
124123

infrastructure/scripts/deploy-app.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
1111
TERRAFORM_DIR="${PROJECT_ROOT}/infrastructure/terraform"
1212

1313
# Default values
14-
ENVIRONMENT="${1:-local}"
14+
ENVIRONMENT="${1:-l container_info=$(ssh -n -o StrictHostKeyChecking=no -o ConnectTimeout=10 "torrust@${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/application/.env ps ${service_name} --format '{{.State}}'" 2>/dev/null)cal}"
1515
VM_IP="${2:-}"
1616
SKIP_HEALTH_CHECK="${SKIP_HEALTH_CHECK:-false}"
1717

@@ -353,15 +353,15 @@ release_stage() {
353353
fi
354354
355355
# Ensure persistent storage directories exist
356-
sudo mkdir -p /var/lib/torrust/{tracker/{lib/database,log,etc},prometheus/{data,etc},proxy/{webroot,etc/nginx-conf},certbot/{etc,lib},dhparam,mysql/init,compose}
356+
sudo mkdir -p /var/lib/torrust/{tracker/{lib/database,log,etc},prometheus/{data,etc},proxy/{webroot,etc/nginx-conf},certbot/{etc,lib},dhparam,mysql/init,application}
357357
358358
# Copy .env file to persistent storage if it doesn't exist
359-
if [ -f application/.env ] && [ ! -f /var/lib/torrust/compose/.env ]; then
360-
sudo cp application/.env /var/lib/torrust/compose/.env
361-
elif [ ! -f /var/lib/torrust/compose/.env ]; then
359+
if [ -f application/.env ] && [ ! -f /var/lib/torrust/application/.env ]; then
360+
sudo cp application/.env /var/lib/torrust/application/.env
361+
elif [ ! -f /var/lib/torrust/application/.env ]; then
362362
# Create default .env from template if none exists
363363
if [ -f .env.production ]; then
364-
sudo cp .env.production /var/lib/torrust/compose/.env
364+
sudo cp .env.production /var/lib/torrust/application/.env
365365
fi
366366
fi
367367
@@ -384,7 +384,7 @@ wait_for_services() {
384384
log_info "Checking container status (attempt ${attempt}/${max_attempts})..."
385385

386386
# Get container status with service names only
387-
services=$(ssh -n -o StrictHostKeyChecking=no -o ConnectTimeout=10 "torrust@${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/compose/.env ps --services" 2>/dev/null || echo "SSH_FAILED")
387+
services=$(ssh -n -o StrictHostKeyChecking=no -o ConnectTimeout=10 "torrust@${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/application/.env ps --services" 2>/dev/null || echo "SSH_FAILED")
388388

389389
if [[ "${services}" == "SSH_FAILED" ]]; then
390390
log_warning "SSH connection failed while checking container status. Retrying in 10 seconds..."
@@ -410,7 +410,7 @@ wait_for_services() {
410410
container_count=$((container_count + 1))
411411

412412
# Get the container state and health for this service
413-
container_info=$(ssh -n -o StrictHostKeyChecking=no -o ConnectTimeout=10 "torrust@${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/compose/.env ps ${service_name} --format '{{.State}}'" 2>/dev/null)
413+
container_info=$(ssh -n -o StrictHostKeyChecking=no -o ConnectTimeout=10 "torrust@${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/application/.env ps ${service_name} --format '{{.State}}'" 2>/dev/null)
414414
health_status=$(ssh -n -o StrictHostKeyChecking=no -o ConnectTimeout=10 "torrust@${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker inspect ${service_name} --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}no-healthcheck{{end}}' 2>/dev/null" || echo "no-healthcheck")
415415

416416
# Clean up output
@@ -460,7 +460,7 @@ wait_for_services() {
460460
done
461461

462462
log_error "Timeout waiting for services to become healthy after ${max_attempts} attempts."
463-
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/compose/.env ps && docker compose --env-file /var/lib/torrust/compose/.env logs" "Dumping logs on failure"
463+
vm_exec "${vm_ip}" "cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/application/.env ps && docker compose --env-file /var/lib/torrust/application/.env logs" "Dumping logs on failure"
464464
exit 1
465465
}
466466

@@ -476,7 +476,7 @@ run_stage() {
476476
cd /home/torrust/github/torrust/torrust-tracker-demo/application
477477
478478
if [ -f compose.yaml ]; then
479-
docker compose --env-file /var/lib/torrust/compose/.env down --remove-orphans || true
479+
docker compose --env-file /var/lib/torrust/application/.env down --remove-orphans || true
480480
fi
481481
" "Stopping existing services"
482482

@@ -487,7 +487,7 @@ run_stage() {
487487
488488
# Pull images with progress output
489489
echo 'Starting Docker image pull...'
490-
docker compose --env-file /var/lib/torrust/compose/.env pull
490+
docker compose --env-file /var/lib/torrust/application/.env pull
491491
echo 'Docker image pull completed'
492492
" 600 "Pulling Docker images with 10-minute timeout"
493493

@@ -496,7 +496,7 @@ run_stage() {
496496
cd /home/torrust/github/torrust/torrust-tracker-demo/application
497497
498498
# Start services
499-
docker compose --env-file /var/lib/torrust/compose/.env up -d
499+
docker compose --env-file /var/lib/torrust/application/.env up -d
500500
" "Starting application services"
501501

502502
# Wait for services to initialize
@@ -515,16 +515,16 @@ validate_deployment() {
515515
vm_exec "${vm_ip}" "
516516
cd /home/torrust/github/torrust/torrust-tracker-demo/application
517517
echo '=== Docker Compose Services (Detailed Status) ==='
518-
docker compose --env-file storage/compose/.env ps --format 'table {{.Service}}\t{{.State}}\t{{.Status}}\t{{.Ports}}'
518+
docker compose --env-file /var/lib/torrust/application/.env ps --format 'table {{.Service}}\t{{.State}}\t{{.Status}}\t{{.Ports}}'
519519
520520
echo ''
521521
echo '=== Docker Compose Services (Default Format) ==='
522-
docker compose --env-file storage/compose/.env ps
522+
docker compose --env-file /var/lib/torrust/application/.env ps
523523
524524
echo ''
525525
echo '=== Container Health Check Details ==='
526526
# Show health status for each container
527-
for container in \$(docker compose --env-file storage/compose/.env ps --format '{{.Name}}'); do
527+
for container in \$(docker compose --env-file /var/lib/torrust/application/.env ps --format '{{.Name}}'); do
528528
echo \"Container: \$container\"
529529
state=\$(docker inspect \$container --format '{{.State.Status}}')
530530
health=\$(docker inspect \$container --format '{{.State.Health.Status}}' 2>/dev/null || echo 'no-healthcheck')
@@ -540,7 +540,7 @@ validate_deployment() {
540540
done
541541
542542
echo '=== Service Logs (last 10 lines each) ==='
543-
docker compose --env-file /var/lib/torrust/compose/.env logs --tail=10
543+
docker compose --env-file /var/lib/torrust/application/.env logs --tail=10
544544
" "Checking detailed service status"
545545

546546
# Test application endpoints
@@ -605,8 +605,8 @@ show_connection_info() {
605605
echo
606606
echo "=== NEXT STEPS ==="
607607
echo "Health Check: make app-health-check ENVIRONMENT=${ENVIRONMENT}"
608-
echo "View Logs: ssh torrust@${vm_ip} 'cd torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/compose/.env logs'"
609-
echo "Stop Services: ssh torrust@${vm_ip} 'cd torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/compose/.env down'"
608+
echo "View Logs: ssh torrust@${vm_ip} 'cd torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/application/.env logs'"
609+
echo "Stop Services: ssh torrust@${vm_ip} 'cd torrust-tracker-demo/application && docker compose --env-file /var/lib/torrust/application/.env down'"
610610
echo
611611
}
612612

0 commit comments

Comments
 (0)