jgraph/drawio-desktop

drawio command-line export requires X-server connection

kanaka opened this issue ยท 8 comments

This is a sub-task of #127.

I'm trying to create a pipeline that uses drawio export mode and package it up for easy use in a docker container. Since the export mode does not display anything it would be nice if we didn't have to use xvfb-run just to make it work. Here is what happens without xvfb-run wrapping the command:

docker run -it --cap-add SYS_ADMIN drawio-image drawio -x --crop infile.drawio -o outfile.pdf

(drawio:1): Gtk-WARNING **: 02:58:36.186: cannot open display: 

There are some X utilities with a command line mode that complain like this but still complete the commandline batch/cmd. drawio appears to be exiting with an error in this situation. By creating a wrapper in the Dockerfile that runs within xvfb-run the command succeeds:

RUN echo "#!/bin/sh\nxvfb-run /usr/bin/drawio \"\${@}\"" > /usr/local/bin/drawio &&     chmod +x /usr/local/bin/drawio
docker run -it --cap-add SYS_ADMIN drawio-image /usr/local/bin/drawio -x --crop infile.drawio -o outfile.pdf
Home directory not accessible: Permission denied
infile.drawio -> outfile.pdf

Note that the Home directory permissions issue is non-fatal and is issue #145

Possible work around might be to use Xvfb. I've not tried it in docker, but have used this in Vagrant:

export display=:1
Xvfb :1 -screen 0 1024x768x16 & sleep 1

Xfvb does work for me without any arguments aside from the command itself. It would be nice not to have to use it however.

cymno commented

The following Dockerfiile allows export of drawio files in a headless docker environment:

FROM debian:jessie-slim

RUN apt update && apt -y upgrade
RUN apt -y install curl xvfb nano \
libgtk-3-0 \
libnotify4 libnss3 libxss1 libxtst6 xdg-utils libatspi2.0-0 libappindicator3-1 libsecret-1-0 \
libgbm1

RUN curl -LJO https://github.com/jgraph/drawio-desktop/releases/download/v13.3.5/draw.io-x86_64-13.3.5.AppImage
RUN chmod +x draw.io-x86_64-13.3.5.AppImage && \
./draw.io-x86_64-13.3.5.AppImage --appimage-extract

# command: 
# xvfb-run -a /squashfs-root/drawio --export --format pdf --output $output_file $input_file --disable-gpu --headless --no-sandbox

# explanation:
# `xvfb-run` (X virtual frame buffer) simulates a display (drawio dpends on it even though not used in CLI mode)
# `-a` flag for xvfb, otherwise causes [_sporadic_ errors](https://musescore.org/en/node/102096) with docker cacheing .X99-lock file in /tmp
# `squashfs-root` is the default extraction point for AppImage files
# `--disable-gpu --headless --no-sandbox` are necessary [as last argument](https://github.com/jgraph/drawio-desktop/issues/249#issuecomment-634157627) to [make electron / chrome](https://github.com/jgraph/drawio-desktop/issues/144) work
fnkr commented

Works fine:

docker run --rm --volume="${PWD}/:/data" fnkr/drawio --export --format png --output /data/diagram.png /data/diagram.drawio

Source: https://github.com/pkg-src/drawio.docker

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. See the FAQ for more information.

This is still an issue.

I am seeing this issue trying to run command line generation of png files over ssh, and believe this is still relevant to this issue.

Can someone explain a little more detail about what portion of the code is requiring the x-server connection?

I was thinking it was related to off-screen versus on-screen rendering but this issue leads me to think its something slightly different.

I don't see any route here apart from using xvfb. draw.io can't run purely on node, it needs a browser and full DOM.

It's either that or we add the same kind of functionality to draw in the docker image. I will close since a working workaround has been provided using xvfb. The CLI feature in docker is jgraph/docker-drawio#18