Skip to content
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

drawio command-line export requires X-server connection #146

Closed
kanaka opened this issue Aug 10, 2019 · 8 comments
Closed

drawio command-line export requires X-server connection #146

kanaka opened this issue Aug 10, 2019 · 8 comments

Comments

@kanaka
Copy link

kanaka commented Aug 10, 2019

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

@kanaka kanaka changed the title drawio command-line export requires X-server connection (sub-task of #127) drawio command-line export requires X-server connection Aug 10, 2019
@jgraph jgraph deleted a comment from modelmat Feb 15, 2020
@e-shreve-ti
Copy link

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

@modelmat
Copy link

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
Copy link

cymno commented Aug 20, 2020

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
Copy link

fnkr commented Aug 29, 2020

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
Copy link

stale bot commented Dec 10, 2020

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.

@stale stale bot added the wontfix label Dec 10, 2020
@modelmat
Copy link

This is still an issue.

@stale stale bot removed the wontfix label Dec 10, 2020
@kurtsansom
Copy link

kurtsansom commented Jan 6, 2021

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.

@davidjgraph
Copy link
Contributor

davidjgraph commented Jan 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants