2

I have a express server running inside a docker container. Once a user makes a REST call to an endpoint, it should make multiple in-memory screenshots of a randomly generated mesh from different angles using Babylon.js, do some image processing on it, create a PDF out of it and return the generated PDF file to the user.

To do so, I am trying to use headless-gl to provide virtual frame buffer for Babylon.js engine.

As far as I understood, I first need to get the gl context and then pass it to babylon engine:

var gl = require(‘gl’)(1024, 768, { preserveDrawingBuffer: true });

var engine = new BABYLON.Engine(gl, true, { disableWebGL2Support: true });

My issue is that I am not able to init the gl and it returns null.

Inside my Dockerfile, I use the following to install the dependencies for xvfb:

RUN apt-get update && apt-get install -y
libgl1-mesa-dri
libglapi-mesa
libosmesa6
mesa-utils
xvfb
&& apt-get clean

My server depends on mongo DB as well so inside my docker-compose.yml file, I wait for the DB container to get initialized before I load my express container:

command: wait-for.sh mongodb:27017 – …/node_modules/.bin/nodemon --inspect=0.0.0.0:9229 ./server.js

I think I need to updated my Dockerfile and docker-compose files with proper commands to load xvfb before running the node application but I am not sure how to do that.

I tried the following along with some other combinations but no luck so far:

command: wait-for.sh mongodb:27017 – xvfb-run -s “-ac -screen 0 1280x1024x24” node ./server.js

I appreciate if someone can help me resolve the issue.

Hamed
  • 1,351
  • 9
  • 23

1 Answers1

0

I think you are missing the server number as an argument. I am using xvfb-run --auto-servernum <command> to automatically get a free one. The default is number 99.

You can also use Xvfb manually with the DISPLAY environment variable set to :99 (default server number), but xvfb-run makes live a lot easier. I think you already read this, but for future users I will quote the stackgl/headless-gl README:

Interacting with Xvfb requires you to start it on the background and to execute your node program with the DISPLAY environment variable set to whatever was configured when running Xvfb (the default being :99). If you want to do that reliably you'll have to start Xvfb from an init.d script at boot time, which is extra configuration burden. Fortunately there is a wrapper script shipped with Xvfb known as xvfb-run which can start Xvfb on the fly, execute your Node.js program and finally shut Xvfb down.

bas
  • 822
  • 10
  • 20