FreeCAD / FreeCAD

This is the official source code of FreeCAD, a free and opensource multiplatform 3D parametric modeler.
https://www.freecad.org
Other
19.67k stars 4.04k forks source link

[Bug] `freecad -c` throws `t.qpa.xcb: could not connect to display ..` when run from Docker > PHP > Laravel stack #7421

Open agustavo87 opened 2 years ago

agustavo87 commented 2 years ago

Is there an existing issue for this?

Forums discussion

https://forum.freecadweb.org/viewtopic.php?p=620415

Version

0.20 (Release)

Full version info

FreeCad AppImage at https://github.com/FreeCAD/FreeCAD-Bundle/releases/download/0.20/FreeCAD_0.20-29177-2022-06-15-conda-Linux-x86_64-py39.AppImage

Subproject(s) affected?

No response

Issue description

Run from Laravel Sail docker container on a Laravel 8.0 Application from Windows Subsystem for Linux (WSL).

composer create-project laravel/laravel:^8.0 freecad-issue
cd freecad-issue
composer require laravel/sail --dev
# The next could take a while, no service is necessary
php artisan sail:install 
./vendor/bin/sail up
# Laravel app should be accessible on http://localhost

# Publish Dockerfiles on docker/8.1/Dockerfile
sail artisan sail:publish

# Download AppImage
wget -O freecad.AppImage https://github.com/FreeCAD/FreeCAD-Bundle/releases/download/0.20/FreeCAD_0.20-29177-2022-06-15-conda-Linux-x86_64-py39.AppImage
chmod +x freecad.AppImage

Modify docker/8.1/Dockerfile at the end to add freecad dependencies

RUN apt-get clean && apt-get update \
    && apt-get install -y libgl1
ENV APPIMAGE_EXTRACT_AND_RUN=1 

Then stop, rebuild, and restart image

./vendor/bin/sail down
./vendor/bin/sail build
./vendor/bin/sail up -d

modify .env file at the end

APPIMAGE_EXTRACT_AND_RUN=1 

Now test if the AppImage is working

./vendor/bin/sail shell
./freecad.AppImage -c "print(2+2)" #4

If is working as expected the web route can be added to check the freecad runned from a HTTP request. On routes/web.php add at the end:

Route::get('/freecad', function () {
 return 'result:'.`../freecad.AppImage -c "print(2+2)" 2>&1`;
});

If at the browser one go to localhost/freecad it show

result:qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: eglfs, minimal, minimalegl, offscreen, vnc, webgl, xcb. /tmp/appimage_extracted_8cac30c456e0f6469e8601386557085d/AppRun: line 42: 65 Aborted ${MAIN} "$@"

Anything else?

I have tried to isolate the issue and have found the next.

Right now, is solved (at least temporarily) running things vía a script with "no-reload" option as sail user, but this need to be run manually, and can't use supervisor. But this don't clarify what could be happening to make freecad run correctly as headless in some situations, and try to run GUI mode in the others

Workaround

To this is necessary to disable supervisor running artisan server. On docker/8.1/supervisor.conf

[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

# [program:php]
# command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
# user=sail
# environment=LARAVEL_SAIL="1"
# stdout_logfile=/dev/stdout
# stdout_logfile_maxbytes=0
# stderr_logfile=/dev/stderr
# stderr_logfile_maxbytes=0

Then the image can be rebuild

./vendor/bin/sail down
./vendor/bin/sail build
./vendor/bin/sail up -d

Now the web app is not automatically seved by supervisor http://localhost should give error. So the server can be started manually and some tweaks can be made, for example using the --no-reload option.

./vendor/bin/sail shell
/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80 --no-reload

Now, for some reason, http://localhost/freecad shows as expected result:4. Other tweaks that make things works is running from sail root-shell or disabling only # user=sail on supervisor.conf.

Code of Conduct

agustavo87 commented 2 years ago

Tried to run directly some parts of FreeCAD with launching options from AppImage as sugested in the GH issue :

./FreeCAD.AppImage
./FreeCAD.AppImage freecadcmd
./FreeCAD.AppImage python --version
./FreeCAD.AppImage python

The results where the next

Apparently, when launching python, even inside the AppImage and above the docker > php > php built-in server > laravel artisan serve stack everything seems to be working as expected, but when calling freecadcmd something happens. But this is an interaction with the described stack, becouse from docker > shell seems to be working as expected.

adrianinsaval commented 2 years ago

this is expected behavior IMO since the GUI is not available there, freecadcmd should be used instead, in the forum discussion another problem arises from this so either this issue should be updated or better closed IMO.

agustavo87 commented 2 years ago

this is expected behavior IMO since the GUI is not available there

So why does this work from shell? Also works when the HTTP is handled by a server (i.e., PHP built-in server) that is run as root.

freecadcmd should be used instead

Also tried with freecadcmd from inside AppImage (forum discussion)

freecad.AppImage freecadcmd -c "print(2+2)"

adrianinsaval commented 2 years ago

Yeah but that looks like a different problem and it should be treated as such.

luzpaz commented 2 years ago

Does that merit opening a ticket on FreeCAD-bundle? (where appimage related bugs are filed)

adrianinsaval commented 2 years ago

Not IMO, the GUI issue seems to be a problem with the environment and same thing with the permission issue above, in the forum thread that was solved too but FreeCAD still fails. It's not clear if this is really related to being appimage, since it only fails on that environment I would think not. OP hasn't replied with a log file yet so not much can be done.

luzpaz commented 2 years ago

@agustavo87 ping

luzpaz commented 1 year ago

@amrit3701 is this reproducible with your docker project ?

amrit3701 commented 1 year ago

@agustavo87

If you want to run FreeCAD code on server, then I would suggest to use FreeCAD CLI docker images.

Here is the docs: https://wiki.freecad.org/FreeCAD_Docker_CLI_mode

In FreeCAD docker images, FreeCAD is compiled without GUI element and you will never display error unless that feature require GUI elements.

agustavo87 commented 1 year ago

OP hasn't replied with a log file yet so not much can be done.

adrianinsaval commented 1 year ago

have you tried a recent development version? can you still reproduce? https://github.com/FreeCAD/FreeCAD-Bundle/releases/tag/weekly-builds

Can you also reproduce using freecad packaged some other way? (snap, flatpak or system pakcage)

maxwxyz commented 4 months ago

Is this still relevant?

luzpaz commented 3 months ago

@agustavo87 please respond