Fix variable replacement logic for nested variables and remove repo file modification
- Remove localize_deployment call from main flow to avoid modifying repo files - Enhance localize_yml_file to recursively expand nested variables using envsubst - Ensure config files contain actual values, not variable names
This commit is contained in:
@@ -129,13 +129,24 @@ localize_yml_file() {
|
|||||||
debug_log "Backed up $file_path"
|
debug_log "Backed up $file_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use envsubst to replace all ${VAR} with environment values
|
# Use envsubst to replace all ${VAR} with environment values, handling nested variables
|
||||||
if command -v envsubst >/dev/null 2>&1; then
|
if command -v envsubst >/dev/null 2>&1; then
|
||||||
log_info "DEBUG: DEFAULT_EMAIL=$DEFAULT_EMAIL"
|
log_info "DEBUG: DEFAULT_EMAIL=$DEFAULT_EMAIL"
|
||||||
envsubst < "$file_path" > "$file_path.tmp" && mv "$file_path.tmp" "$file_path"
|
temp_file="$file_path.tmp"
|
||||||
debug_log "Replaced variables in $file_path using envsubst"
|
cp "$file_path" "$temp_file"
|
||||||
|
changed=true
|
||||||
|
while [ "$changed" = true ]; do
|
||||||
|
changed=false
|
||||||
|
new_content=$(envsubst < "$temp_file")
|
||||||
|
if [ "$new_content" != "$(cat "$temp_file")" ]; then
|
||||||
|
changed=true
|
||||||
|
echo "$new_content" > "$temp_file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
mv "$temp_file" "$file_path"
|
||||||
|
debug_log "Replaced variables in $file_path using envsubst with nested expansion"
|
||||||
replaced_count=$(grep -o '\${[^}]*}' "$file_path" | wc -l)
|
replaced_count=$(grep -o '\${[^}]*}' "$file_path" | wc -l)
|
||||||
replaced_count=$((replaced_count / 2)) # Approximate, since envsubst replaces all
|
replaced_count=$((replaced_count / 2)) # Approximate
|
||||||
else
|
else
|
||||||
log_warning "envsubst not available, cannot localize $file_path"
|
log_warning "envsubst not available, cannot localize $file_path"
|
||||||
if [ "$fail_on_missing" = true ]; then
|
if [ "$fail_on_missing" = true ]; then
|
||||||
@@ -1649,9 +1660,6 @@ main() {
|
|||||||
# Save configuration
|
# Save configuration
|
||||||
save_env_file
|
save_env_file
|
||||||
|
|
||||||
# Perform enhanced placeholder replacement across all config files
|
|
||||||
localize_deployment
|
|
||||||
|
|
||||||
# Validate secrets for core deployment
|
# Validate secrets for core deployment
|
||||||
validate_secrets
|
validate_secrets
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user