-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pygbag within dockerized Python env #57
Comments
pygbag needs "localhost" address literally in the url bar to work correctly, a lot of conditionnal blocks depend on that. even 127.0.0.1 would not work correctly for getting .js / camera or ssl downgrades and with CORS restrictions that browser applies. Maybe try pygame-embed as host-less alternative, see example here https://pygame-web.github.io/showroom/test_embed.html it can access files on-the-fly without need for packing i don't use docker but it seems to me you need to redirect the port 8000 from the guest to 127.0.0.1:8000 on the host. ssh client can usually help doing that it has great tunnel creation abilities |
Actually what I am doing is (from a Windows host):
Then, from within the dockerized (ubuntu) python env:
Where
and these errors are shown within the console Moreover, accessing the same resource from the browser, using Contrary, running the above commands from a Linux host, the behaviour is completely different and everything (surprinsingly) works! Both the NB redirecting to port |
@pmp-p I suppose I should focus on the
|
if you bind the server to a special ip then it won't be bound to localhost anymore I don't think you should set it all all ( or try 0.0.0.0 instead) . This is not a really a pygbag parameter it's inherited from the python http test server. The "bind" pygbag uses is actually the Regarding what address is sent to the browser, there's no parameter at all it (should) reuse the base url asked by browser and found in the headers => that's why in the screenshot the browser ask for files directly on 172.17.0.3 bypassing pygbag proxy. http://172.17.0.3:8030/ is certainly not valid browser side : you must get it to ask everything on locahost:8030 so it does not make direct network requests and lower security barrier ( lots of things non-ssl are only tolerated on "localhost" based url) |
If it helps, I have a docker setup but instead of running the python web server, it runs nginx and an auto-reloader. To use that repo: init git submodules, then I use the If |
@andreagalle added powershell run example: https://github.com/gabriel-v/python-wasm-pygame-experiments/tree/7b9311d43c8e6b52c12247ea035dcc38c82fdf13 The container also builds pygbag from scratch - you can customize it by changing the fork under confirmed at a friend's windows machine the container works as expected. the hot reloading only works on windows with the in-container code editor, as |
Thanks a lot @gabriel-v , I'll try it out no later than tonight! From what I can see you used another base image, different from https://hub.docker.com/r/alnoda/python-workspace : do you think that could be the issue? I really liked that image, having a "complete" python workspace. |
that image is built from this dockerfile which is just debian + python You can create your own image by changing that FROM, and also here and here to your own image repository (or comment out the docker push) You probably want to remove the Or, you could start from the debian base image known to work, and install whatever you want from that other place here. |
The image you linked seems to be based on ubuntu 20 which probably doesn't have python3.11 in the container. Through the building code, cmake and pygbag CLI might work with python 3.9 or lower - see if it works! PS build takes ~45min on my machine |
Thanks a lot for the additional details, I had a look at your Wonderful, thanks again for the hints on the python version needed by Concerning the alnoda/python-workspace image I was talking about, this Docker image was meant to give the students a complete and "ready to go" python env without anything to install apart from If the problem resides on this Docker image I'll try to work it out! |
if the students will only be running code in the browser, then they will have those pre-installed for browser. Also keep in mind anything you install in the docker image with So the students won't be using the zsh / other things packaged in your docker image. Try out the browser editor i packaged in the image (see readme) and edit with it "src/test-hotreload/game.py" and see game code instantly reset itself - that would be cool for the students, right? |
In that VS Code they have git, terminals (bash and ssh) that run in the container and work wonderfully. To run code in the browser, they either edit the code in Either way, you can ask them to write browser code that interacts with the container flask server from here, or give them an API backend yourself and make multiplayer games. See pygame-web/pkg-porting-wasm#5 for details on hot reload implementation - you can find examples of |
Thanks a lot @gabriel-v I have to read your suggestions more carefully. Then I would be happy to share with you what I've done so far. Any other suggestion from you would be really appreciated! |
I made it, it was just necessary to edit this line within the There I had to replace Running pygbag from within the container, the
always passing the container IP address to the pygbag I will submit a pull request ASAP, to handle this case with a couple of additional parameters. What do you think @pmp-p ? |
it's probably usefull but i'm quite sure camera access will break if anything else than "localhost" is in url of end user and still on http+lan. Also I still have trouble to figure out what docker is bringing for something that is 100% prebuilt and runs only client side. Do you have some schematics of what you are doing ? if it is only about handling students files in a work session there are probably much simpler solutions. |
Not it is just about having |
Moreover, yesterday, I was able to dev/run/play everything from the Browser only (without having to install even Docker) making use of GitHub codespaces (you will find more info here). I had to slightly adjust your |
Well what part/use of pygbag really requires docker ? The python module was only made for packaging "final" product in a quick way. I think people - not yet packaging for a game release - should just use a browser + online pygbag runtime ( currently hosted on github pages ) with codesandbox.io/github.dev or just some network/usb drive folder dropped on Chromium browers integrated source editor ( it works fine with python code ). my own testing zone on codesandbox https://codesandbox.io/s/happy-hooks-mb850n?file=/test-hg_fsurl.html that runs live without packaging. pygbag - python module side - is really for localhost use when you want minimal network traffic while testing ( or eventually go offline) or access IoT with ws:// or camera/audio recording. Which are usefull but still unexplored corner cases. |
future of pygbag is run from browser or wasi cmdline, not from docker. |
Since I planned to dev and run everything from a docker container alnoda-workspace this package would perfectly fits to make some amazing Python games without having to export the graphic session somehow.
After importing pygame & pygbag everything works fine if I am running the container from a Linux host, but not from a Windows one. The console on my Chrome browser shows that the server fails to retrieve some
.js
resources.I am going to edit this post, to provide more information on how to reproduce this issue, what’s the error, but I would at least have a feedback on the possible scenario:
bind
or the issue resides on the Docker side (deployed container and/or host machine)?This SO post seems connected to this issue:
https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach
The text was updated successfully, but these errors were encountered: