@@ -351,174 +351,12 @@ validate_environment() {
351351 fi
352352 done
353353
354- # Validate SSL configuration variables
355- validate_ssl_configuration
356-
357- # Validate backup configuration variables
358- validate_backup_configuration
359-
360354 log_success " Environment validation passed"
361355}
362356
363- # Validate SSL certificate configuration
364- validate_ssl_configuration () {
365- # Check if TRACKER_DOMAIN is set and not a placeholder
366- if [[ -z " ${TRACKER_DOMAIN:- } " ]]; then
367- log_error " SSL configuration: TRACKER_DOMAIN is not set"
368- exit 1
369- fi
370-
371- if [[ " ${TRACKER_DOMAIN} " == " REPLACE_WITH_YOUR_DOMAIN" ]]; then
372- log_error " SSL configuration: TRACKER_DOMAIN contains placeholder value 'REPLACE_WITH_YOUR_DOMAIN'"
373- log_error " Please edit your environment file and set a real domain name"
374- exit 1
375- fi
376-
377- # Check if CERTBOT_EMAIL is set and not a placeholder
378- if [[ -z " ${CERTBOT_EMAIL:- } " ]]; then
379- log_error " SSL configuration: CERTBOT_EMAIL is not set"
380- exit 1
381- fi
382-
383- if [[ " ${CERTBOT_EMAIL} " == " REPLACE_WITH_YOUR_EMAIL" ]]; then
384- log_error " SSL configuration: CERTBOT_EMAIL contains placeholder value 'REPLACE_WITH_YOUR_EMAIL'"
385- log_error " Please edit your environment file and set a real email address"
386- exit 1
387- fi
388-
389- # Validate email format (basic validation)
390- if [[ ! " ${CERTBOT_EMAIL} " =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\. [a-zA-Z]{2,}$ ]]; then
391- log_error " SSL configuration: CERTBOT_EMAIL '${CERTBOT_EMAIL} ' is not a valid email format"
392- exit 1
393- fi
394-
395- # Check if ENABLE_SSL is a valid boolean
396- if [[ -z " ${ENABLE_SSL:- } " ]]; then
397- log_error " SSL configuration: ENABLE_SSL is not set"
398- exit 1
399- fi
400-
401- if [[ " ${ENABLE_SSL} " != " true" && " ${ENABLE_SSL} " != " false" ]]; then
402- log_error " SSL configuration: ENABLE_SSL must be 'true' or 'false', got '${ENABLE_SSL} '"
403- exit 1
404- fi
405-
406- # Log SSL configuration validation result
407- if [[ " ${ENABLE_SSL} " == " true" ]]; then
408- log_info " SSL configuration: Enabled for domain '${TRACKER_DOMAIN} ' with email '${CERTBOT_EMAIL} '"
409- else
410- log_info " SSL configuration: Disabled (ENABLE_SSL=false)"
411- fi
412- }
413-
414- # Validate backup configuration
415- validate_backup_configuration () {
416- # Check if ENABLE_DB_BACKUPS is a valid boolean
417- if [[ -z " ${ENABLE_DB_BACKUPS:- } " ]]; then
418- log_error " Backup configuration: ENABLE_DB_BACKUPS is not set"
419- exit 1
420- fi
421-
422- if [[ " ${ENABLE_DB_BACKUPS} " != " true" && " ${ENABLE_DB_BACKUPS} " != " false" ]]; then
423- log_error " Backup configuration: ENABLE_DB_BACKUPS must be 'true' or 'false', got '${ENABLE_DB_BACKUPS} '"
424- exit 1
425- fi
426-
427- # Validate BACKUP_RETENTION_DAYS is numeric and reasonable
428- if [[ -z " ${BACKUP_RETENTION_DAYS:- } " ]]; then
429- log_error " Backup configuration: BACKUP_RETENTION_DAYS is not set"
430- exit 1
431- fi
432-
433- if ! [[ " ${BACKUP_RETENTION_DAYS} " =~ ^[0-9]+$ ]]; then
434- log_error " Backup configuration: BACKUP_RETENTION_DAYS must be a positive integer, got '${BACKUP_RETENTION_DAYS} '"
435- exit 1
436- fi
437-
438- if [[ " ${BACKUP_RETENTION_DAYS} " -lt 1 ]]; then
439- log_error " Backup configuration: BACKUP_RETENTION_DAYS must be at least 1 day, got '${BACKUP_RETENTION_DAYS} '"
440- exit 1
441- fi
442-
443- if [[ " ${BACKUP_RETENTION_DAYS} " -gt 365 ]]; then
444- log_warning " Backup configuration: BACKUP_RETENTION_DAYS is very high (${BACKUP_RETENTION_DAYS} days)"
445- log_warning " This may consume significant disk space"
446- fi
447-
448- # Log backup configuration validation result
449- if [[ " ${ENABLE_DB_BACKUPS} " == " true" ]]; then
450- log_info " Backup configuration: Enabled with ${BACKUP_RETENTION_DAYS} days retention"
451- else
452- log_info " Backup configuration: Disabled (ENABLE_DB_BACKUPS=false)"
453- fi
454- }
455-
456- # Process configuration templates
457- process_templates () {
458- local templates_dir=" ${CONFIG_DIR} /templates"
459- local output_dir=" ${PROJECT_ROOT} /application/storage/tracker/etc"
460-
461- # Ensure output directory exists
462- mkdir -p " ${output_dir} "
463-
464- # Process tracker configuration template
465- if [[ -f " ${templates_dir} /application/tracker.toml.tpl" ]]; then
466- log_info " Processing tracker configuration template"
467- envsubst < " ${templates_dir} /application/tracker.toml.tpl" > " ${output_dir} /tracker.toml"
468- log_info " Generated: ${output_dir} /tracker.toml"
469- fi
470-
471- # Process prometheus configuration template
472- if [[ -f " ${templates_dir} /application/prometheus.yml.tpl" ]]; then
473- log_info " Processing prometheus configuration template"
474- local prometheus_output_dir=" ${PROJECT_ROOT} /application/storage/prometheus/etc"
475- mkdir -p " ${prometheus_output_dir} "
476- envsubst < " ${templates_dir} /application/prometheus.yml.tpl" > " ${prometheus_output_dir} /prometheus.yml"
477- log_info " Generated: ${prometheus_output_dir} /prometheus.yml"
478- fi
479-
480- # Process nginx configuration template
481- if [[ -f " ${templates_dir} /application/nginx/nginx.conf.tpl" ]]; then
482- log_info " Processing nginx configuration template"
483- local nginx_output_dir=" ${PROJECT_ROOT} /application/storage/proxy/etc/nginx-conf"
484- mkdir -p " ${nginx_output_dir} "
485- envsubst < " ${templates_dir} /application/nginx/nginx.conf.tpl" > " ${nginx_output_dir} /nginx.conf"
486- log_info " Generated: ${nginx_output_dir} /nginx.conf"
487- fi
488-
489- log_success " Configuration templates processed"
490- }
491-
492- # Generate .env file for Docker Compose
493- generate_docker_env () {
494- local templates_dir=" ${CONFIG_DIR} /templates"
495- local env_output=" ${PROJECT_ROOT} /application/storage/compose/.env"
496-
497- log_info " Generating Docker Compose environment file"
498-
499- # Ensure the storage/compose directory exists
500- mkdir -p " $( dirname " ${env_output} " ) "
501-
502- # Set generation date for template
503- GENERATION_DATE=" $( TZ=UTC date) "
504- export GENERATION_DATE
505-
506- # Ensure ENVIRONMENT is exported for template substitution
507- export ENVIRONMENT
508-
509- # Process Docker Compose environment template
510- if [[ -f " ${templates_dir} /application/docker-compose.env.tpl" ]]; then
511- envsubst < " ${templates_dir} /application/docker-compose.env.tpl" > " ${env_output} "
512- log_info " Generated: ${env_output} "
513- else
514- log_error " Docker Compose environment template not found: ${templates_dir} /application/docker-compose.env.tpl"
515- exit 1
516- fi
517- }
518-
519357# Main execution
520358main () {
521- log_info " Starting configuration generation for environment type: ${ENVIRONMENT} with provider: ${PROVIDER} "
359+ log_info " Starting infrastructure configuration generation for environment type: ${ENVIRONMENT} with provider: ${PROVIDER} "
522360
523361 # Validate inputs
524362 validate_environment_type " ${ENVIRONMENT} "
@@ -527,24 +365,34 @@ main() {
527365 # Generate environment configuration
528366 generate_environment_config " ${ENVIRONMENT} " " ${PROVIDER} " " ${OUTPUT_NAME} "
529367
530- log_success " Configuration generation completed successfully"
368+ log_success " Infrastructure configuration generation completed successfully"
531369 log_info " Generated file: infrastructure/config/environments/${OUTPUT_NAME} .env"
370+ log_info " "
371+ log_info " Next steps:"
372+ log_info " 1. Review and customize the generated environment file"
373+ log_info " 2. Run infrastructure deployment: make infra-apply ENVIRONMENT=${ENVIRONMENT} ENVIRONMENT_FILE=${OUTPUT_NAME} "
374+ log_info " 3. Generate application configuration: make app-config ENVIRONMENT=${ENVIRONMENT} ENVIRONMENT_FILE=${OUTPUT_NAME} "
532375}
533376
534377# Show help
535378show_help () {
536379 cat << EOF
537- Environment Configuration Generator
380+ Infrastructure Environment Configuration Generator
538381
539382Usage: $0 <ENVIRONMENT> <PROVIDER> [OUTPUT_NAME]
540383
384+ Description:
385+ Generates infrastructure environment configuration files (*.env) for deploying
386+ the Torrust Tracker Demo infrastructure. This script handles only infrastructure
387+ configuration - application configuration is handled separately.
388+
541389Arguments:
542390 ENVIRONMENT Environment type: development, testing, e2e, staging, production
543391 PROVIDER Provider name (from infrastructure/config/providers/*.env)
544392 OUTPUT_NAME Optional custom output filename (default: {environment}-{provider})
545393
546394Environment Types:
547- development Local development environment
395+ development Local development environment (libvirt/KVM)
548396 testing General testing environment (reserved for future use)
549397 e2e End-to-end testing environment
550398 staging Pre-production staging environment
@@ -575,9 +423,17 @@ Generated Files:
575423 - All files include ENVIRONMENT and PROVIDER variables for identification
576424
577425Note:
426+ This script only generates infrastructure environment configuration files.
427+ For application configuration, use the application configuration scripts.
578428 Users can create any number of environment files with custom names.
579429 The application identifies environment type and provider from variables inside the file,
580430 not from the filename.
431+
432+ Workflow:
433+ 1. Generate infrastructure config: ./infrastructure/scripts/configure-env.sh <ENV> <PROVIDER>
434+ 2. Deploy infrastructure: make infra-apply ENVIRONMENT=<ENV> ENVIRONMENT_FILE=<FILE>
435+ 3. Generate application config: make app-config ENVIRONMENT=<ENV> ENVIRONMENT_FILE=<FILE>
436+ 4. Deploy application: make app-deploy ENVIRONMENT=<ENV> ENVIRONMENT_FILE=<FILE>
581437EOF
582438}
583439
0 commit comments