Open p-i- opened 1 month ago
Ok, so here's what I've done.
pi@πlocal ~/demeisen_gen2/computer-use-demo main
> cat .ports
# INTERNAL ports end in 1 (think 1 ~ I for Internal), EXTERNAL ports end in 0
PORT_VNC_INTERNAL=5901
PORT_VNC_EXTERNAL=5900
PORT_NOVNC_INTERNAL=6081
PORT_NOVNC_EXTERNAL=6080
PORT_HTTP_INTERNAL=8081
PORT_HTTP_EXTERNAL=8080
PORT_STREAMLIT_INTERNAL=8501
PORT_STREAMLIT_EXTERNAL=8500
And I've tweaked entrypoint.sh
:
pi@πlocal ~/demeisen_gen2/computer-use-demo main
> cat image/entrypoint.sh
#!/bin/bash
set -e
# Source and export all variables from .ports
set -a
source /host/computer-use-demo/.ports || exit 1
set +a
./start_all.sh
./novnc_startup.sh
# Generate index.html from template
envsubst < static_content/index.html.template > static_content/index.html
:
Now, as all these port variables are now in the shell environment, the subservient ?_startup.sh scripts can all use them, as can any Python script.
The only gotcha is that static_content/index.html uses a port, so I've moved that to a .template file, which entrypoint.sh renders (as you can see above).
Another benefit of what I've done is to separate EXTERNAL from INTERNAL ports. That's important for code-clarity, otherwise you have two separate objects that happen to have the same value only being referenced by that value. Confusing.
Finally grep for all the 4 hardcoded initial ports to make sure you've replaced EVERY SINGLE HARDCODED reference, and you should be good to go.
There's one gotcha though. Does this .ports go INTO the docker image via COPY in the Dockerfile? For me no, as I'm mounting the containing host-folder, so that the container can see its self.
Hmm, I have screen sharing off on my Mac, and still get this error.
ok fixed it by:
localhost:8080
full cmd:
docker run \
-p 5900:5900 \
-p 6080:6080 \
-p 8080:8080 \
-p 8501:8501 \
-e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
-it ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest
cc @IgorGanapolsky
Running this command stopped the Mac service that uses the port for me.
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -stop
Executing the (minimally tweaked)
docker run
command from the README.md:Inspecting, ...
It turns out that I have to disable screen-sharing on macOS to free this port:
I think it's a mistake to re-use a port that macOS has, by default, reserved, given that you are free to use ANY port you wish.
It does seem odd to me that in 2024 the best solution still seems to be "Pick a random 16-bit integer and hope nobody else on your OS picked the same one". Very retro. hey ho...
I think it would make much more sense to have a .ports file and make the ports dynamic. And to use different numbers for external and internal. That would make the code easier to work with.