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

Commit a8b11c5

Browse files
committed
refactor: move nginx.conf to infrastructure templates and improve configuration management
- Move nginx.conf template from application/share/container/default/config/ to infrastructure/config/templates/nginx.conf.tpl - Update install.sh to only verify nginx.conf exists (not create it) - Update infrastructure/scripts/configure-env.sh to generate nginx.conf from template - Add application/storage cleanup to clean-and-fix target with user confirmation - Improve separation of concerns: infrastructure manages templates, application verifies files exist - Follow 12-factor principles: configuration is generated by infrastructure, not application This ensures the nginx.conf file is always generated with the latest configuration and integration tests work properly with clean application/storage directories.
1 parent 10592d0 commit a8b11c5

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,23 @@ clean-and-fix: ## Clean up all VMs and fix libvirt permissions
189189
@cd $(TERRAFORM_DIR) && rm -f terraform.tfstate terraform.tfstate.backup .terraform.lock.hcl 2>/dev/null || true
190190
@echo "3. Cleaning libvirt images:"
191191
@sudo rm -f /var/lib/libvirt/images/torrust-tracker-demo* /var/lib/libvirt/images/ubuntu-24.04-base.qcow2 2>/dev/null || true
192-
@echo "4. Fixing libvirt setup:"
192+
@echo "4. Cleaning application storage (generated configuration files):"
193+
@if [ -d "application/storage" ]; then \
194+
echo " WARNING: This will delete all generated configuration files in application/storage/"; \
195+
echo " This includes nginx configs, tracker configs, and any cached data."; \
196+
echo " These files will be regenerated when you run 'make configure-local'."; \
197+
read -p " Do you want to delete application/storage? (y/N): " confirm; \
198+
if [ "$$confirm" = "y" ] || [ "$$confirm" = "Y" ]; then \
199+
echo " Removing application/storage..."; \
200+
rm -rf application/storage; \
201+
echo " ✓ Application storage cleaned"; \
202+
else \
203+
echo " Skipping application/storage cleanup"; \
204+
fi; \
205+
else \
206+
echo " No application/storage directory found"; \
207+
fi
208+
@echo "5. Fixing libvirt setup:"
193209
@$(MAKE) fix-libvirt
194210
@echo "✓ Clean up complete. You can now run 'make apply' safely."
195211

application/share/bin/install.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ mkdir -p ./storage/proxy/etc/nginx-conf
2323
mkdir -p ./storage/proxy/webroot
2424
mkdir -p ./storage/dhparam
2525

26+
# Verify nginx configuration exists (should be provided by infrastructure)
2627
if ! [ -f "./storage/proxy/etc/nginx-conf/nginx.conf" ]; then
27-
echo "Creating proxy config file: './storage/proxy/etc/nginx-conf/nginx.conf'"
28-
cp ./share/container/default/config/nginx.conf ./storage/proxy/etc/nginx-conf/nginx.conf
28+
echo "ERROR: Nginx configuration file './storage/proxy/etc/nginx-conf/nginx.conf' not found!"
29+
echo "This file should be generated by the infrastructure configuration system."
30+
echo "Expected location: $(pwd)/storage/proxy/etc/nginx-conf/nginx.conf"
31+
echo ""
32+
echo "To generate the configuration file, run:"
33+
echo " make configure-local # For local development"
34+
echo " make configure-production # For production deployment"
35+
exit 1
2936
fi
3037

38+
echo "Found nginx configuration: ./storage/proxy/etc/nginx-conf/nginx.conf"
39+
3140
## Certbot
3241

3342
mkdir -p ./storage/certbot/etc

docs/guides/integration-testing-guide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ This guide provides a complete integration testing workflow that:
15481548
This guide provides a complete integration testing workflow that:
15491549

15501550
1. **Creates fresh infrastructure** in ~3-5 minutes
1551-
2. **Generates configuration files** from templates (~2 seconds)
1551+
2. **Generates configuration files** from templates (~2 seconds)
15521552
3. **Refreshes OpenTofu state** to detect VM IP (~3 seconds)
15531553
4. **Waits for cloud-init** to complete (~2-3 minutes)
15541554
5. **Runs comprehensive tests** covering all services (~3-5 minutes)
@@ -1565,10 +1565,10 @@ During the most recent testing cycle, the following components were validated su
15651565
#### Infrastructure Tests
15661566

15671567
-**VM Access**: SSH connectivity working at `192.168.122.54`
1568-
-**Docker Installation**: Docker 28.3.1 and Docker Compose V2.38.1 working
1568+
-**Docker Installation**: Docker 28.3.1 and Docker Compose V2.38.1 working
15691569
-**Service Health**: All containers running with healthy status
15701570

1571-
#### Service Deployment
1571+
#### Service Deployment
15721572

15731573
-**MySQL**: Database running healthy with proper credentials
15741574
-**Tracker**: Torrust Tracker running with all endpoints active
@@ -1603,7 +1603,7 @@ During the most recent testing cycle, the following components were validated su
16031603
# Health check (no auth needed)
16041604
curl -s http://$VM_IP/api/health_check | jq .
16051605

1606-
# Stats API (auth required)
1606+
# Stats API (auth required)
16071607
curl -s "http://$VM_IP/api/v1/stats?token=local-dev-admin-token-12345" | jq .
16081608
```
16091609

infrastructure/scripts/configure-env.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ process_templates() {
141141
log_info "Generated: ${prometheus_output_dir}/prometheus.yml"
142142
fi
143143

144+
# Process nginx configuration template
145+
if [[ -f "${templates_dir}/nginx.conf.tpl" ]]; then
146+
log_info "Processing nginx configuration template"
147+
local nginx_output_dir="${PROJECT_ROOT}/application/storage/proxy/etc/nginx-conf"
148+
mkdir -p "${nginx_output_dir}"
149+
envsubst <"${templates_dir}/nginx.conf.tpl" >"${nginx_output_dir}/nginx.conf"
150+
log_info "Generated: ${nginx_output_dir}/nginx.conf"
151+
fi
152+
144153
log_success "Configuration templates processed"
145154
}
146155

0 commit comments

Comments
 (0)