An open API service indexing awesome lists of open source software.

https://github.com/rlespinasse/docker-drawio-desktop-headless

Headless version of drawio-desktop
https://github.com/rlespinasse/docker-drawio-desktop-headless

docker-base-image docker-image drawio drawio-tools hacktoberfest headless

Last synced: 3 months ago
JSON representation

Headless version of drawio-desktop

Awesome Lists containing this project

README

          

= Draw.io Desktop Headless docker image

Dockerized headless version of https://github.com/jgraph/drawio-desktop[Draw.io Desktop v29.6.6]

== What it does

Draw.io Desktop exposes a command-line client to allow us to create, check or export diagrams.

Since Draw.io Desktop is a GUI application, we need a GUI environment to run it.
And this prevents us to use it for automation in non-GUI environments such as CI tools.

This docker image enables us to run the command-line client in a headless mode by using a configurable **X** server.

Other minor additions are available

* Add timeout capability since the application can hang sometimes (due to user action needed in GUI mode)
* Clear the output log from Electron Security Warning
* Disable auto-update functionality to avoid unnecessary log
* Font support via two image variants (see <>)

== Getting Started

Run the docker image with your current directory mounted as `/data`:

[source,console]
----
$ docker run -it -w /data -v $(pwd):/data rlespinasse/drawio-desktop-headless
Usage: drawio [options] [input file/folder]
...
----

Export a Draw.io file to PNG:

[source,console]
----
$ docker run -it -w /data -v $(pwd):/data rlespinasse/drawio-desktop-headless \
-x -f png my-diagram.drawio
----

== How-to Guides

=== Run as non-root user

[source,console]
----
$ docker run -it \
-u $(id -u):$(id -g) \ <1>
-e HOME=/data/home -w /data \ <2>
-v /etc/passwd:/etc/passwd \ <3>
-v $(pwd):/data rlespinasse/drawio-desktop-headless
Usage: drawio [options] [input file/folder]
...
----
<1> Enable non-root user
<2> env HOME need to contains the path of the working directory (can be the same)
<3> Needed to run drawio as non-root since v24.4.6

.What if env HOME is not set properly?
[%collapsible]
====
[,console]
----
Fontconfig error: No writable cache directories
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Failed to get 'userData' path
at initDataListener (/opt/drawio/resources/app.asar/node_modules/electron-store/index.js:15:19)
at new ElectronStore (/opt/drawio/resources/app.asar/node_modules/electron-store/index.js:48:32)
at Object. (/opt/drawio/resources/app.asar/src/main/electron.js:15:15)
at Module._compile (node:internal/modules/cjs/loader:1271:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at Module._load (node:internal/modules/cjs/loader:967:12)
at l._load (node:electron/js2c/asar_bundle:2:13642)
at node:electron/js2c/browser_init:2:120247
at node:electron/js2c/browser_init:2:120456
/opt/drawio-desktop/runner.sh: line 4: 15 Trace/breakpoint trap (core dumped) "${DRAWIO_DESKTOP_EXECUTABLE_PATH:?}" "$@" --no-sandbox --disable-gpu
----
====

.What if this volume is not set properly?
[%collapsible]
====
[,console]
----
A JavaScript error occurred in the main process
Uncaught Exception:
SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)
at new SystemError (node:internal/errors:259:5)
at new NodeError (node:internal/errors:370:7)
at Object.userInfo (node:os:365:11)
at file:///opt/drawio/resources/app.asar/node_modules/atomically/dist/constants.js:10:29
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async node:electron/js2c/browser_init:2:125628
at async loadESM (node:internal/process/esm_loader:28:7)
----
====

=== Use custom fonts

To use your own fonts (e.g., proprietary or brand fonts), mount a volume to the custom fonts directory:

[source,console]
----
$ docker run -it -w /data \
-v $(pwd):/data \
-v /path/to/my/fonts:/usr/local/share/fonts/custom \
rlespinasse/drawio-desktop-headless
----

This works with both the `full` and `minimal` variants.

NOTE: Want to add a system font package instead? Modify the `Dockerfile` to install the missing package.

=== Choose an image variant

The docker image is available in two font variants to balance image size and language coverage.

* Use **`full`** (tag: `latest`) if your diagrams contain Chinese, Japanese, Korean, or other non-Latin scripts.
* Use **`minimal`** (tag: `minimal`) for Latin-script diagrams only — significantly smaller image.

[source,console]
----
$ docker pull rlespinasse/drawio-desktop-headless:latest
$ docker pull rlespinasse/drawio-desktop-headless:minimal
----

See <> for the full list of included font packages.

=== Use as docker base image

This docker image can be used as the base image to build a higher-level tool upon it.

In addition to running configuration, you have access to

- `DRAWIO_DESKTOP_EXECUTABLE_PATH` to have access to the executable path of Draw.io Desktop.
- `DRAWIO_DESKTOP_RUNNER_COMMAND_LINE` to run your script instead of the default one.

==== Used by

* Docker image https://github.com/rlespinasse/drawio-export[**rlespinasse/drawio-export**] which enhance export capabilities of the **Draw.io Desktop Headless** docker image,
** And GitHub Action https://github.com/rlespinasse/drawio-export-action[**rlespinasse/drawio-export-action**] which is build on top of **drawio-export** docker image.

== Reference

=== Image Variants

==== `full` (default) — tag: `latest`

Broad Unicode and CJK coverage.

Included font packages:

* https://packages.debian.org/trixie/fonts-liberation[fonts-liberation] — Helvetica/Arial/Times/Courier compatible
* https://packages.debian.org/trixie/fonts-dejavu-core[fonts-dejavu-core] — broad Unicode fallback
* https://packages.debian.org/trixie/fonts-noto-core[fonts-noto-core] — Latin, Cyrillic, Greek, Arabic, Devanagari, and more
* https://packages.debian.org/trixie/fonts-noto-cjk[fonts-noto-cjk] — Chinese, Japanese, Korean
* https://packages.debian.org/trixie/fonts-arphic-ukai[fonts-arphic-ukai] — Chinese serif
* https://packages.debian.org/trixie/fonts-arphic-uming[fonts-arphic-uming] — Chinese sans-serif
* https://packages.debian.org/trixie/fonts-ipafont-mincho[fonts-ipafont-mincho] — Japanese serif
* https://packages.debian.org/trixie/fonts-ipafont-gothic[fonts-ipafont-gothic] — Japanese sans-serif
* https://packages.debian.org/trixie/fonts-unfonts-core[fonts-unfonts-core] — Korean

==== `minimal` — tag: `minimal`

Western fonts only. Significantly smaller image.

Included font packages:

* https://packages.debian.org/trixie/fonts-liberation[fonts-liberation] — Helvetica/Arial/Times/Courier compatible
* https://packages.debian.org/trixie/fonts-dejavu-core[fonts-dejavu-core] — broad Unicode fallback

=== Configuration

[cols="2a,3a,1a",options="header"]
|===

| Environment Variable
| Description
| Default Value

| **DRAWIO_DESKTOP_COMMAND_TIMEOUT**
| To prevent Draw.io Desktop process to hang indefinitely.

The value is a floating point number with an optional suffix: 's'
for seconds (the default), 'm' for minutes, 'h' for hours or 'd'
for days. A duration of 0 disables the associated timeout.
| `10s`

| **XVFB_DISPLAY**
| Screen Display setup for XVFB
| `:42`

| **XVFB_OPTIONS**
| Options for Xvfb
| `-nolisten unix` (enable non-root run)

| **ELECTRON_DISABLE_SECURITY_WARNINGS**
| Avoid printing https://github.com/electron/electron/blob/master/docs/tutorial/security.md#electron-security-warnings[electron warning]
| `true`

| **DRAWIO_DISABLE_UPDATE**
| Disable auto-update of Draw.io Desktop
| `true`

| **SCRIPT_DEBUG_MODE**
| Enable `set -x` in internal scripts for debugging purpose
| `false`

|===

== Thanks to

Thanks for the community about https://github.com/jgraph/drawio-desktop/issues/127[the workaround docker-image based on Draw.io Desktop].

== Contributing

Pull requests are welcome.
For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.