Skip to content

Commit

Permalink
feat: dockerized draw.io desktop in headless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rlespinasse committed Jan 27, 2021
1 parent bf56974 commit 8f3ca38
Show file tree
Hide file tree
Showing 29 changed files with 6,778 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = tab
indent_size = 4
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: rlespinasse
28 changes: 28 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build
on:
pull_request:
push:
branches:
- v1.x
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rlespinasse/[email protected]
- name: Build docker image
run: make build
env:
DOCKER_IMAGE: ${{ github.repository }}:${{ env.GITHUB_REF_SLUG }}
- uses: cycjimmy/semantic-release-action@v2
with:
semantic_version: 17.3.7
branches: |
[
'v1.x',
]
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/dockerhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Update Docker Hub information
on:
release:
types: [published]
push:
branches:
- v1.x
paths:
- DOCKER.md
- .github/workflows/dockerhub.yaml
jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Sync information on Docker Hub
uses: rlespinasse/[email protected]
with:
pass: ${{ secrets.DOCKER_PASSWORD }}
slug: rlespinasse/drawio-desktop-headless
readme: ./DOCKER.md
description: true
17 changes: 17 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Publish to Registry
on:
release:
types: [published]
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rlespinasse/[email protected]
- name: Publish to Registry
uses: elgohr/[email protected]
with:
name: rlespinasse/drawio-desktop-headless
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: "latest,${{ env.GITHUB_REF_SLUG }}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
*.pdf
31 changes: 31 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Draw.io Desktop Headless docker image

[Dockerized headless][1] version of [Draw.io Desktop][2]

## What is does

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

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

This [docker image][1] enable us to run the command-line client in a headless mode.

## Running

```bash
docker run -it -v $(pwd):/data rlespinasse/drawio-desktop-headless
```

Read about [docker image configuration][3]

## License

View [license information][4] for the software contained in this image.

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.

[1]: https://github.com/rlespinasse/docker-drawio-desktop-headless
[2]: https://github.com/jgraph/drawio-desktop
[3]: https://github.com/rlespinasse/docker-drawio-desktop-headless/blob/v1.x/README.adoc#configuration
[4]: https://github.com/rlespinasse/docker-drawio-desktop-headless/blob/v1.x/LICENSE
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM debian:latest

WORKDIR "/opt/drawio-desktop"

ENV DRAWIO_VERSION "14.1.8"
RUN set -e; \
apt-get update && apt-get install -y \
libappindicator3-1 \
libatspi2.0-0 \
libasound2 \
libgconf-2-4 \
libgtk-3-0 \
libnotify4 \
libnss3 \
libsecret-1-0 \
libxss1 \
libxtst6 \
libgbm-dev \
sgrep \
wget \
xdg-utils \
xvfb; \
wget -q https://github.com/jgraph/drawio-desktop/releases/download/v${DRAWIO_VERSION}/draw.io-amd64-${DRAWIO_VERSION}.deb \
&& apt-get install /opt/drawio-desktop/draw.io-amd64-${DRAWIO_VERSION}.deb \
&& rm -rf /opt/drawio-desktop/draw.io-amd64-${DRAWIO_VERSION}.deb; \
rm -rf /var/lib/apt/lists/*;

COPY scripts/* ./

ENV ELECTRON_DISABLE_SECURITY_WARNINGS "true"
ENV DRAWIO_DISABLE_UPDATE "true"
ENV DRAWIO_DESKTOP_COMMAND_TIMEOUT "10s"
ENV DRAWIO_DESKTOP_EXECUTABLE_PATH "/opt/draw.io/drawio"
ENV DRAWIO_DESKTOP_RUNNER_COMMAND_LINE "/opt/drawio-desktop/runner.sh"
ENV XVFB_DISPLAY ":42"
ENV XVFB_OPTIONS ""

ENTRYPOINT [ "/opt/drawio-desktop/entrypoint.sh" ]
CMD [ "--help" ]
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: build run setup-test test cleanup

DOCKER_IMAGE?=rlespinasse/drawio-desktop-headless:local
build:
@docker build -t ${DOCKER_IMAGE} .

RUN_ARGS?=
DOCKER_OPTIONS?=
run:
@docker run -t $(DOCKER_OPTIONS) -w /data -v $(PWD):/data ${DOCKER_IMAGE} ${RUN_ARGS}

setup-test:
@npm install -g bats

test: cleanup build
@mkdir -p tests/output
@DOCKER_IMAGE=$(DOCKER_IMAGE) bats -r tests

cleanup:
@rm -rf tests/output
83 changes: 83 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
= Draw.io Desktop Headless docker image

image:https://img.shields.io/docker/v/rlespinasse/drawio-desktop-headless[Docker Version,link=https://hub.docker.com/r/rlespinasse/drawio-desktop-headless]
image:https://img.shields.io/docker/pulls/rlespinasse/drawio-desktop-headless[Docker Pull,link=https://hub.docker.com/r/rlespinasse/drawio-desktop-headless]
image:https://github.com/rlespinasse/docker-drawio-desktop-headless/workflows/Build/badge.svg[Build]

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

== What is does

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

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

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

Other minor addition have been set
* 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 unneccessary log

== Running

[source,bash]
----
docker run -it -v $(pwd):/data rlespinasse/drawio-desktop-headless
----

=== 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
|

| **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
| `true`

|===

== Use as docker base image

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

In addition of 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.

== Thanks to

Thanks for the community about https://github.com/jgraph/drawio-desktop/issues/127[the work around docker-image based of 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.
Loading

0 comments on commit 8f3ca38

Please sign in to comment.