jgraph / docker-drawio

Dockerized draw.io based on whichever is the most secure image at the time.
GNU General Public License v3.0
1.48k stars 359 forks source link

Self-Contained Export to PDF Fails with 500 Internal Server Error #128

Closed paul-switchnetsys closed 7 months ago

paul-switchnetsys commented 10 months ago

I've been running the self-contained docker image flawlessly for several months now. To the point that the app was opened up to other engineers in my team. Recently, I've had reports that exporting to PDF fails with a 500 Internal Server Error.

Checking myself, I can confirm that this is the case. Looking at the docker log for the export-server container I see:

image-export     |   Puppeteer old Headless deprecation warning:
image-export     |     In the near feature `headless: true` will default to the new Headless mode
image-export     |     for Chrome instead of the old Headless implementation. For more
image-export     |     information, please see https://developer.chrome.com/articles/new-headless/.
image-export     |     Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
image-export     |     If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.
image-export     | 
image-export     | warn: Handled exception: Could not find Chromium (rev. 1108766). This can occur if either
image-export     |  1. you did not perform an installation before running the script (e.g. `npm install`) or
image-export     |  2. your cache path is incorrectly configured (which is: /home/pptruser/.cache/puppeteer).
image-export     | For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration. req=ip=82.16.180.57 format=pdf w=0 h=0 bg=%23ffffff  {"stack":"Error: Could not find Chromium (rev. 1108766). This can occur if either\n 1. you did not perform an installation before running the script (e.g. `npm install`) or\n 2. your cache path is incorrectly configured (which is: /home/pptruser/.cache/puppeteer).\nFor (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.\n    at ChromeLauncher.resolveExecutablePath (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:289:27)\n    at ChromeLauncher.executablePath (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:182:25)\n    at ChromeLauncher.computeLaunchArguments (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:99:37)\n    at async ChromeLauncher.launch (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:83:28)\n    at async handleRequest (/home/pptruser/draw-image-export2/export.js:554:17)"}
image-export     | ::ffff:172.18.0.20 - - [26/Oct/2023:06:33:13 +0000] "POST / HTTP/1.1" 500 - "https://draw.domain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.60"

A check via Google suggests that 'npm install' either didn't run, or didn't run correctly. However, when I try to manually run 'npm install' via docker exec I encounter a permissions issue:

paul@marvin:~/docker/drawio$ docker exec -it image-export bash
pptruser@4ef45069484c:~/draw-image-export2$ npm install
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /home/pptruser/draw-image-export2/node_modules/buffer
npm ERR! dest /home/pptruser/draw-image-export2/node_modules/.buffer-gK5cV64K
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/home/pptruser/draw-image-export2/node_modules/buffer' -> '/home/pptruser/draw-image-export2/node_modules/.buffer-gK5cV64K'
npm ERR!  [Error: EACCES: permission denied, rename '/home/pptruser/draw-image-export2/node_modules/buffer' -> '/home/pptruser/draw-image-export2/node_modules/.buffer-gK5cV64K'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/home/pptruser/draw-image-export2/node_modules/buffer',
npm ERR!   dest: '/home/pptruser/draw-image-export2/node_modules/.buffer-gK5cV64K'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in: /home/pptruser/.npm/_logs/2023-10-26T07_03_14_107Z-debug-0.log

Aside from some minor changes to the self-contained docker-compose.yml file (shown below with the domain anonymised), I'm struggling to get export to PDF working again. Export to other formats appear to be working as expected (aside from a weird dashed line appearing in the VSDX export, but that's a separate issue).

version: '3.5'

networks:
  proxy_net:
    external: true

services:
  drawio:
    image: jgraph/drawio
    container_name: drawio
    restart: unless-stopped
    networks:
      - proxy_net
    environment:
      - DRAWIO_SELF_CONTAINED=1
      - EXPORT_URL=http://image-export:8000/
      - PLANTUML_URL=http://plantuml-server:8080/
      - DRAWIO_BASE_URL=draw.domain.com
      - DRAWIO_SERVER_URL=https://draw.domain.com
      - DRAWIO_CLOUD_CONVERT_APIKEY=valid_drawio_cloud_convert_apikey
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://drawio:8080 || exit 1"]
      interval: 1m30s
      timeout: 10s
      retries: 5
      start_period: 10s
  image-export:
    container_name: image-export
    image: jgraph/export-server
    expose:
      - "8000"
    networks:
      - proxy_net
    volumes:
      - fonts_volume:/usr/share/fonts/drawio
    environment:
      - DRAWIO_BASE_URL=draw.domain.com
  plantuml-server:
    container_name: plantuml-server
    image: plantuml/plantuml-server
    expose:
      - "8080"
    networks:
      - proxy_net
    volumes:
      - fonts_volume:/usr/share/fonts/drawio
volumes:
  fonts_volume:

Any advice would be greatly appreciated.

Thanks,

ZID-TU-Graz-Collab commented 9 months ago

we are also affected by this issue

jjasoncool commented 9 months ago

@paul-switchnetsys Which drawio version are you using? I can find same issue like this.

https://github.com/jgraph/drawio/issues/3596

jjasoncool commented 9 months ago

https://github.com/jgraph/docker-drawio/issues/144 https://github.com/jgraph/drawio/issues/3596

paul-switchnetsys commented 9 months ago

@jjasoncool I'm currently running drawio V22.0.8 and the issue I am experiencing is as per https://github.com/jgraph/docker-drawio/issues/144 where Chromium doesn't exist.

I'll try removing the drawio and image-export containers and pulling a new version down (it has been about a month or more since this issue came to light).

paul-switchnetsys commented 9 months ago

Sadly, I have the same issue.

> drawio-export@1.0.0 start
> node export.js
draw.io export server worker 4 listening on port 8000...
draw.io export server worker 1 listening on port 8000...
draw.io export server worker 3 listening on port 8000...
draw.io export server worker 2 listening on port 8000...
  Puppeteer old Headless deprecation warning:
    In the near feature `headless: true` will default to the new Headless mode
    for Chrome instead of the old Headless implementation. For more
    information, please see https://developer.chrome.com/articles/new-headless/.
    Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
    If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.
warn: Handled exception: Could not find Chromium (rev. 1108766). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npm install`) or
 2. your cache path is incorrectly configured (which is: /home/pptruser/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration. req=ip=82.16.180.57 format=pdf w=0 h=0 bg=%23ffffff  {"stack":"Error: Could not find Chromium (rev. 1108766). This can occur if either\n 1. you did not perform an installation before running the script (e.g. `npm install`) or\n 2. your cache path is incorrectly configured (which is: /home/pptruser/.cache/puppeteer).\nFor (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.\n    at ChromeLauncher.resolveExecutablePath (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:289:27)\n    at ChromeLauncher.executablePath (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:182:25)\n    at ChromeLauncher.computeLaunchArguments (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:99:37)\n    at async ChromeLauncher.launch (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:83:28)\n    at async handleRequest (/home/pptruser/draw-image-export2/export.js:554:17)"}
::ffff:172.18.0.20 - - [24/Nov/2023:12:08:23 +0000] "POST / HTTP/1.1" 500 - "https://draw.switchnetsys.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"

Interestingly, the error mentions the cache path of "/home/pptuser/.cache/puppeteer" which doesn't exist in the container. ProductLauncher.js and ChromeLauncher.js do exist in the path "/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/" however.

jjasoncool commented 9 months ago

Sadly, I have the same issue.

> drawio-export@1.0.0 start
> node export.js
draw.io export server worker 4 listening on port 8000...
draw.io export server worker 1 listening on port 8000...
draw.io export server worker 3 listening on port 8000...
draw.io export server worker 2 listening on port 8000...
  Puppeteer old Headless deprecation warning:
    In the near feature `headless: true` will default to the new Headless mode
    for Chrome instead of the old Headless implementation. For more
    information, please see https://developer.chrome.com/articles/new-headless/.
    Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
    If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.
warn: Handled exception: Could not find Chromium (rev. 1108766). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npm install`) or
 2. your cache path is incorrectly configured (which is: /home/pptruser/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration. req=ip=82.16.180.57 format=pdf w=0 h=0 bg=%23ffffff  {"stack":"Error: Could not find Chromium (rev. 1108766). This can occur if either\n 1. you did not perform an installation before running the script (e.g. `npm install`) or\n 2. your cache path is incorrectly configured (which is: /home/pptruser/.cache/puppeteer).\nFor (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.\n    at ChromeLauncher.resolveExecutablePath (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:289:27)\n    at ChromeLauncher.executablePath (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:182:25)\n    at ChromeLauncher.computeLaunchArguments (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:99:37)\n    at async ChromeLauncher.launch (/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:83:28)\n    at async handleRequest (/home/pptruser/draw-image-export2/export.js:554:17)"}
::ffff:172.18.0.20 - - [24/Nov/2023:12:08:23 +0000] "POST / HTTP/1.1" 500 - "https://draw.switchnetsys.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"

Interestingly, the error mentions the cache path of "/home/pptuser/.cache/puppeteer" which doesn't exist in the container. ProductLauncher.js and ChromeLauncher.js do exist in the path "/home/pptruser/draw-image-export2/node_modules/puppeteer-core/lib/cjs/puppeteer/node/" however.

My drawio container seems don't using export-server

high3eam commented 8 months ago

Same issue here as well. Self contained drawio with export-server throws this error.

Running drawio behind Caddy, a reverse proxy.

My docker compose config ``` version: '3' services: plantuml-server: image: plantuml/plantuml-server expose: - "8080" networks: - drawionet volumes: - fonts_volume:/usr/share/fonts/drawio image-export: image: jgraph/export-server expose: - "8000" networks: - drawionet volumes: - fonts_volume:/usr/share/fonts/drawio environment: - DRAWIO_BASE_URL=https://draw.domain.com drawio: image: jgraph/drawio ports: - 127.0.0.1:21356:8080 - 127.0.0.1:21357:8443 links: - plantuml-server:plantuml-server - image-export:image-export depends_on: - plantuml-server - image-export networks: - drawionet environment: - DRAWIO_SELF_CONTAINED=1 - PLANTUML_URL=http://plantuml-server:8080/ - EXPORT_URL=http://image-export:8000/ - DRAWIO_BASE_URL=https://draw.domain.com - DRAWIO_SERVER_URL=https://draw.domain.com/ networks: drawionet: volumes: fonts_volume: ```
m-mohamedin commented 8 months ago

The next version should fix it

paul-switchnetsys commented 7 months ago

The next version should fix it

Thanks to the notification, I removed all containers (plantuml, image-export and draw) pulled new images and (after making a minor change to my docker-compose.yml, I can now export to PDF!

For reference the changes I made were:

Original (drawio container)
      - DRAWIO_BASE_URL=draw.domain.com
      - DRAWIO_SERVER_URL=https://draw.domain.com
Updated
      - DRAWIO_BASE_URL=https://draw.domain.com
      - DRAWIO_SERVER_URL=https://draw.domain.com/
Original (image-export container)
      - DRAWIO_BASE_URL=draw.domain.com
Updated
      - DRAWIO_BASE_URL=https://draw.domain.com

I'm not sure if those changes were needed or if it was simply a case of removing the containers, pulling new images and issuing a docker compose up -d.

Either way, PDF export is now working for me.

Thanks,

m-mohamedin commented 7 months ago

Thanks @paul-switchnetsys for confirming

aluevano commented 6 months ago

Same issue here as well. Self contained drawio with export-server throws this error.

Running drawio behind Caddy, a reverse proxy.

My docker compose config

version: '3'
services:
  plantuml-server:
    image: plantuml/plantuml-server
    expose:
      - "8080"
    networks:
      - drawionet
    volumes:
      - fonts_volume:/usr/share/fonts/drawio
  image-export:
    image: jgraph/export-server
    expose:
      - "8000"
    networks:
      - drawionet
    volumes:
      - fonts_volume:/usr/share/fonts/drawio
    environment:
      - DRAWIO_BASE_URL=https://draw.domain.com
  drawio:
    image: jgraph/drawio
    ports:
      - 127.0.0.1:21356:8080
      - 127.0.0.1:21357:8443
    links:
      - plantuml-server:plantuml-server
      - image-export:image-export
    depends_on:
      - plantuml-server
      - image-export
    networks:
      - drawionet
    environment:
      - DRAWIO_SELF_CONTAINED=1
      - PLANTUML_URL=http://plantuml-server:8080/
      - EXPORT_URL=http://image-export:8000/
      - DRAWIO_BASE_URL=https://draw.domain.com
      - DRAWIO_SERVER_URL=https://draw.domain.com/
networks:
  drawionet:

volumes:
  fonts_volume:

What does your Caddyfile looks like? I have the same issue with all internal network and it is the only feature that is not working. Using the latest container images.