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

Commit f19d2cc

Browse files
committed
refactor: [#28] reorganize application configuration templates
- Create organized directory structure for application templates - Move all templates to infrastructure/config/templates/application/ - Create nginx subdirectory for nginx-specific templates - Create crontab subdirectory for cron job templates - Add .tpl extensions to crontab files for consistency - Update all script references to use new template paths - Update documentation references across all guides - Maintain template processing functionality with new structure Template Structure: ├── application/ │ ├── docker-compose.env.tpl │ ├── tracker.toml.tpl │ ├── prometheus.yml.tpl │ ├── nginx/ │ │ ├── nginx.conf.tpl │ │ ├── nginx-http.conf.tpl │ │ ├── nginx-https-extension.conf.tpl │ │ └── nginx-https-selfsigned.conf.tpl │ └── crontab/ │ ├── mysql-backup.cron.tpl │ └── ssl-renewal.cron.tpl Benefits: - Improved organization and discoverability - Clear separation by service/component type - Consistent .tpl naming conventions - Better maintainability and navigation - Validated with successful E2E test run
1 parent a978621 commit f19d2cc

File tree

17 files changed

+34
-32
lines changed

17 files changed

+34
-32
lines changed

application/docs/backups.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ sudo crontab -e
1414
```
1515

1616
You should see the MySQL backup cron job configured from the template system in
17-
`infrastructure/config/templates/crontab/mysql-backup.cron`.
17+
`infrastructure/config/templates/application/crontab/mysql-backup.cron.tpl`.
1818

1919
## Check Backups
2020

application/share/bin/ssl-configure-nginx.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ fi
4040
NGINX_CONFIG_DIR="/var/lib/torrust/proxy/etc/nginx-conf"
4141
NGINX_CONFIG_FILE="${NGINX_CONFIG_DIR}/default.conf"
4242
TEMPLATES_DIR="${PROJECT_ROOT}/infrastructure/config/templates"
43-
HTTP_TEMPLATE="${TEMPLATES_DIR}/nginx-http.conf.tpl"
44-
HTTPS_EXTENSION_TEMPLATE="${TEMPLATES_DIR}/nginx-https-extension.conf.tpl"
43+
HTTP_TEMPLATE="${TEMPLATES_DIR}/application/nginx/nginx-http.conf.tpl"
44+
HTTPS_EXTENSION_TEMPLATE="${TEMPLATES_DIR}/application/nginx/nginx-https-extension.conf.tpl"
4545

4646
# Check prerequisites
4747
check_prerequisites() {

docs/adr/007-two-level-environment-variable-structure.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ with clear separation of concerns:
5151
### Level 2: Docker Compose Environment Variables
5252

5353
**Purpose**: Container runtime configuration
54-
**Template**: `infrastructure/config/templates/docker-compose.env.tpl`
54+
**Template**: `infrastructure/config/templates/application/docker-compose.env.tpl`
5555
**Generated File**: `.env` (in application directory)
5656
**Scope**: Docker Compose and running containers only
5757

@@ -80,7 +80,7 @@ Level 1: Main Environment Variables
8080
8181
▼ (template processing)
8282
Level 2: Docker Environment Variables
83-
├── infrastructure/config/templates/docker-compose.env.tpl
83+
├── infrastructure/config/templates/application/docker-compose.env.tpl
8484
└── (generated) application/.env
8585
```
8686

@@ -157,7 +157,7 @@ configure_backups "$ENABLE_DB_BACKUPS" "$BACKUP_RETENTION_DAYS"
157157

158158
```bash
159159
# Generate Docker environment file from template
160-
envsubst < "infrastructure/config/templates/docker-compose.env.tpl" > "application/.env"
160+
envsubst < "infrastructure/config/templates/application/docker-compose.env.tpl" > "application/.env"
161161
```
162162

163163
### For Container Configuration

docs/guides/ssl-testing-guide.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ The SSL/HTTPS automation has been **fully implemented** and is working end-to-en
2828

2929
### Architecture Components (All Implemented)
3030

31-
- **HTTP Template**: `infrastructure/config/templates/nginx-http.conf.tpl`
32-
- **HTTPS Template**: `infrastructure/config/templates/nginx-https-selfsigned.conf.tpl`**NEW**
31+
- **HTTP Template**: `infrastructure/config/templates/application/nginx/nginx-http.conf.tpl`
32+
- **HTTPS Template**:
33+
`infrastructure/config/templates/application/nginx/nginx-https-selfsigned.conf.tpl`
3334
- **SSL Scripts**: Located in `application/share/bin/ssl-*.sh`**IMPLEMENTED**
3435
- **Pebble Test Environment**: `application/compose.test.yaml`
3536

@@ -89,7 +90,7 @@ source infrastructure/config/environments/local.env
8990
export DOLLAR='$'
9091

9192
# Test template processing
92-
envsubst < infrastructure/config/templates/nginx-http.conf.tpl > /tmp/test-nginx-http.conf
93+
envsubst < infrastructure/config/templates/application/nginx/nginx-http.conf.tpl > /tmp/test-nginx-http.conf
9394

9495
# Verify output
9596
cat /tmp/test-nginx-http.conf
@@ -219,7 +220,7 @@ ssh torrust@$VM_IP \
219220
source infrastructure/config/environments/local.env
220221
export DOLLAR='$'
221222

222-
envsubst < infrastructure/config/templates/nginx-https-extension.conf.tpl > /tmp/test-nginx-https.conf
223+
envsubst < infrastructure/config/templates/application/nginx/nginx-https-extension.conf.tpl > /tmp/test-nginx-https.conf
223224

224225
# Verify output
225226
cat /tmp/test-nginx-https.conf
@@ -793,7 +794,7 @@ Health Check: ✅ HTTPS working, minor HTTP redirect issue in test script
793794

794795
- **SSL Script**: `application/share/bin/ssl-generate-test-certs.sh` - Complete implementation
795796
- **Shell Utils**: `application/share/bin/shell-utils.sh` - Application-specific utilities
796-
- **Nginx Template**: `infrastructure/config/templates/nginx-https-selfsigned.conf.tpl`
797+
- **Nginx Template**: `infrastructure/config/templates/application/nginx/nginx-https-selfsigned.conf.tpl`
797798
- **Deploy Integration**: `infrastructure/scripts/deploy-app.sh` - SSL generation before services
798799
- **Cloud-init Update**: `infrastructure/cloud-init/user-data.yaml.tpl` - OpenSSL package installation
799800

docs/issues/21-complete-application-installation-automation.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ The recommended workflow follows the [Torrust production deployment guide](https
698698

699699
```bash
700700
# Step 1: Deploy with HTTP-only nginx configuration
701-
cp ../infrastructure/config/templates/nginx-http.conf.tpl /var/lib/torrust/proxy/etc/nginx-conf/default.conf
701+
cp ../infrastructure/config/templates/application/nginx/nginx-http.conf.tpl /var/lib/torrust/proxy/etc/nginx-conf/default.conf
702702
sed -i "s/\${DOMAIN_NAME}/torrust-demo.com/g" /var/lib/torrust/proxy/etc/nginx-conf/default.conf
703703
docker compose up -d
704704
```
@@ -744,7 +744,7 @@ For development and testing, use Pebble to validate the complete SSL workflow lo
744744
docker compose -f compose.test.yaml up -d pebble pebble-challtestsrv
745745

746746
# Step 2: Set up test nginx configuration
747-
cp ../infrastructure/config/templates/nginx-http.conf.tpl /var/lib/torrust/proxy/etc/nginx-conf/default.conf
747+
cp ../infrastructure/config/templates/application/nginx/nginx-http.conf.tpl /var/lib/torrust/proxy/etc/nginx-conf/default.conf
748748
sed -i "s/\${DOMAIN_NAME}/test.local/g" /var/lib/torrust/proxy/etc/nginx-conf/default.conf
749749

750750
# Step 3: Start application services
@@ -884,7 +884,8 @@ implemented and fully tested.
884884

885885
**Status**: ✅ **COMPLETED** - Crontab templates exist and backup automation is fully integrated.
886886

887-
**File**: `infrastructure/config/templates/crontab/mysql-backup.cron`**EXISTS AND FUNCTIONAL**
887+
**File**: `infrastructure/config/templates/application/crontab/mysql-backup.cron.tpl`
888+
**EXISTS AND FUNCTIONAL**
888889

889890
```plaintext
890891
# MySQL Database Backup Crontab Entry
@@ -917,7 +918,7 @@ implemented and fully tested.
917918

918919
**Files Updated**:
919920

920-
- `infrastructure/config/templates/docker-compose.env.tpl` - Added backup variables
921+
- `infrastructure/config/templates/application/docker-compose.env.tpl` - Added backup variables
921922
- `infrastructure/config/environments/local.env` - Local testing configuration
922923
- `infrastructure/config/environments/local.defaults` - Template defaults
923924

@@ -946,7 +947,7 @@ BACKUP_RETENTION_DAYS=7
946947

947948
**Testing Guide Created**: [Database Backup Testing Guide](../guides/database-backup-testing-guide.md)
948949

949-
**File**: `infrastructure/config/templates/crontab/mysql-backup.cron`**EXISTS**
950+
**File**: `infrastructure/config/templates/application/crontab/mysql-backup.cron.tpl`**EXISTS**
950951

951952
```plaintext
952953
# MySQL Database Backup Crontab Entry
@@ -958,7 +959,7 @@ BACKUP_RETENTION_DAYS=7
958959
>> /var/log/mysql-backup.log 2>&1
959960
```
960961

961-
**File**: `infrastructure/config/templates/crontab/ssl-renewal.cron`**EXISTS**
962+
**File**: `infrastructure/config/templates/application/crontab/ssl-renewal.cron.tpl`**EXISTS**
962963

963964
```plaintext
964965
# SSL Certificate Renewal Crontab Entry
@@ -1232,7 +1233,7 @@ setup_ssl_automation() {
12321233
vm_exec "${vm_ip}" "
12331234
cd /home/torrust/github/torrust/torrust-tracker-demo/application
12341235
source ./share/bin/crontab_utils.sh
1235-
add_cronjob 'ssl-renewal.cron' 'torrust'
1236+
add_cronjob 'ssl-renewal.cron.tpl' 'torrust'
12361237
" "SSL renewal crontab setup"
12371238
12381239
log_success "SSL setup completed"
@@ -1254,7 +1255,7 @@ setup_backup_automation() {
12541255
vm_exec "${vm_ip}" "
12551256
cd /home/torrust/github/torrust/torrust-tracker-demo/application
12561257
source ./share/bin/crontab_utils.sh
1257-
add_cronjob 'mysql-backup.cron' 'torrust'
1258+
add_cronjob 'mysql-backup.cron.tpl' 'torrust'
12581259
" "MySQL backup crontab setup"
12591260
12601261
log_success "Database backup automation configured"

0 commit comments

Comments
 (0)