diff --git a/backend/services/deploy-mining.sh b/backend/services/deploy-mining.sh index b341781d..a562d35b 100755 --- a/backend/services/deploy-mining.sh +++ b/backend/services/deploy-mining.sh @@ -254,7 +254,6 @@ load_env() { fi # Set defaults (match docker-compose.yml settings) - # export is required so envsubst can access these when processing connector JSON templates export POSTGRES_HOST="${POSTGRES_HOST:-localhost}" export POSTGRES_PORT="${POSTGRES_PORT:-5432}" export POSTGRES_USER="${POSTGRES_USER:-rwa_user}" @@ -268,6 +267,14 @@ load_env() { KAFKA_CONTAINER="${KAFKA_CONTAINER:-rwa-kafka}" } +# Substitute environment variables in a file, supporting ${VAR:-default} syntax. +# GNU envsubst does NOT handle ${VAR:-default}, so we use eval with heredoc instead. +substitute_env_vars() { + eval "cat <<__ENVSUBST_EOF__ +$(cat "$1") +__ENVSUBST_EOF__" +} + # =========================================================================== # Helper: Execute psql command (auto-detect Docker or local) # =========================================================================== @@ -843,7 +850,7 @@ cdc_resnapshot() { if [ "$use_file_config" = true ]; then # Use config file, replace snapshot.mode with always local json_config - json_config=$(cat "$config_file" | envsubst | sed 's/"snapshot.mode": "initial"/"snapshot.mode": "always"/') + json_config=$(substitute_env_vars "$config_file" | sed 's/"snapshot.mode": "initial"/"snapshot.mode": "always"/') result=$(echo "$json_config" | curl -s -X POST "$connect_url/connectors" \ -H "Content-Type: application/json" \ -d @- 2>/dev/null) @@ -944,9 +951,8 @@ register_outbox_connectors() { local config_only config_only=$(cat "$config_file" | sed 's/.*"config"://' | sed 's/}$//') - # Use envsubst to replace environment variables, then update local result - result=$(cat "$config_file" | envsubst | curl -s -X PUT \ + result=$(substitute_env_vars "$config_file" | curl -s -X PUT \ -H "Content-Type: application/json" \ -d @- \ "$connect_url/connectors/$connector/config" 2>/dev/null) @@ -960,7 +966,7 @@ register_outbox_connectors() { # Connector doesn't exist, create it # Replace environment variables in the config file local result - result=$(cat "$config_file" | envsubst | curl -s -X POST \ + result=$(substitute_env_vars "$config_file" | curl -s -X POST \ -H "Content-Type: application/json" \ -d @- \ "$connect_url/connectors" 2>/dev/null) @@ -1394,7 +1400,7 @@ full_reset() { if [ -n "$config_file" ] && [ -f "$config_file" ]; then log_info "Registering source connector: $connector" local result - result=$(cat "$config_file" | envsubst | curl -s -X POST "$DEBEZIUM_CONNECT_URL/connectors" \ + result=$(substitute_env_vars "$config_file" | curl -s -X POST "$DEBEZIUM_CONNECT_URL/connectors" \ -H "Content-Type: application/json" \ -d @- 2>/dev/null)