Skip to content

Commit 2d641bf

Browse files
committed
Fix setup.sh to preserve unknown config.json fields (payment, lrmProvider)
Use jq to merge new config with existing, preserving fields that setup.sh doesn't manage. Warns and aborts if jq not installed and config exists.
1 parent 9d1c5fa commit 2d641bf

1 file changed

Lines changed: 37 additions & 12 deletions

File tree

cloud/deploy/setup.sh

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,28 +360,29 @@ else
360360
CORS_CONFIG="null"
361361
fi
362362

363-
# Write merged config.json
363+
# Write/merge config.json
364364
# Note: Inside Docker container, API always listens on 8080 (mapped to API_PORT on host)
365365
print_step "Writing config.json..."
366366

367367
# Build the server section based on CORS config
368368
if [ "$CORS_CONFIG" = "null" ]; then
369-
SERVER_SECTION='"server": {
370-
"urls": "http://0.0.0.0:8080",
371-
"environment": "'"${ENVIRONMENT}"'"
372-
}'
369+
SERVER_JSON='{
370+
"urls": "http://0.0.0.0:8080",
371+
"environment": "'"${ENVIRONMENT}"'"
372+
}'
373373
else
374-
SERVER_SECTION='"server": {
375-
"urls": "http://0.0.0.0:8080",
376-
"environment": "'"${ENVIRONMENT}"'",
377-
"cors": '"${CORS_CONFIG}"'
378-
}'
374+
SERVER_JSON='{
375+
"urls": "http://0.0.0.0:8080",
376+
"environment": "'"${ENVIRONMENT}"'",
377+
"cors": '"${CORS_CONFIG}"'
378+
}'
379379
fi
380380

381-
cat > "$CONFIG_FILE" <<EOF
381+
# Build the new config as JSON
382+
NEW_CONFIG=$(cat <<EOF
382383
{
383384
"\$schema": "./config.schema.json",
384-
${SERVER_SECTION},
385+
"server": ${SERVER_JSON},
385386
"database": {
386387
"connectionString": "Host=lrmcloud-postgres;Port=5432;Database=lrmcloud;Username=lrm;Password=${POSTGRES_PASSWORD}",
387388
"autoMigrate": true
@@ -432,6 +433,30 @@ cat > "$CONFIG_FILE" <<EOF
432433
}
433434
}
434435
EOF
436+
)
437+
438+
# Merge with existing config to preserve unknown fields (payment, lrmProvider, etc.)
439+
if [ -f "$CONFIG_FILE" ] && command -v jq &> /dev/null; then
440+
# Use jq to deep merge: existing config as base, new config overwrites known fields
441+
# This preserves fields like "payment", "lrmProvider" that setup.sh doesn't manage
442+
MERGED_CONFIG=$(jq -s '.[0] * .[1]' "$CONFIG_FILE" <(echo "$NEW_CONFIG"))
443+
echo "$MERGED_CONFIG" | jq '.' > "$CONFIG_FILE"
444+
print_success "Config merged (preserved existing fields like payment, lrmProvider)"
445+
elif [ -f "$CONFIG_FILE" ] && [ "$EXISTING_CONFIG" = true ]; then
446+
# No jq available but config exists - warn user
447+
print_info "Warning: jq not installed. Cannot merge configs."
448+
print_info "Existing fields (payment, lrmProvider, etc.) will be LOST!"
449+
read -p "Continue anyway? [y/N]: " OVERWRITE_RESPONSE
450+
if [ "$OVERWRITE_RESPONSE" != "y" ] && [ "$OVERWRITE_RESPONSE" != "Y" ]; then
451+
print_error "Aborted. Install jq: sudo apt install jq"
452+
exit 1
453+
fi
454+
echo "$NEW_CONFIG" | jq '.' > "$CONFIG_FILE" 2>/dev/null || echo "$NEW_CONFIG" > "$CONFIG_FILE"
455+
else
456+
# New config - just write it
457+
echo "$NEW_CONFIG" | jq '.' > "$CONFIG_FILE" 2>/dev/null || echo "$NEW_CONFIG" > "$CONFIG_FILE"
458+
fi
459+
435460
chmod 644 "$CONFIG_FILE" # 644 allows Docker container to read the file
436461
print_success "Config saved to $CONFIG_FILE"
437462

0 commit comments

Comments
 (0)