Skip to content

fix: guard docker-entrypoint sed against empty env vars#45

Merged
homeles merged 1 commit intomainfrom
fix/docker-entrypoint-env-vars
Mar 30, 2026
Merged

fix: guard docker-entrypoint sed against empty env vars#45
homeles merged 1 commit intomainfrom
fix/docker-entrypoint-env-vars

Conversation

@lupita-hom
Copy link
Copy Markdown
Collaborator

Problem

Commit f899d10 added docker-entrypoint.sh as the container ENTRYPOINT to support runtime API URL replacement. However, the script unconditionally runs sed to replace the build-time URL defaults (http://localhost/api, ws://localhost) with the values of REACT_APP_API_URL and REACT_APP_WEBSOCKET_URL.

When running via docker-compose, the client service does not pass these as runtime env vars (they are only build ARGs). So at container startup:

  • REACT_APP_API_URLempty string
  • REACT_APP_WEBSOCKET_URLempty string

The sed replaces all API URLs in the JS bundle with empty strings. Every fetch() call then hits "" → resolves to the nginx root → returns index.html (HTML) instead of JSON → the app crashes with TypeError: undefined is not an object (evaluating 'd.map') on every page that makes API calls (Settings, Dashboard, etc.).

Root Cause

# OLD (always runs, even when vars are empty):
sed -i -e "s|http://localhost/api|${REACT_APP_API_URL}|g" "$file"
#                                  ^^^^^^^^^^^^^^^^^^^^^^^^
#                                  Empty → replaces URLs with nothing

Fix

Only run the sed replacement when the env vars are actually set (non-empty). When not set, the build-time defaults remain intact and work correctly with the existing nginx.conf proxy_pass to server:5001.

# NEW (guarded):
if [ -n "${REACT_APP_API_URL}" ]; then
  sed -i "s|http://localhost/api|${REACT_APP_API_URL}|g" "$file"
fi

Also added:

  • set -e for fail-fast behavior
  • File existence check ([ -f "$file" ]) to avoid errors on empty glob
  • Clear startup logging for debugging
  • Proper newline at end of file

Testing

Docker Compose (default — no runtime env vars):

docker compose up --build -d
# Settings page loads ✅
# API calls return JSON ✅
# No sed replacement runs (build defaults preserved)

Kubernetes / custom deployment (with runtime env vars):

docker run -e REACT_APP_API_URL=https://myhost.com/api \
           -e REACT_APP_WEBSOCKET_URL=wss://myhost.com \
           -p 8080:80 runwatch-client:fix
# URLs replaced at startup ✅
# API calls route to custom host ✅

Fixes regression from f899d10.

The docker-entrypoint.sh unconditionally ran sed to replace API URLs
in the JS bundle, even when REACT_APP_API_URL and REACT_APP_WEBSOCKET_URL
were not set as runtime env vars. This replaced the build-time defaults
(http://localhost/api, ws://localhost) with empty strings, breaking all
API calls — fetch('') hits nginx root and returns index.html instead of
JSON, causing 'undefined is not an object' crashes throughout the app.

Fix: only run sed replacement when the env vars are actually set (non-empty).
When not set, the build-time defaults remain intact and work correctly
with the existing nginx proxy_pass configuration.

Fixes the regression introduced in f899d10.
@github-actions
Copy link
Copy Markdown

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA d9d2980.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@homeles homeles merged commit 84cf0bb into main Mar 30, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants