balena-io-experimental / browser

A drop-in web browser block
96 stars 70 forks source link

Other container web service auto detection not working #159

Open bbugh opened 9 months ago

bbugh commented 9 months ago

The auto detection of another container's web ports does not seem to be working, at least as described in the README. Here is a minimal reproduction:

version: '2'

volumes:
  settings:

services:
  browser:
    restart: always
    image: bh.cr/balenalabs/browser-aarch64
    privileged: true
    volumes:
      - 'settings:/data'
    ports:
      - '5011' # management API (optional)
  web:
    restart: always
    image: nginx:1.25.2
    ports:
      - '80'
  1. When starting, it will output:

    [Logs]    [2023-10-03T00:26:12.869Z] [browser] LAUNCH_URL environment variable not set.
    [Logs]    [2023-10-03T00:26:12.871Z] [browser] Looking for local HTTP/S services.
    [Logs]    [2023-10-03T00:26:12.876Z] [browser] No service found on port 80
    [Logs]    [2023-10-03T00:26:12.881Z] [browser] No service found on port 443
    [Logs]    [2023-10-03T00:26:12.886Z] [browser] No service found on port 8080
    [Logs]    [2023-10-03T00:26:12.887Z] [browser] Displaying default HTML page
  2. If you force it to load web via the API, it will work fine:

    ADDRESS=`sudo balena scan --json | jq -r '.[0].address'`
    curl --data "url=web" http://$ADDRESS:5011/url

    This will show the "welcome to nginx" page on the device

  3. If you tell it to re-scan via the API, it still won't find the local container.

    curl -X POST http://$ADDRESS:5011/scan

    💩

    [Logs]    [2023-10-03T00:34:14.361Z] [browser] LAUNCH_URL environment variable not set.
    [Logs]    [2023-10-03T00:34:14.363Z] [browser] Looking for local HTTP/S services.
    [Logs]    [2023-10-03T00:34:14.369Z] [browser] No service found on port 80
    [Logs]    [2023-10-03T00:34:14.374Z] [browser] No service found on port 443
    [Logs]    [2023-10-03T00:34:14.378Z] [browser] No service found on port 8080
    [Logs]    [2023-10-03T00:34:14.383Z] [browser] Displaying default HTML page
  4. but if you manually specify LAUNCH_URL to the other container...

    services:
      browser:
        environment:
          LAUNCH_URL: http://web

    ... it works:

    image
phil-d-wilson commented 9 months ago

Hey Brian,I think the block container will need to be in host networking mode since it scans ports on the localhost:https://github.com/balena-labs-projects/browser/blob/master/src/server.js#L65The readme was recently updated to remove host networking to fix a problem with pulseaudio, but it seems more nuanced. Phil -------- Original message --------From: Brian Bugh @.> Date: 03/10/2023 01:43 (GMT+00:00) To: balena-labs-projects/browser @.> Cc: Subscribed @.***> Subject: [balena-labs-projects/browser] Other container web service auto detection not working (Issue #159) The auto detection of another container's web ports does not seem to be working, at least as described in the README. Here is a minimal reproduction: version: '2'

volumes: settings:

services: browser: restart: always image: bh.cr/balenalabs/browser-aarch64 privileged: true volumes:

When starting, it will output: [Logs] [2023-10-03T00:26:12.869Z] [browser] LAUNCH_URL environment variable not set. [Logs] [2023-10-03T00:26:12.871Z] [browser] Looking for local HTTP/S services. [Logs] [2023-10-03T00:26:12.876Z] [browser] No service found on port 80 [Logs] [2023-10-03T00:26:12.881Z] [browser] No service found on port 443 [Logs] [2023-10-03T00:26:12.886Z] [browser] No service found on port 8080 [Logs] [2023-10-03T00:26:12.887Z] [browser] Displaying default HTML page

If you force it to load web via the API, it will work fine: ADDRESS=sudo balena scan --json | jq -r '.[0].address' curl --data "url=web" http://$ADDRESS:5011/url This will show the "welcome to nginx" page on the device

If you tell it to re-scan via the API, it still won't find the local container. curl -X POST http://$ADDRESS:5011/scan 💩 [Logs] [2023-10-03T00:34:14.361Z] [browser] LAUNCH_URL environment variable not set. [Logs] [2023-10-03T00:34:14.363Z] [browser] Looking for local HTTP/S services. [Logs] [2023-10-03T00:34:14.369Z] [browser] No service found on port 80 [Logs] [2023-10-03T00:34:14.374Z] [browser] No service found on port 443 [Logs] [2023-10-03T00:34:14.378Z] [browser] No service found on port 8080 [Logs] [2023-10-03T00:34:14.383Z] [browser] Displaying default HTML page

but if you manually specify LAUNCH_URL to the other container... services: browser: environment: LAUNCH_URL: http://web ... it works:

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>