Skip to content

Commit 74e4c7e

Browse files
committed
fix: [#28] SSL certificate domain mismatch in deploy-app.sh
- Fixed generate_selfsigned_certificates() function to use correct staging domains - Removed hardcoded fallback to 'tracker.test.local' - Added proper environment loading from staging-hetzner-staging.env - Implemented base domain extraction logic for certificate generation - SSL certificates now correctly generated for tracker.torrust-demo.dev and grafana.torrust-demo.dev - Resolves nginx startup issues with SSL certificate domain mismatches Validation: - Successfully redeployed staging environment with correct certificates - All services healthy and HTTPS endpoints working - nginx running correctly with proper staging domain certificates
1 parent 2b2c3db commit 74e4c7e

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

infrastructure/scripts/deploy-app.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,38 @@ generate_configuration_locally() {
396396
# this approach ensures consistency with production deployment workflows.
397397
generate_selfsigned_certificates() {
398398
local vm_ip="$1"
399-
local tracker_domain="${TRACKER_DOMAIN:-tracker.test.local}"
400399

401-
log_info "Generating self-signed SSL certificates on VM for tracker domain: ${tracker_domain}..."
400+
# Load environment variables from the deployment environment file to access domain configuration
401+
local env_file="${PROJECT_ROOT}/infrastructure/config/environments/${ENVIRONMENT_FILE}.env"
402+
if [[ -f "${env_file}" ]]; then
403+
# shellcheck source=/dev/null
404+
source "${env_file}"
405+
log_info "Loaded deployment environment configuration for SSL certificate generation"
406+
else
407+
log_error "Environment file not found: ${env_file}"
408+
log_error "Cannot generate certificates without environment configuration"
409+
exit 1
410+
fi
411+
412+
# Validate that TRACKER_DOMAIN is set
413+
if [[ -z "${TRACKER_DOMAIN:-}" ]]; then
414+
log_error "TRACKER_DOMAIN is not set in environment configuration"
415+
log_error "Expected format: tracker.yourdomain.com"
416+
log_error "Please verify the environment file: ${env_file}"
417+
exit 1
418+
fi
419+
420+
# Extract base domain from TRACKER_DOMAIN (e.g., "torrust-demo.dev" from "tracker.torrust-demo.dev")
421+
local base_domain="${TRACKER_DOMAIN#tracker.}"
422+
if [[ "${base_domain}" == "${TRACKER_DOMAIN}" ]]; then
423+
log_error "TRACKER_DOMAIN does not start with 'tracker.': ${TRACKER_DOMAIN}"
424+
log_error "Expected format: tracker.yourdomain.com"
425+
exit 1
426+
fi
427+
428+
log_info "Generating self-signed SSL certificates on VM..."
429+
log_info " Base domain: ${base_domain}"
430+
log_info " Will generate certificates for: tracker.${base_domain} and grafana.${base_domain}"
402431

403432
# Copy the certificate generation script and its shell utilities to VM
404433
local cert_script="${PROJECT_ROOT}/application/share/bin/ssl-generate-test-certs.sh"
@@ -427,8 +456,8 @@ generate_selfsigned_certificates() {
427456
vm_exec "${vm_ip}" "chmod +x ${vm_app_dir}/share/bin/shell-utils.sh"
428457

429458
# Run certificate generation from the application directory where compose.yaml is located
430-
log_info "Running certificate generation for tracker domain: ${tracker_domain}"
431-
vm_exec "${vm_ip}" "cd ${vm_app_dir} && ./share/bin/ssl-generate-test-certs.sh '${tracker_domain}'"
459+
log_info "Running certificate generation for base domain: ${base_domain}"
460+
vm_exec "${vm_ip}" "cd ${vm_app_dir} && ./share/bin/ssl-generate-test-certs.sh '${base_domain}'"
432461

433462
log_success "Self-signed SSL certificates generated successfully"
434463
}

0 commit comments

Comments
 (0)